Skip to content

Commit

Permalink
Merge branch 'master' into collections-dir-support
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Oct 31, 2018
2 parents f4e8655 + bf68687 commit 5de5b26
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 50 deletions.
28 changes: 2 additions & 26 deletions .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
24 changes: 24 additions & 0 deletions .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'
3 changes: 3 additions & 0 deletions History.markdown
Expand Up @@ -5,11 +5,14 @@
* 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

* 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

Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions 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'
2 changes: 1 addition & 1 deletion jekyll-compose.gemspec
Expand Up @@ -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
6 changes: 4 additions & 2 deletions lib/jekyll-compose/arg_parser.rb
Expand Up @@ -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!
Expand Down
13 changes: 8 additions & 5 deletions lib/jekyll-compose/file_editor.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 18 additions & 2 deletions lib/jekyll/commands/draft.rb
Expand Up @@ -25,12 +25,15 @@ 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

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
Expand All @@ -41,6 +44,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
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll/commands/page.rb
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions lib/jekyll/commands/post.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll/commands/publish.rb
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll/commands/unpublish.rb
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions spec/draft_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -101,6 +102,44 @@
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

context "and collections_dir is set" do
let(:collections_dir) { "my_collections" }
let(:drafts_dir) { Pathname.new source_dir("site", collections_dir, "_drafts") }
Expand Down
4 changes: 2 additions & 2 deletions spec/post_spec.rb
Expand Up @@ -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

Expand Down

0 comments on commit 5de5b26

Please sign in to comment.