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

Generate configuration from CLI options #76

Merged
merged 3 commits into from Oct 31, 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
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 @@ -30,11 +37,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
3 changes: 2 additions & 1 deletion lib/jekyll/commands/draft.rb
Expand Up @@ -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
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
5 changes: 4 additions & 1 deletion 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
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