diff --git a/lib/jekyll-compose.rb b/lib/jekyll-compose.rb index 92f34ec..b492052 100644 --- a/lib/jekyll-compose.rb +++ b/lib/jekyll-compose.rb @@ -2,6 +2,8 @@ module Jekyll module Compose + DEFAULT_TYPE = "md" + DEFAULT_LAYOUT = "post" end end diff --git a/lib/jekyll/commands/draft.rb b/lib/jekyll/commands/draft.rb index 2bd0be9..7272f42 100644 --- a/lib/jekyll/commands/draft.rb +++ b/lib/jekyll/commands/draft.rb @@ -19,8 +19,8 @@ def self.init_with_program(prog) def self.process(args = [], options = {}) raise ArgumentError.new('You must specify a name.') if args.empty? - type = options["type"] || "markdown" - layout = options["layout"] || "post" + type = options["type"] || Jekyll::Compose::DEFAULT_TYPE + layout = options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT title = args.shift name = title.gsub(' ', '-').downcase @@ -38,7 +38,7 @@ def self.process(args = [], options = {}) # Internal: Gets the filename of the draft to be created # # Returns the filename of the draft, as a String - def self.draft_name(name, ext='markdown') + def self.draft_name(name, ext=Jekyll::Compose::DEFAULT_TYPE) "_drafts/#{name}.#{ext}" end diff --git a/lib/jekyll/commands/post.rb b/lib/jekyll/commands/post.rb index da35d02..6b939d6 100644 --- a/lib/jekyll/commands/post.rb +++ b/lib/jekyll/commands/post.rb @@ -20,8 +20,8 @@ def self.init_with_program(prog) def self.process(args = [], options = {}) raise ArgumentError.new('You must specify a name.') if args.empty? - type = options["type"].nil? ? "markdown" : options["type"] - layout = options["layout"].nil? ? "post" : options["layout"] + type = options["type"] || Jekyll::Compose::DEFAULT_TYPE + layout = options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT date = options["date"].nil? ? Time.now : DateTime.parse(options["date"]) diff --git a/spec/draft_spec.rb b/spec/draft_spec.rb index 0d03d73..2556342 100644 --- a/spec/draft_spec.rb +++ b/spec/draft_spec.rb @@ -2,7 +2,7 @@ let(:name) { 'A test post' } let(:args) { [name] } let(:drafts_dir) { Pathname.new source_dir('_drafts') } - let(:path) { drafts_dir.join('a-test-post.markdown') } + let(:path) { drafts_dir.join('a-test-post.md') } before(:all) do FileUtils.mkdir_p source_dir unless File.directory? source_dir @@ -25,7 +25,7 @@ it 'writes a helpful success message' do output = capture_stdout { described_class.process(args) } - expect(output).to eql("New draft created at ./_drafts/a-test-post.markdown.\n") + expect(output).to eql("New draft created at ./_drafts/a-test-post.md.\n") end it 'errors with no arguments' do @@ -36,7 +36,7 @@ context 'when the draft already exists' do let(:name) { 'An existing draft' } - let(:path) { drafts_dir.join('an-existing-draft.markdown') } + let(:path) { drafts_dir.join('an-existing-draft.md') } before(:each) do FileUtils.touch path @@ -45,7 +45,7 @@ it 'raises an error' do expect(-> { capture_stdout { described_class.process(args) } - }).to raise_error("A draft already exists at ./_drafts/an-existing-draft.markdown") + }).to raise_error("A draft already exists at ./_drafts/an-existing-draft.md") end it 'overwrites if --force is given' do diff --git a/spec/post_spec.rb b/spec/post_spec.rb index e9b27a5..d94485a 100644 --- a/spec/post_spec.rb +++ b/spec/post_spec.rb @@ -2,7 +2,7 @@ let(:name) { 'A test post' } let(:args) { [name] } let(:posts_dir) { Pathname.new source_dir('_posts') } - let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-a-test-post.markdown" } + let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-a-test-post.md" } let(:path) { posts_dir.join(filename) } before(:all) do @@ -37,7 +37,7 @@ context 'when the post already exists' do let(:name) { 'An existing post' } - let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-an-existing-post.markdown" } + let(:filename) { "#{Time.now.strftime('%Y-%m-%d')}-an-existing-post.md" } before(:each) do FileUtils.touch path