Merge pull request #2417 from jekyll/jekyll-env
This commit is contained in:
commit
4147e92561
|
@ -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.
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: I'm a Jekyll environment exchequer
|
||||
---
|
||||
|
||||
{{ jekyll.environment }}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue