From 8342231a56aae0cf0b3fe71db3677b016fb58ff0 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Mon, 17 Jul 2017 14:36:45 -0400 Subject: [PATCH 1/4] default sass to compressed in production --- lib/github-pages/configuration.rb | 18 ++++++++++++------ spec/github-pages/configuration_spec.rb | 13 +++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index ddcd0668..79c86526 100644 --- a/lib/github-pages/configuration.rb +++ b/lib/github-pages/configuration.rb @@ -24,11 +24,12 @@ class Configuration }, }.freeze - # Jekyll defaults merged with Pages defaults. - MERGED_DEFAULTS = Jekyll::Utils.deep_merge_hashes( - Jekyll::Configuration::DEFAULTS, - DEFAULTS - ).freeze + # User-overwritable defaults used only in production for practical reasons + PRODUCTION_DEFAULTS = Jekyll::Utils.deep_merge_hashes DEFAULTS, { + "sass" => { + "style" => "compressed", + }, + }.freeze # Options which GitHub Pages sets, regardless of the user-specified value # @@ -82,6 +83,11 @@ def development? Jekyll.env == "development" end + def merged_defaults + defaults = development? ? DEFAULTS : PRODUCTION_DEFAULTS + Jekyll::Utils.deep_merge_hashes Jekyll::Configuration::DEFAULTS, defaults + end + # Given a user's config, determines the effective configuration by building a user # configuration sandwhich with our overrides overriding the user's specified # values which themselves override our defaults. @@ -91,7 +97,7 @@ def development? # Note: this is a highly modified version of Jekyll#configuration def effective_config(user_config) # Merge user config into defaults - config = Jekyll::Utils.deep_merge_hashes(MERGED_DEFAULTS, user_config) + config = Jekyll::Utils.deep_merge_hashes(merged_defaults, user_config) .fix_common_issues .add_default_collections diff --git a/spec/github-pages/configuration_spec.rb b/spec/github-pages/configuration_spec.rb index 060a7319..9218f170 100644 --- a/spec/github-pages/configuration_spec.rb +++ b/spec/github-pages/configuration_spec.rb @@ -55,6 +55,14 @@ it "accepts local configs" do expect(effective_config["testing"]).to eql("123") end + + context "in development" do + before { ENV["JEKYLL_ENV"] = "development" } + + it "doesn't compress sass" do + expect(effective_config["sass"]).to be_nil + end + end end context "#set being called via the hook" do @@ -159,6 +167,11 @@ expect(described_class.disable_whitelist?).to eql(false) end end + + it "compresses sass" do + puts ENV["JEKYLL_ENV"].inspect + expect(effective_config["sass"]).to eql("style" => "compressed") + end end end end From 334f3849973107399150be2b2f2a49eed44d7185 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Mon, 17 Jul 2017 15:25:22 -0400 Subject: [PATCH 2/4] remove debug cruft --- spec/github-pages/configuration_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/github-pages/configuration_spec.rb b/spec/github-pages/configuration_spec.rb index 9218f170..5b3a2f67 100644 --- a/spec/github-pages/configuration_spec.rb +++ b/spec/github-pages/configuration_spec.rb @@ -169,7 +169,6 @@ end it "compresses sass" do - puts ENV["JEKYLL_ENV"].inspect expect(effective_config["sass"]).to eql("style" => "compressed") end end From 2339417cc1dce671b35f2c091feac0e97f8bd127 Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Thu, 20 Jul 2017 09:30:13 -0400 Subject: [PATCH 3/4] rename merged_defaults to defaults_for_env --- lib/github-pages/configuration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/github-pages/configuration.rb b/lib/github-pages/configuration.rb index 79c86526..fa38a159 100644 --- a/lib/github-pages/configuration.rb +++ b/lib/github-pages/configuration.rb @@ -83,7 +83,7 @@ def development? Jekyll.env == "development" end - def merged_defaults + def defaults_for_env defaults = development? ? DEFAULTS : PRODUCTION_DEFAULTS Jekyll::Utils.deep_merge_hashes Jekyll::Configuration::DEFAULTS, defaults end @@ -97,7 +97,7 @@ def merged_defaults # Note: this is a highly modified version of Jekyll#configuration def effective_config(user_config) # Merge user config into defaults - config = Jekyll::Utils.deep_merge_hashes(merged_defaults, user_config) + config = Jekyll::Utils.deep_merge_hashes(defaults_for_env, user_config) .fix_common_issues .add_default_collections From 5e056cf2de25669156a41f64655cf4ccfecba17c Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Thu, 20 Jul 2017 09:30:20 -0400 Subject: [PATCH 4/4] add tests for defaults_for_env --- spec/github-pages/configuration_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/github-pages/configuration_spec.rb b/spec/github-pages/configuration_spec.rb index 5b3a2f67..72c9dcdc 100644 --- a/spec/github-pages/configuration_spec.rb +++ b/spec/github-pages/configuration_spec.rb @@ -14,6 +14,8 @@ let(:configuration) { Jekyll.configuration(test_config) } let(:site) { Jekyll::Site.new(configuration) } let(:effective_config) { described_class.effective_config(site.config) } + let(:defaults_for_env) { described_class.defaults_for_env } + before(:each) do ENV.delete("DISABLE_WHITELIST") ENV["JEKYLL_ENV"] = "test" @@ -61,6 +63,7 @@ it "doesn't compress sass" do expect(effective_config["sass"]).to be_nil + expect(defaults_for_env["sass"]).to be_nil end end end @@ -170,6 +173,7 @@ it "compresses sass" do expect(effective_config["sass"]).to eql("style" => "compressed") + expect(defaults_for_env["sass"]).to eql("style" => "compressed") end end end