Skip to content

Commit

Permalink
Formatting of dates and times in a DRY manner (#60)
Browse files Browse the repository at this point in the history
Merge pull request 60
  • Loading branch information
alzeih authored and jekyllbot committed May 24, 2018
1 parent d2e3004 commit eaee85f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/jekyll-compose.rb
Expand Up @@ -13,6 +13,8 @@ module Compose
DEFAULT_TYPE = "md"
DEFAULT_LAYOUT = "post"
DEFAULT_LAYOUT_PAGE = "page"
DEFAULT_DATESTAMP_FORMAT = "%Y-%m-%d"
DEFAULT_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M %z"
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll/commands/post.rb
Expand Up @@ -56,11 +56,11 @@ def file_name
end

def _date_stamp
@params.date.strftime "%Y-%m-%d"
@params.date.strftime Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT
end

def _time_stamp
@params.date.strftime("%Y-%m-%d %H:%M %z")
@params.date.strftime Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT
end

def content(custom_front_matter = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/commands/publish.rb
Expand Up @@ -55,7 +55,7 @@ def from
end

def to
date_stamp = params.date.strftime "%Y-%m-%d"
date_stamp = params.date.strftime Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT
"_posts/#{date_stamp}-#{params.name}"
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/post_spec.rb
Expand Up @@ -4,8 +4,8 @@
let(:name) { "A test post" }
let(:args) { [name] }
let(:posts_dir) { Pathname.new source_dir("_posts") }
let(:datestamp) { Time.now.strftime("%Y-%m-%d") }
let(:timestamp) { Time.now.strftime("%Y-%m-%d %H:%M %z") }
let(:datestamp) { Time.now.strftime(Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT) }
let(:timestamp) { Time.now.strftime(Jekyll::Compose::DEFAULT_TIMESTAMP_FORMAT) }
let(:filename) { "#{datestamp}-a-test-post.md" }
let(:path) { posts_dir.join(filename) }

Expand Down Expand Up @@ -68,7 +68,7 @@

context "when the post already exists" do
let(:name) { "An existing post" }
let(:filename) { "#{Time.now.strftime("%Y-%m-%d")}-an-existing-post.md" }
let(:filename) { "#{Time.now.strftime(Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT)}-an-existing-post.md" }

before(:each) do
FileUtils.touch path
Expand Down
2 changes: 1 addition & 1 deletion spec/publish_spec.rb
Expand Up @@ -4,7 +4,7 @@
let(:drafts_dir) { Pathname.new source_dir("_drafts") }
let(:posts_dir) { Pathname.new source_dir("_posts") }
let(:draft_to_publish) { "a-test-post.md" }
let(:datestamp) { Time.now.strftime("%Y-%m-%d") }
let(:datestamp) { Time.now.strftime(Jekyll::Compose::DEFAULT_DATESTAMP_FORMAT) }
let(:post_filename) { "#{datestamp}-#{draft_to_publish}" }
let(:args) { ["_drafts/#{draft_to_publish}"] }

Expand Down

0 comments on commit eaee85f

Please sign in to comment.