Class: Markover::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/markover/optionparser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse!(args) ⇒ Object



6
7
8
# File 'lib/markover/optionparser.rb', line 6

def self.parse!(args)
  new.parse!(args)
end

Instance Method Details

#parse!(args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/markover/optionparser.rb', line 10

def parse!(args)
  return {} if args.empty?
  options = {
    outputdir: nil,
    stylesheet: nil,
    recursive: false,
    merge: false,
    filename: nil,
    debug: false,
    wkhtmltopdfparameters: '',
    removefrontmatter: false,
    table_of_contents: false
  }
  parser(options).parse!(args)
  options
end

#parser(options) ⇒ Object



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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/markover/optionparser.rb', line 27

def parser(options)
  OptionParser.new do |parser|
    parser.banner = 'Usage: markover [options] [files or directories]'
    parser.separator ''
    parser.separator 'Options'

    parser.on('-o', '--output-dir', '=OUTDIR',
     'Save parsed files to OUTDIR.  Defaults to working directory.') do |value|

      options[:outputdir] = value
    end

    parser.on('-s', '--stylesheet', '=SHEET',
      'Override standard stylesheet with SHEET') do |value|

      options[:stylesheet] = value
    end

    parser.on('-r', '--recursive',
      'Recurse current or target directory and convert all valid markup files') do

      options[:recursive] = true
    end

    parser.on('-m', '--merge', '=FILENAME',
      'Merge any and all passed markup files into single file of the specified name') do |value|

      options[:merge] = true
      options[:filename] = value
    end

    parser.on('-d', '--debug', 'Dumps HTML output to stdout') do |value|
      options[:debug] = true
    end

    parser.on('-w', '--wkhtmltopdf-params', '=PARAMS',
      'Parameters to be passed on to wkhtmltopdf. Use "" if more than one parameter. See wkhtmltopdf usage for possible parameters.') do |value|
      options[:wkhtmltopdfparameters] = value
    end

    parser.on('-o', '--remove-front-matter', 'Remove yaml frontmatter from your files.') do
      options[:removefrontmatter] = true
    end

    parser.on('-n', '--output-filename', '=FILENAME',
      'Sets the name of the output file. Only used with single file and in merge mode.') do |value|

      options[:filename] = value
    end

    parser.on('-t', '--toc', 'Generate a table of contents') do
      options[:table_of_contents] = true
    end

    parser.on('-v', '--version', 'Show version information and quit') do
      puts Markover::Version
      exit
    end

    parser.on('-?', '-h', '--help', 'Show this message') do
      puts parser
      exit
    end
  end
end