Skip to content

Commit

Permalink
Merge pull request #2417 from jekyll/jekyll-env
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr committed May 17, 2014
2 parents 5d6f6b0 + 3413c96 commit 4147e92
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
9 changes: 9 additions & 0 deletions lib/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def require_all(path)
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.
#
Expand Down
30 changes: 17 additions & 13 deletions lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,23 @@ def site_data
# "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
Expand Down
5 changes: 5 additions & 0 deletions test/source/environment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: I'm a Jekyll environment exchequer
---

{{ jekyll.environment }}
2 changes: 1 addition & 1 deletion test/test_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def initialize(opts = {})
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
Expand Down
31 changes: 31 additions & 0 deletions test/test_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def generate(site)
coffeescript.coffee
contacts.html
deal.with.dots.html
environment.html
exploit.md
foo.md
index.html
Expand Down Expand Up @@ -407,5 +408,35 @@ def convert(*args)
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

0 comments on commit 4147e92

Please sign in to comment.