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. # 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 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 fc09a850..f2480267 100644 --- a/test/test_filters.rb +++ b/test/test_filters.rb @@ -156,7 +156,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