From b249289b9d01091d0423f869a4fc9d07ebf0c283 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 16:40:05 +0200 Subject: [PATCH 01/14] Set the timezone for the process --- lib/jekyll.rb | 16 +++++++++++++++- lib/jekyll/configuration.rb | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index d8eb7a54..f4bea173 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -73,6 +73,20 @@ module Jekyll config = config.read_config_files(config.config_files(override)) # Merge DEFAULTS < _config.yml < override - config.deep_merge(override).stringify_keys + config = config.deep_merge(override).stringify_keys + set_timezone(config) + + config + end + + # Static: Set the TZ environment variable to use the timezone specified + # + # config - the Jekyll::Configuration generated by Jekyll.configuration + # + # Returns nothing + def self.set_timezone(config) + if config['timezone'] + ENV['TZ'] = config['timezone'] + end end end diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 9433a015..7d676bfd 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -10,6 +10,8 @@ module Jekyll 'layouts' => '_layouts', 'keep_files' => ['.git','.svn'], + 'timezone' => nil # use the local timezone + 'safe' => false, 'show_drafts' => nil, 'limit_posts' => nil, From c0a2d0f88835629a1bb3f8aae164a44fed6a3b52 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 13 Apr 2013 16:45:42 +0200 Subject: [PATCH 02/14] Fixed syntax error --- lib/jekyll/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index 7d676bfd..3544b98b 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -10,7 +10,7 @@ module Jekyll 'layouts' => '_layouts', 'keep_files' => ['.git','.svn'], - 'timezone' => nil # use the local timezone + 'timezone' => nil, # use the local timezone 'safe' => false, 'show_drafts' => nil, From d6a08b093ac1f4e96f2b84dca7b10fc97c426944 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 14 Apr 2013 20:20:56 +0200 Subject: [PATCH 03/14] Add docs for timezone setting. --- site/_posts/2012-07-01-configuration.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/site/_posts/2012-07-01-configuration.md b/site/_posts/2012-07-01-configuration.md index 30e20f8d..bca5dc69 100644 --- a/site/_posts/2012-07-01-configuration.md +++ b/site/_posts/2012-07-01-configuration.md @@ -81,6 +81,21 @@ class="flag">flags (specified on the command-line) that control them.

include: [DIR, FILE, ...]

+ + +

Time Zone

+

+ Set the time zone for site generation. This sets the TZ + shell environment variable, which Ruby uses to handle time and date + creation and manipulation. Any entry from the + IANA Time Zone + Database is valid. +

+ + +

timezone: TIMEZONE

+ + From fbf818b6181044ab751a66121120f9ae82c97022 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 14 Apr 2013 20:23:20 +0200 Subject: [PATCH 04/14] Add example TZ and default value note. --- site/_posts/2012-07-01-configuration.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/site/_posts/2012-07-01-configuration.md b/site/_posts/2012-07-01-configuration.md index bca5dc69..11cb9dd5 100644 --- a/site/_posts/2012-07-01-configuration.md +++ b/site/_posts/2012-07-01-configuration.md @@ -89,7 +89,8 @@ class="flag">flags (specified on the command-line) that control them. shell environment variable, which Ruby uses to handle time and date creation and manipulation. Any entry from the IANA Time Zone - Database is valid. + Database is valid, e.g. America/New_York. The default + is the local time zone, as set by your operating system.

From b51b796a1e558e384e71b3da9cd3556c38cc468a Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 14 Apr 2013 20:59:31 +0200 Subject: [PATCH 05/14] Feature for timezone switching --- features/site_configuration.feature | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/features/site_configuration.feature b/features/site_configuration.feature index c07a3c73..f5974d0b 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -116,6 +116,34 @@ Feature: Site configuration And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" + Scenario: Generate proper dates with explicitly set timezone + Given I have a _layouts directory + And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: \"%Y-%m-%d\" }}" + And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" + And I have an "index.html" page with layout "page" that contains "site index page" + And I have a configuration file with: + | key | value | + | time | 2013-04-10 | + | timezone | America/New_York | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | "2013-04-09 23:22 -0400" | post | content for entry1. | + | entry2 | "2013-04-10 03:14 -0400" | post | content for entry2. | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 2 on 2013-04-10" in "_site/index.html" + And I should see "Post Layout:

content for entry1.

