From 2aa407954d2e1d655ba4808d554b97072a76c077 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 21 Oct 2018 20:40:00 +0530 Subject: [PATCH 1/7] Setup AppVeyor builds --- README.md | 6 +++++- appveyor.yml | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 appveyor.yml diff --git a/README.md b/README.md index 785f66e..3dbb87f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,11 @@ Streamline your writing in Jekyll with some commands. -[![Build Status](https://travis-ci.org/jekyll/jekyll-compose.svg?branch=master)](https://travis-ci.org/jekyll/jekyll-compose) +[![Linux Build Status](https://img.shields.io/travis/jekyll/jekyll-compose/master.svg?label=Linux%20build)][travis] +[![Windows Build status](https://img.shields.io/appveyor/ci/jekyll/jekyll-compose/master.svg?label=Windows%20build)][appveyor] + +[travis]: https://travis-ci.org/jekyll/jekyll-compose +[appveyor]: https://ci.appveyor.com/project/jekyll/jekyll-compose ## Installation diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..6e25691 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,28 @@ +version: "{build}" +clone_depth: 5 +branches: + only: + - master + +build: off + +environment: + matrix: + - RUBY_FOLDER_VER: "25-x64" + - RUBY_FOLDER_VER: "25" + - RUBY_FOLDER_VER: "24" + - RUBY_FOLDER_VER: "23" + +install: + - SET PATH=C:\Ruby%RUBY_FOLDER_VER%\bin;%PATH% + - bundle install --retry 5 --jobs=%NUMBER_OF_PROCESSORS% --clean --path vendor\bundle + +test_script: + - ruby --version + - gem --version + - bundler --version + - bash ./script/cibuild + +cache: + # If one of the files after the right arrow changes, cache will be invalidated + - 'vendor\bundle -> appveyor.yml,Gemfile,jekyll-compose.gemspec' From 49365054d09e18aa252e25c588af35e1561ed694 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Fri, 26 Oct 2018 11:38:40 -0400 Subject: [PATCH 2/7] chore(deps): rubocop-jekyll 0.3 (#80) Merge pull request 80 --- .rubocop.yml | 28 ++-------------------------- .rubocop_todo.yml | 24 ++++++++++++++++++++++++ jekyll-compose.gemspec | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 65e92f6..03092af 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,30 +1,6 @@ +inherit_from: .rubocop_todo.yml + require: rubocop-jekyll inherit_gem: rubocop-jekyll: .rubocop.yml - -Lint/AmbiguousOperator: - Exclude: - - lib/jekyll/commands/draft.rb - - lib/jekyll/commands/page.rb - - lib/jekyll/commands/post.rb - -Metrics/LineLength: - Exclude: - - jekyll-compose.gemspec - - lib/jekyll-compose/file_creator.rb - - lib/jekyll-compose/file_mover.rb - - lib/jekyll/commands/draft.rb - - lib/jekyll/commands/page.rb - - lib/jekyll/commands/post.rb - - lib/jekyll/commands/publish.rb - - lib/jekyll/commands/unpublish.rb - - spec/**/* - -Metrics/BlockLength: - Exclude: - - spec/**/* - -Style/GlobalVars: - Exclude: - - spec/spec_helper.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..f9182d8 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,24 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2018-10-26 17:05:15 +0200 using RuboCop version 0.60.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +Lint/AmbiguousOperator: + Exclude: + - 'lib/jekyll/commands/draft.rb' + - 'lib/jekyll/commands/page.rb' + - 'lib/jekyll/commands/post.rb' + +# Offense count: 5 +# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Exclude: + - 'lib/jekyll-compose/file_creator.rb' + - 'lib/jekyll-compose/file_mover.rb' + - 'lib/jekyll/commands/publish.rb' + - 'lib/jekyll/commands/unpublish.rb' diff --git a/jekyll-compose.gemspec b/jekyll-compose.gemspec index 7022157..48c9a1c 100644 --- a/jekyll-compose.gemspec +++ b/jekyll-compose.gemspec @@ -25,5 +25,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.5" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "rubocop-jekyll", "~> 0.2" + spec.add_development_dependency "rubocop-jekyll", "~> 0.3" end From 311e50d5d2c507a0c9ff28f8c1c99afb79184f83 Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Fri, 26 Oct 2018 11:38:42 -0400 Subject: [PATCH 3/7] Update history to reflect merge of #80 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index 5fc8fa4..2e1fe04 100644 --- a/History.markdown +++ b/History.markdown @@ -5,6 +5,7 @@ * Replace `puts` calls with `Jekyll.logger.info` (#69) * Formatting of dates and times in a DRY manner (#60) * Appease newest Rubocop (#71) + * chore(deps): rubocop-jekyll 0.3 (#80) ### Minor Enhancements From a0fcf2cf76acce085ad61235a5d79e020f000eb4 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 31 Oct 2018 15:19:42 +0530 Subject: [PATCH 4/7] Mirror `draft` command to current `post` command (#79) Merge pull request 79 --- lib/jekyll/commands/draft.rb | 17 ++++++++++++- spec/draft_spec.rb | 48 +++++++++++++++++++++++++++++++++--- spec/post_spec.rb | 4 +-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/commands/draft.rb b/lib/jekyll/commands/draft.rb index d146039..01160a3 100644 --- a/lib/jekyll/commands/draft.rb +++ b/lib/jekyll/commands/draft.rb @@ -30,7 +30,9 @@ def self.process(args = [], options = {}) draft = DraftFileInfo.new params - Compose::FileCreator.new(draft, params.force?, params.source).create! + file_creator = Compose::FileCreator.new(draft, params.force?, params.source) + file_creator.create! + Compose::FileEditor.open_editor(file_creator.file_path) end class DraftFileInfo < Compose::FileInfo @@ -41,6 +43,19 @@ def resource_type def path "_drafts/#{file_name}" end + + def content(custom_front_matter = {}) + default_front_matter = compose_config["draft_default_front_matter"] + custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash) + + super(custom_front_matter) + end + + private + + def compose_config + @compose_config ||= Jekyll.configuration["jekyll_compose"] || {} + end end end end diff --git a/spec/draft_spec.rb b/spec/draft_spec.rb index 1d572ef..36c0943 100644 --- a/spec/draft_spec.rb +++ b/spec/draft_spec.rb @@ -13,6 +13,7 @@ before(:each) do FileUtils.mkdir_p drafts_dir unless File.directory? drafts_dir + allow(Jekyll::Compose::FileEditor).to receive(:system) end after(:each) do @@ -79,12 +80,15 @@ context "when a configuration file exists" do let(:config) { source_dir("_config.yml") } let(:drafts_dir) { Pathname.new source_dir(File.join("site", "_drafts")) } + let(:config_data) do + %( + source: site + ) + end before(:each) do File.open(config, "w") do |f| - f.write(%( -source: site -)) + f.write(config_data) end end @@ -97,6 +101,44 @@ capture_stdout { described_class.process(args) } expect(path).to exist end + + context "configuration is set" do + let(:drafts_dir) { Pathname.new source_dir("_drafts") } + let(:config_data) do + %( + jekyll_compose: + auto_open: true + draft_default_front_matter: + description: my description + category: + ) + end + + it "creates post with the specified config" do + capture_stdout { described_class.process(args) } + post = File.read(path) + expect(post).to match(%r!description: my description!) + expect(post).to match(%r!category: !) + end + + context "env variable EDITOR is set up" do + before { ENV["EDITOR"] = "nano" } + + it "opens post in default editor" do + expect(Jekyll::Compose::FileEditor).to receive(:run_editor).with("nano", path.to_s) + capture_stdout { described_class.process(args) } + end + + context "env variable JEKYLL_EDITOR is set up" do + before { ENV["JEKYLL_EDITOR"] = "nano" } + + it "opens post in jekyll editor" do + expect(Jekyll::Compose::FileEditor).to receive(:run_editor).with("nano", path.to_s) + capture_stdout { described_class.process(args) } + end + end + end + end end context "when source option is set" do diff --git a/spec/post_spec.rb b/spec/post_spec.rb index 77cbcb3..6d114e3 100644 --- a/spec/post_spec.rb +++ b/spec/post_spec.rb @@ -133,10 +133,10 @@ end context "env variable EDITOR is set up" do - before { ENV["EDITOR"] = "vim" } + before { ENV["EDITOR"] = "nano" } it "opens post in default editor" do - expect(Jekyll::Compose::FileEditor).to receive(:run_editor).with("vim", path.to_s) + expect(Jekyll::Compose::FileEditor).to receive(:run_editor).with("nano", path.to_s) capture_stdout { described_class.process(args) } end From cd4a687a6f5d4205fa55d010c18082b670239b4f Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Wed, 31 Oct 2018 05:49:44 -0400 Subject: [PATCH 5/7] Update history to reflect merge of #79 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index 2e1fe04..d44d60a 100644 --- a/History.markdown +++ b/History.markdown @@ -11,6 +11,7 @@ * Add some color to the success msg like jekyll new (#75) * Allow additional front matter for Post (#41) + * Mirror `draft` command to current `post` command (#79) ## 0.8.0 / 2018-03-24 From 5413e92dfa035b418727f630f9d282b1522963c0 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 31 Oct 2018 15:21:00 +0530 Subject: [PATCH 6/7] Generate configuration from CLI options (#76) Merge pull request 76 --- lib/jekyll-compose/arg_parser.rb | 6 ++++-- lib/jekyll-compose/file_editor.rb | 13 ++++++++----- lib/jekyll/commands/draft.rb | 3 ++- lib/jekyll/commands/page.rb | 3 ++- lib/jekyll/commands/post.rb | 13 +++++-------- lib/jekyll/commands/publish.rb | 3 ++- lib/jekyll/commands/unpublish.rb | 3 ++- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/jekyll-compose/arg_parser.rb b/lib/jekyll-compose/arg_parser.rb index 6e0b3e2..1aa08e6 100644 --- a/lib/jekyll-compose/arg_parser.rb +++ b/lib/jekyll-compose/arg_parser.rb @@ -4,10 +4,12 @@ module Jekyll module Compose class ArgParser attr_reader :args, :options, :config - def initialize(args, options) + + # TODO: Remove `nil` parameter in v1.0 + def initialize(args, options, config = nil) @args = args @options = options - @config = Jekyll.configuration(options) + @config = config || Jekyll.configuration(options) end def validate! diff --git a/lib/jekyll-compose/file_editor.rb b/lib/jekyll-compose/file_editor.rb index 6b48455..c05f004 100644 --- a/lib/jekyll-compose/file_editor.rb +++ b/lib/jekyll-compose/file_editor.rb @@ -16,6 +16,13 @@ module Jekyll module Compose class FileEditor class << self + attr_reader :compose_config + alias_method :jekyll_compose_config, :compose_config + + def bootstrap(config) + @compose_config = config["jekyll_compose"] || {} + end + def open_editor(filepath) run_editor(post_editor, File.expand_path(filepath)) if post_editor end @@ -31,11 +38,7 @@ def post_editor end def auto_open? - jekyll_compose_config && jekyll_compose_config["auto_open"] - end - - def jekyll_compose_config - @jekyll_compose_config ||= Jekyll.configuration["jekyll_compose"] + compose_config["auto_open"] end end end diff --git a/lib/jekyll/commands/draft.rb b/lib/jekyll/commands/draft.rb index 01160a3..a9770f9 100644 --- a/lib/jekyll/commands/draft.rb +++ b/lib/jekyll/commands/draft.rb @@ -25,7 +25,8 @@ def self.options end def self.process(args = [], options = {}) - params = Compose::ArgParser.new args, options + config = configuration_from_options(options) + params = Compose::ArgParser.new args, options, config params.validate! draft = DraftFileInfo.new params diff --git a/lib/jekyll/commands/page.rb b/lib/jekyll/commands/page.rb index 2b18149..cd60396 100644 --- a/lib/jekyll/commands/page.rb +++ b/lib/jekyll/commands/page.rb @@ -25,7 +25,8 @@ def self.options end def self.process(args = [], options = {}) - params = PageArgParser.new args, options + config = configuration_from_options(options) + params = PageArgParser.new args, options, config params.validate! page = PageFileInfo.new params diff --git a/lib/jekyll/commands/post.rb b/lib/jekyll/commands/post.rb index 5279e03..06d6b63 100644 --- a/lib/jekyll/commands/post.rb +++ b/lib/jekyll/commands/post.rb @@ -26,13 +26,16 @@ def self.options end def self.process(args = [], options = {}) - params = PostArgParser.new args, options + config = configuration_from_options(options) + params = PostArgParser.new args, options, config params.validate! post = PostFileInfo.new params file_creator = Compose::FileCreator.new(post, params.force?, params.source) file_creator.create! + + Compose::FileEditor.bootstrap(config) Compose::FileEditor.open_editor(file_creator.file_path) end @@ -64,17 +67,11 @@ def _time_stamp end def content(custom_front_matter = {}) - default_front_matter = compose_config["post_default_front_matter"] + default_front_matter = params.config.dig("jekyll_compose", "post_default_front_matter") custom_front_matter.merge!(default_front_matter) if default_front_matter.is_a?(Hash) super({ "date" => _time_stamp }.merge(custom_front_matter)) end - - private - - def compose_config - @compose_config ||= Jekyll.configuration["jekyll_compose"] || {} - end end end end diff --git a/lib/jekyll/commands/publish.rb b/lib/jekyll/commands/publish.rb index 2ddedff..3aa7ec7 100644 --- a/lib/jekyll/commands/publish.rb +++ b/lib/jekyll/commands/publish.rb @@ -20,7 +20,8 @@ def self.init_with_program(prog) end def self.process(args = [], options = {}) - params = PublishArgParser.new args, options + config = configuration_from_options(options) + params = PublishArgParser.new args, options, config params.validate! movement = DraftMovementInfo.new params diff --git a/lib/jekyll/commands/unpublish.rb b/lib/jekyll/commands/unpublish.rb index fb67993..e5c7416 100644 --- a/lib/jekyll/commands/unpublish.rb +++ b/lib/jekyll/commands/unpublish.rb @@ -19,7 +19,8 @@ def self.init_with_program(prog) end def self.process(args = [], options = {}) - params = UnpublishArgParser.new args, options + config = configuration_from_options(options) + params = UnpublishArgParser.new args, options, config params.validate! movement = PostMovementInfo.new params From bf68687c301fb4a5c38e9414eadb61690c6a511c Mon Sep 17 00:00:00 2001 From: jekyllbot Date: Wed, 31 Oct 2018 05:51:02 -0400 Subject: [PATCH 7/7] Update history to reflect merge of #76 [ci skip] --- History.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/History.markdown b/History.markdown index d44d60a..1d8b439 100644 --- a/History.markdown +++ b/History.markdown @@ -12,6 +12,7 @@ * Add some color to the success msg like jekyll new (#75) * Allow additional front matter for Post (#41) * Mirror `draft` command to current `post` command (#79) + * Generate configuration from CLI options (#76) ## 0.8.0 / 2018-03-24