Class: JekyllLiquidDebug::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-liquid-debug.rb

Class Method Summary collapse

Class Method Details

.func_set_file(file) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/jekyll-liquid-debug.rb', line 65

def self.func_set_file(file)
  if File.file?(file)
    return file
  else
    puts "Fatal: < #{file} > is not a file"
    exit
  end
end

.parse(options) ⇒ Object



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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jekyll-liquid-debug.rb', line 10

def self.parse(options)
  # Hash to contain all settings
  # it is needed to set default values, to help use Struct make Hash dottable.
  # because Struct does not have method to check whether key exists
  args = {file:false, html:false, kmd:false, outhtml:false, outmd:false,
          yaml:false,
  }
  OptionParser.new do |opt|
    opt.banner = "Usage: jekyll-liquid-debug [options]"
    opt.separator ""
    opt.separator "Input files:"

    opt.on("-f", "--file [FILE]", String, "input liquid template") do |v|
      args[:file] = Parser.func_set_file(v)
    end

    opt.on("-t", "--html [FILE]", String, "input html template") do |v|
      args[:html] = Parser.func_set_file(v)
    end

    opt.on("-y", "--yaml [FILE]", String, "input YAML file, parsed to `site.[var]'") do |v|
      args[:yaml] = Parser.func_set_file(v)
    end

    opt.on("-k", "--md [FILE]", String, "input raw markdown file, precedent for option `-t'") do |v|
      args[:kmd] = Parser.func_set_file(v)
    end

    opt.on("--out-html", TrueClass, "output html file, overwrite may happen") do |v|
      args[:outhtml] = true
    end

    opt.on("--out-md", TrueClass, "output markdown file, overwrite may happen") do |v|
      args[:outmd] = true
    end

    opt.separator ""
    opt.separator "Common options:"
    opt.on_tail("-h", "--help", "Show help message") do
      puts opt
      exit
    end
    opt.on_tail("-v", "--version", "Show version") do
      puts "Version #{VERSION}"
      exit
    end
    opt.on_tail("--feature", "Show development feature") do
      FEATURE.each { |x| puts x }
      exit
    end
  end.parse!(options)

  return args
end