built at 2013-04-09T23:22:00-04:00" in "_site/2013/04/09/entry1.html" + And I should see "Post Layout:

content for entry2.

built at 2013-04-10T03:14:00-04:00" in "_site/2013/04/10/entry2.html" + And I have a configuration file with: + | key | value | + | timezone | Australia/Melbourne | + When I run jekyll + Then the _site directory should exist + And I should see "Page Layout: 2 on 2013-04-10" in "_site/index.html" + And I should see "Post Layout:

content for entry1.

built at 2013-04-10T13:14:00+10:00" in "_site/2013/04/10/entry1.html" + And I should see "Post Layout:

content for entry2.

built at 2013-04-10T17:14:00+10:00" in "_site/2013/04/10/entry2.html" + Scenario: Limit the number of posts generated by most recent date Given I have a _posts directory And I have a configuration file with: From 48795462c2896f68ddd2a69e1c63fb4ea29b541b Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 14 Apr 2013 20:59:40 +0200 Subject: [PATCH 06/14] Cucumber: remove test dir if it's there --- features/step_definitions/jekyll_steps.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index fd58679d..65556d37 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -1,4 +1,7 @@ Before do + if File.directory?(TEST_DIR) + FileUtils.rm_rf(TEST_DIR) + end FileUtils.mkdir(TEST_DIR) Dir.chdir(TEST_DIR) end From df868b308a624ecd7b87eee1c42977ab6aec08f6 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sun, 14 Apr 2013 21:00:03 +0200 Subject: [PATCH 07/14] Set Jekyll path relative to the env file, not to CWD --- features/support/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index 7e550c6c..8522fa7d 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -7,7 +7,7 @@ World do end TEST_DIR = File.join('/', 'tmp', 'jekyll') -JEKYLL_PATH = File.join(ENV['PWD'], 'bin', 'jekyll') +JEKYLL_PATH = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'jekyll') def run_jekyll(opts = {}) command = JEKYLL_PATH.clone From 9c57fad430d5a7a08923da49b35710962ae95cc0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 00:31:40 +0200 Subject: [PATCH 08/14] Finished feature for timezone shifting. --- features/site_configuration.feature | 32 ++++++++++++++++------- features/step_definitions/jekyll_steps.rb | 19 ++++++++++++-- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/features/site_configuration.feature b/features/site_configuration.feature index f5974d0b..90afd919 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -116,33 +116,45 @@ Feature: Site configuration And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" - Scenario: Generate proper dates with explicitly set timezone + Scenario: Generate proper dates with explicitly set timezone (which is the same) Given I have a _layouts directory - And I have a page layout that contains "Page Layout: {{ site.posts.size }} on {{ site.time | date: \"%Y-%m-%d\" }}" + And I have a page layout that contains "Page Layout: {{ site.posts.size }}" And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" And I have an "index.html" page with layout "page" that contains "site index page" And I have a configuration file with: | key | value | - | time | 2013-04-10 | | timezone | America/New_York | And I have a _posts directory And I have the following posts: - | title | date | layout | content | - | entry1 | "2013-04-09 23:22 -0400" | post | content for entry1. | - | entry2 | "2013-04-10 03:14 -0400" | post | content for entry2. | + | title | date | layout | content | + | entry1 | 2013-04-09 23:22 -0400 | post | content for entry1. | + | entry2 | 2013-04-10 03:14 -0400 | post | content for entry2. | When I run jekyll Then the _site directory should exist - And I should see "Page Layout: 2 on 2013-04-10" in "_site/index.html" + And I should see "Page Layout: 2" in "_site/index.html" And I should see "Post Layout:

content for entry1.

built at 2013-04-09T23:22:00-04:00" in "_site/2013/04/09/entry1.html" And I should see "Post Layout:

content for entry2.

built at 2013-04-10T03:14:00-04:00" in "_site/2013/04/10/entry2.html" + + Scenario: Generate proper dates with explicitly set timezone, which is very different + Given I have a _layouts directory + And I have a page layout that contains "Page Layout: {{ site.posts.size }}" + And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" + And I have an "index.html" page with layout "page" that contains "site index page" And I have a configuration file with: | key | value | | timezone | Australia/Melbourne | + And I have a _posts directory + And I have the following posts: + | title | date | layout | content | + | entry1 | 2013-04-09 23:22 -0400 | post | content for entry1. | + | entry2 | 2013-04-10 03:14 -0400 | post | content for entry2. | When I run jekyll Then the _site directory should exist - And I should see "Page Layout: 2 on 2013-04-10" in "_site/index.html" - And I should see "Post Layout:

