From 1c11afd78d4868fbcc98151081e78ff26f4cebfc Mon Sep 17 00:00:00 2001 From: Jordon Bedwell Date: Thu, 15 May 2014 16:28:37 -0500 Subject: [PATCH 1/3] Fix #2413 and setup a Jekyll.env. --- lib/jekyll.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index 941084d5..26c6e569 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -76,6 +76,15 @@ require 'jekyll-sass-converter' SafeYAML::OPTIONS[:suppress_warnings] = true module Jekyll + + # Public: Tells you which Jekyll environment you are building in so you can skip tasks + # if you need to. This is useful when doing expensive compression tasks on css and + # images and allows you to skip that when working in development. + + def self.env + ENV["JEKYLL_ENV"] || "development" + end + # Public: Generate a Jekyll configuration Hash by merging the default # options with anything in _config.yml, and adding the given options on top. # From 780cff46b389a7ee121be80d9ef115d28f3c1b69 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 May 2014 00:38:21 -0400 Subject: [PATCH 2/3] Add jekyll.environment to site_payload. --- lib/jekyll/site.rb | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 5f1580bb..9efe2500 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -314,19 +314,23 @@ module Jekyll # "tags" - The Hash of tag values and Posts. # See Site#post_attr_hash for type info. def site_payload - {"jekyll" => { "version" => Jekyll::VERSION }, - "site" => Utils.deep_merge_hashes(config, - Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], { - "time" => time, - "posts" => posts.sort { |a, b| b <=> a }, - "pages" => pages, - "static_files" => static_files.sort { |a, b| a.relative_path <=> b.relative_path }, - "html_pages" => pages.reject { |page| !page.html? }, - "categories" => post_attr_hash('categories'), - "tags" => post_attr_hash('tags'), - "collections" => collections, - "documents" => documents, - "data" => site_data + { + "jekyll" => { + "version" => Jekyll::VERSION, + "environment" => Jekyll.env + }, + "site" => Utils.deep_merge_hashes(config, + Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], { + "time" => time, + "posts" => posts.sort { |a, b| b <=> a }, + "pages" => pages, + "static_files" => static_files.sort { |a, b| a.relative_path <=> b.relative_path }, + "html_pages" => pages.reject { |page| !page.html? }, + "categories" => post_attr_hash('categories'), + "tags" => post_attr_hash('tags'), + "collections" => collections, + "documents" => documents, + "data" => site_data })) } end From 3413c9684565ee27fa91e77e37e0b89c9a7b36bc Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 17 May 2014 00:47:03 -0400 Subject: [PATCH 3/3] Add test for Jekyll.env --- test/source/environment.html | 5 +++++ test/test_filters.rb | 2 +- test/test_site.rb | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/source/environment.html diff --git a/test/source/environment.html b/test/source/environment.html new file mode 100644 index 00000000..b875a61f --- /dev/null +++ b/test/source/environment.html @@ -0,0 +1,5 @@ +--- +title: I'm a Jekyll environment exchequer +--- + +{{ jekyll.environment }} diff --git a/test/test_filters.rb b/test/test_filters.rb index e56a88ce..22734378 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -137,7 +137,7 @@ class TestFilters < Test::Unit::TestCase assert_equal 2, g["items"].size when "" assert g["items"].is_a?(Array), "The list of grouped items for '' is not an Array." - assert_equal 10, g["items"].size + assert_equal 11, g["items"].size end end end diff --git a/test/test_site.rb b/test/test_site.rb index 94263491..de02b8dd 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -166,6 +166,7 @@ class TestSite < Test::Unit::TestCase coffeescript.coffee contacts.html deal.with.dots.html + environment.html exploit.md foo.md index.html @@ -407,5 +408,35 @@ class TestSite < Test::Unit::TestCase end end + + context "manipulating the Jekyll environment" do + setup do + @site = Site.new(site_configuration) + @site.process + @page = @site.pages.find { |p| p.name == "environment.html" } + end + + should "default to 'development'" do + assert_equal "development", @page.content.strip + end + + context "in production" do + setup do + ENV["JEKYLL_ENV"] = "production" + @site = Site.new(site_configuration) + @site.process + @page = @site.pages.find { |p| p.name == "environment.html" } + end + + teardown do + ENV.delete("JEKYLL_ENV") + end + + should "be overridden by JEKYLL_ENV" do + assert_equal "production", @page.content.strip + end + end + end + end end