Merge pull request #2417 from jekyll/jekyll-env

This commit is contained in:
Parker Moore 2014-05-17 00:53:55 -04:00
commit 4147e92561
5 changed files with 63 additions and 14 deletions

View File

@ -76,6 +76,15 @@ require 'jekyll-sass-converter'
SafeYAML::OPTIONS[:suppress_warnings] = true SafeYAML::OPTIONS[:suppress_warnings] = true
module Jekyll 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 # Public: Generate a Jekyll configuration Hash by merging the default
# options with anything in _config.yml, and adding the given options on top. # options with anything in _config.yml, and adding the given options on top.
# #

View File

@ -314,7 +314,11 @@ module Jekyll
# "tags" - The Hash of tag values and Posts. # "tags" - The Hash of tag values and Posts.
# See Site#post_attr_hash for type info. # See Site#post_attr_hash for type info.
def site_payload def site_payload
{"jekyll" => { "version" => Jekyll::VERSION }, {
"jekyll" => {
"version" => Jekyll::VERSION,
"environment" => Jekyll.env
},
"site" => Utils.deep_merge_hashes(config, "site" => Utils.deep_merge_hashes(config,
Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], { Utils.deep_merge_hashes(Hash[collections.map{|label, coll| [label, coll.docs]}], {
"time" => time, "time" => time,

View File

@ -0,0 +1,5 @@
---
title: I'm a Jekyll environment exchequer
---
{{ jekyll.environment }}

View File

@ -156,7 +156,7 @@ class TestFilters < Test::Unit::TestCase
assert_equal 2, g["items"].size assert_equal 2, g["items"].size
when "" when ""
assert g["items"].is_a?(Array), "The list of grouped items for '' is not an Array." 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 end
end end

View File

@ -166,6 +166,7 @@ class TestSite < Test::Unit::TestCase
coffeescript.coffee coffeescript.coffee
contacts.html contacts.html
deal.with.dots.html deal.with.dots.html
environment.html
exploit.md exploit.md
foo.md foo.md
index.html index.html
@ -407,5 +408,35 @@ class TestSite < Test::Unit::TestCase
end end
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
end end