content for entry1.

built at 2013-04-10T13:14:00+10:00" in "_site/2013/04/10/entry1.html" - And I should see "Post Layout:

content for entry2.

built at 2013-04-10T17:14:00+10:00" in "_site/2013/04/10/entry2.html" + And I should see "Page Layout: 2" in "_site/index.html" + And the "_site/2013/04/10/entry1.html" file should exist + And the "_site/2013/04/10/entry2.html" file should exist + And I should see escaped "Post Layout:

content for entry1.

built at 2013-04-10T13:22:00+10:00" in "_site/2013/04/10/entry1.html" + And I should see escaped "Post Layout:

content for entry2.

built at 2013-04-10T17:14:00+10:00" in "_site/2013/04/10/entry2.html" Scenario: Limit the number of posts generated by most recent date Given I have a _posts directory diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 65556d37..c56ec42e 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -64,7 +64,15 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire if "draft" == status path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}") else - date = Date.strptime(post['date'], '%m/%d/%Y').strftime('%Y-%m-%d') + date = if post['date'].split.size > 1 + parsed_date = DateTime.strptime(post['date'], '%Y-%m-%d %H:%M %z') + post['date'] = parsed_date.to_s + parsed_date.strftime('%Y-%m-%d') + else + parsed_date = Date.strptime(post['date'], '%m/%d/%Y') # WHY WOULD YOU EVER DO THIS + post['date'] = parsed_date.to_s + parsed_date.strftime('%Y-%m-%d') + end path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}") end @@ -72,6 +80,9 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire %w(title layout tag tags category categories published author path).each do |key| matter_hash[key] = post[key] if post[key] end + if "post" == status + matter_hash["date"] = post["date"] if post["date"] + end matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp content = post['content'] @@ -137,7 +148,11 @@ Then /^the (.*) directory should exist$/ do |dir| end Then /^I should see "(.*)" in "(.*)"$/ do |text, file| - assert_match Regexp.new(text), File.open(file).readlines.join + assert Regexp.new(text).match(File.open(file).readlines.join) +end + +Then /^I should see escaped "(.*)" in "(.*)"$/ do |text, file| + assert Regexp.new(Regexp.escape(text)).match(File.open(file).readlines.join) end Then /^the "(.*)" file should exist$/ do |file| From 88e68e038a34896331661918aa723784f570bfa0 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 14:32:14 +0200 Subject: [PATCH 09/14] Extract out date parsing in feature steps --- features/step_definitions/jekyll_steps.rb | 13 ++++++------- features/support/env.rb | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index c56ec42e..6dc88f14 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -64,15 +64,14 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire if "draft" == status path = File.join(before || '.', '_drafts', after || '.', "#{title}.#{ext}") else - date = if post['date'].split.size > 1 - parsed_date = DateTime.strptime(post['date'], '%Y-%m-%d %H:%M %z') - post['date'] = parsed_date.to_s - parsed_date.strftime('%Y-%m-%d') + format = if has_time_component?(post['date']) + '%Y-%m-%d %H:%M %z' else - parsed_date = Date.strptime(post['date'], '%m/%d/%Y') # WHY WOULD YOU EVER DO THIS - post['date'] = parsed_date.to_s - parsed_date.strftime('%Y-%m-%d') + '%m/%d/%Y' # why even end + parsed_date = DateTime.strptime(post['date'], format) + post['date'] = parsed_date.to_s + date = parsed_date.strftime('%Y-%m-%d') path = File.join(before || '.', '_posts', after || '.', "#{date}-#{title}.#{ext}") end diff --git a/features/support/env.rb b/features/support/env.rb index 8522fa7d..38bab950 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -17,5 +17,9 @@ def run_jekyll(opts = {}) system command end +def has_time_component?(date_string) + date_string.split(" ").size > 1 +end + # work around "invalid option: --format" cucumber bug (see #296) Test::Unit.run = true if RUBY_VERSION < '1.9' From 83cb01dd596efa600b6bc400f156596cc1fc8b31 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 14:33:52 +0200 Subject: [PATCH 10/14] Using File.exists? more generally instead of File.directory? so /tmp/jekyll is always removed before running tests --- features/step_definitions/jekyll_steps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 6dc88f14..ab0fed53 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -1,5 +1,5 @@ Before do - if File.directory?(TEST_DIR) + if File.exists?(TEST_DIR) FileUtils.rm_rf(TEST_DIR) end FileUtils.mkdir(TEST_DIR) From aa1f52fce82537ccacff17271dec992f240602bb Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 14:35:28 +0200 Subject: [PATCH 11/14] Renamed timezone feature scenarios --- features/site_configuration.feature | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/site_configuration.feature b/features/site_configuration.feature index 90afd919..14f29be7 100644 --- a/features/site_configuration.feature +++ b/features/site_configuration.feature @@ -116,7 +116,7 @@ Feature: Site configuration And I should see "Post Layout:

