Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting of dates and times in a DRY manner #60

Merged
merged 2 commits into from May 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/jekyll-compose.rb
Expand Up @@ -12,6 +12,8 @@ module Compose
DEFAULT_TYPE = "md".freeze
DEFAULT_LAYOUT = "post".freeze
DEFAULT_LAYOUT_PAGE = "page".freeze
DEFAULT_DATESTAMP_FORMAT = "%Y-%m-%d".freeze
DEFAULT_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M %z".freeze
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll/commands/post.rb
Expand Up @@ -54,11 +54,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 @@ -54,7 +54,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 @@ -67,7 +67,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