Skip to content

Commit d7bb9af

Browse files
author
Matthew Loberg
committed
Refactor ArgParser to load Jekyll configuration
Load in Jekyll configuration when parsing args. Add source method to return Jekyll source directory and update the drafts command to use this new method.
1 parent f959e64 commit d7bb9af

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/jekyll-compose/arg_parser.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
class Jekyll::Compose::ArgParser
2-
attr_reader :args, :options
2+
attr_reader :args, :options, :config
33
def initialize(args, options)
44
@args = args
55
@options = options
6+
@config = Jekyll.configuration(options)
67
end
78

89
def validate!
@@ -24,4 +25,8 @@ def title
2425
def force?
2526
!!options["force"]
2627
end
28+
29+
def source
30+
source = config['source'].gsub(/^#{Regexp.quote(Dir.pwd)}/, '')
31+
end
2732
end

lib/jekyll/commands/draft.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@ def self.options
2424

2525

2626
def self.process(args = [], options = {})
27-
config = configuration_from_options(options)
28-
2927
params = Compose::ArgParser.new args, options
3028
params.validate!
3129

3230
draft = DraftFileInfo.new params
3331

34-
root = config['source'].gsub(/^#{Regexp.quote(Dir.pwd)}/, '')
35-
36-
Compose::FileCreator.new(draft, params.force?, root).create!
32+
Compose::FileCreator.new(draft, params.force?, params.source).create!
3733
end
3834

3935
class DraftFileInfo < Compose::FileInfo

0 commit comments

Comments
 (0)