content for entry1.

" in "_site/2007/12/31/entry1.html" And I should see "Post Layout:

content for entry2.

" in "_site/2020/01/31/entry2.html" - Scenario: Generate proper dates with explicitly set timezone (which is the same) + Scenario: Generate proper dates with explicitly set timezone (same as posts' time) Given I have a _layouts directory And I have a page layout that contains "Page Layout: {{ site.posts.size }}" And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" @@ -135,7 +135,7 @@ Feature: Site configuration And I should see "Post Layout:

content for entry1.

built at 2013-04-09T23:22:00-04:00" in "_site/2013/04/09/entry1.html" And I should see "Post Layout:

content for entry2.

built at 2013-04-10T03:14:00-04:00" in "_site/2013/04/10/entry2.html" - Scenario: Generate proper dates with explicitly set timezone, which is very different + Scenario: Generate proper dates with explicitly set timezone (different than posts' time) Given I have a _layouts directory And I have a page layout that contains "Page Layout: {{ site.posts.size }}" And I have a post layout that contains "Post Layout: {{ content }} built at {{ page.date | date_to_xmlschema }}" From b68d33ed8bf865621e68cfb8b61614caaae579fe Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 14:37:37 +0200 Subject: [PATCH 12/14] Remove 'shell' from description of changing TZ --- site/_posts/2012-07-01-configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/_posts/2012-07-01-configuration.md b/site/_posts/2012-07-01-configuration.md index 11cb9dd5..1556d449 100644 --- a/site/_posts/2012-07-01-configuration.md +++ b/site/_posts/2012-07-01-configuration.md @@ -86,7 +86,7 @@ class="flag">flags (specified on the command-line) that control them.

Time Zone

Set the time zone for site generation. This sets the TZ - shell environment variable, which Ruby uses to handle time and date + environment variable, which Ruby uses to handle time and date creation and manipulation. Any entry from the IANA Time Zone Database is valid, e.g. America/New_York. The default From b4f68baafb533d49843a39bb1ce34299206f5239 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 15:39:36 +0200 Subject: [PATCH 13/14] Jekyll.set_timezone accepts just the timezone, not the config --- lib/jekyll.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/jekyll.rb b/lib/jekyll.rb index f4bea173..662a471c 100644 --- a/lib/jekyll.rb +++ b/lib/jekyll.rb @@ -74,19 +74,17 @@ module Jekyll # Merge DEFAULTS < _config.yml < override config = config.deep_merge(override).stringify_keys - set_timezone(config) + set_timezone(config['timezone']) if config['timezone'] config end # Static: Set the TZ environment variable to use the timezone specified # - # config - the Jekyll::Configuration generated by Jekyll.configuration + # timezone - the IANA Time Zone # # Returns nothing - def self.set_timezone(config) - if config['timezone'] - ENV['TZ'] = config['timezone'] - end + def self.set_timezone(timezone) + ENV['TZ'] = timezone end end From 457e90fd414cb0107f2cf377e44f9c0e123978cd Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 15 Apr 2013 15:42:21 +0200 Subject: [PATCH 14/14] Just remove the darn TEST_DIR --- features/step_definitions/jekyll_steps.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index ab0fed53..c30b9034 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -1,7 +1,5 @@ Before do - if File.exists?(TEST_DIR) - FileUtils.rm_rf(TEST_DIR) - end + FileUtils.rm_rf(TEST_DIR) FileUtils.mkdir(TEST_DIR) Dir.chdir(TEST_DIR) end