create configuration from options only once in the boot process (#5487)

Merge pull request 5487
This commit is contained in:
Florian Thomas 2017-04-19 19:50:25 +01:00 committed by jekyllbot
parent 76fb728f72
commit 0108b22f3c
3 changed files with 28 additions and 9 deletions

View File

@ -37,6 +37,7 @@ module Jekyll
# #
# Returns a full Jekyll configuration # Returns a full Jekyll configuration
def configuration_from_options(options) def configuration_from_options(options)
return options if options.is_a?(Jekyll::Configuration)
Jekyll.configuration(options) Jekyll.configuration(options)
end end

View File

@ -32,11 +32,12 @@ module Jekyll
cmd.action do |_, opts| cmd.action do |_, opts|
opts["serving"] = true opts["serving"] = true
opts["watch" ] = true unless opts.key?("watch") opts["watch" ] = true unless opts.key?("watch")
config = opts["config"]
opts["url"] = default_url(opts) if Jekyll.env == "development" config = configuration_from_options(opts)
Build.process(opts) if Jekyll.env == "development"
opts["config"] = config config["url"] = default_url(config)
Serve.process(opts) end
[Build, Serve].each { |klass| klass.process(config) }
end end
end end
end end

View File

@ -82,16 +82,26 @@ class TestCommandsServe < JekyllUnitTest
end end
should "keep config between build and serve" do should "keep config between build and serve" do
custom_options = { options = {
"config" => %w(_config.yml _development.yml), "config" => %w(_config.yml _development.yml),
"serving" => true, "serving" => true,
"watch" => false, # for not having guard output when running the tests "watch" => false, # for not having guard output when running the tests
"url" => "http://localhost:4000", "url" => "http://localhost:4000",
} }
config = Jekyll::Configuration.from(options)
expect(Jekyll::Commands::Serve).to receive(:process).with(custom_options) allow(Jekyll::Command).to(
@merc.execute(:serve, { "config" => %w(_config.yml _development.yml), receive(:configuration_from_options).with(options).and_return(config)
"watch" => false, }) )
allow(Jekyll::Command).to(
receive(:configuration_from_options).with(config).and_return(config)
)
expect(Jekyll::Commands::Build).to(
receive(:process).with(config).and_call_original
)
expect(Jekyll::Commands::Serve).to receive(:process).with(config)
@merc.execute(:serve, options)
end end
context "in development environment" do context "in development environment" do
@ -175,5 +185,12 @@ class TestCommandsServe < JekyllUnitTest
end end
end end
end end
should "read `configuration` only once" do
allow(Jekyll::Commands::Serve).to receive(:start_up_webrick)
expect(Jekyll).to receive(:configuration).once.and_call_original
@merc.execute(:serve, { "watch" => false })
end
end end
end end