forked from jekyll/jekyll-compose
/
arg_parser.rb
40 lines (32 loc) · 831 Bytes
/
arg_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true
module Jekyll
module Compose
class ArgParser
attr_reader :args, :options, :config
# TODO: Remove `nil` parameter in v1.0
def initialize(args, options, config = nil)
@args = args
@options = options
@config = config || Jekyll.configuration(options)
end
def validate!
raise ArgumentError, "You must specify a name." if args.empty?
end
def type
options["extension"] || Jekyll::Compose::DEFAULT_TYPE
end
def layout
options["layout"] || Jekyll::Compose::DEFAULT_LAYOUT
end
def title
args.join " "
end
def force?
!!options["force"]
end
def source
config["source"].gsub(%r!^#{Regexp.quote(Dir.pwd)}!, "")
end
end
end
end