Class: Riven::OptParser
- Inherits:
-
Object
- Object
- Riven::OptParser
- Defined in:
- lib/riven/opt_parser.rb
Overview
Utility class to parse the options and files passed to the riven command
Instance Method Summary collapse
-
#files(options) ⇒ Object
Returns an array of Riven::MarkupFile for each given markdown file.
-
#options ⇒ Object
Parses the options and returns a map with the options and their values.
Instance Method Details
#files(options) ⇒ Object
Returns an array of Riven::MarkupFile for each given markdown file
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/riven/opt_parser.rb', line 16 public def files() file_names = ARGV if file_names.size === 1 && File.directory?(file_names[0]) [:dir_given] = file_names.first file_names = Dir["#{file_names[0]}/*.md"].sort end file_names.map { |file| Riven::MarkupFile.new(file) } end |
#options ⇒ Object
Parses the options and returns a map with the options and their values.
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 |
# File 'lib/riven/opt_parser.rb', line 32 public def = { output_file: '', cover_file: '', css_file: '', toc: false, toc_headline: 'Contents', dump_html: false, dump_cover_html: false, verbose: false, dir_given: false } opt_parser = OptionParser.new do |opts| opts. = 'Usage: riven [OPTIONS] Markdown Files' opts.separator '' opts.separator 'Options' opts.on("-o FILE", "--output=FILE", "File name of the output PDF file") do |output_file| [:output_file] = output_file end opts.on("-s FILE", "--css=FILE", "Path to the custom CSS file") do |css_file| [:css_file] = File.(css_file) end opts.on("-c FILE", "--cover=FILE", "Path to the cover MD file") do |cover_file| [:cover_file] = Riven::MarkupFile.new(cover_file) end opts.on("-t HEADLINE", "--toc=HEADLINE", "Enabled the table of contents auto generation") do |headline| [:toc] = true [:toc_headline] = headline end opts.on("-d", "--dump-html", "Dumps the main HTML file to STDOUT") do [:dump_html] = true end opts.on("-D", "--dump-cover-html", "Dumps the cover HTML file to STDOUT") do [:dump_cover_html] = true end opts.on('-v', '--verbose', 'Print the output of wkhtmltopdf to STDOUT. Don\'t combine with -d') do [:verbose] = true end opts.on('-V', '--version', 'Displays the version') do require 'riven/version' puts Riven::VERSION.to_s exit end end opt_parser.parse! return end |