Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom config files from CLI #322

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -11,3 +11,5 @@ AllCops:

Metrics/BlockLength:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
2 changes: 1 addition & 1 deletion jekyll-admin.gemspec
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "jekyll", "~> 3.3"
spec.add_dependency "jekyll", "~> 3.6"
spec.add_dependency "sinatra", "~> 1.4"
spec.add_dependency "sinatra-contrib", "~> 1.4"
spec.add_dependency "addressable", "~> 2.4"
10 changes: 8 additions & 2 deletions lib/jekyll-admin/server/configuration.rb
Original file line number Diff line number Diff line change
@@ -39,9 +39,15 @@ def raw_configuration
)
end

# Returns the path to the *first* config file discovered
# Returns the path to the *first* config file from the list passed to terminal
# switch +--config+ or the first of default config files to be discovered at the
# site's source directory.
def configuration_path
sanitized_path configuration.config_files(overrides).first
if site.config["config"]
sanitized_path site.config["config"].first
else
sanitized_path configuration.config_files(overrides).first
end
end

# The user's uploaded configuration for updates
2 changes: 2 additions & 0 deletions spec/fixtures/site/_config_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Custom Test Site
gems: ["jekyll-admin"]
58 changes: 58 additions & 0 deletions spec/jekyll-admin/custom_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
describe "custom integration" do
let(:source) { fixture_path("site") }
let(:dest) { File.join(source, "_site") }
let(:config) { File.join(source, "_config_test.yml") }

let(:args) do
[
"--detach",
"--watch",
"--source", source,
"--destination", dest,
"--config", config,
]
end

let(:start_command) { %w(bundle exec jekyll serve).concat(args) }
let(:stop_command) { ["pkill", "-f", "jekyll"] }
let(:server) { "http://localhost:4000" }
let(:path) { "/" }
let(:uri) { URI.join(server, path) }
let(:response) { Net::HTTP.get_response(uri) }

before do
Open3.popen3(*start_command)
sleep 3
end

after { Open3.capture2e(*stop_command) }

context "Jekyll site" do
let(:path) { "/" }

it "serves the Jekyll site", :skip => Gem.win_platform? do
expect(response.code).to eql("200")
expect(response.body).to match("You're probably looking for")
end
end

context "Admin site" do
let(:path) { "/admin" }

it "serves the Jekyll site", :skip => Gem.win_platform? do
with_index_stubbed do
expect(response.code).to eql("200")
expect(response.body).to match("Jekyll Admin")
end
end
end

context "API" do
let(:path) { "/_api/configuration" }

it "serves the Jekyll site", :skip => Gem.win_platform? do
expect(response.code).to eql("200")
expect(response.body).to match("Custom Test Site")
end
end
end