Class: Parser::ScriptOptions
- Inherits:
-
Object
- Object
- Parser::ScriptOptions
- Defined in:
- lib/parser.rb
Instance Attribute Summary collapse
-
#chrome_path ⇒ Object
Returns the value of attribute chrome_path.
-
#css_path ⇒ Object
Returns the value of attribute css_path.
-
#generate_css ⇒ Object
Returns the value of attribute generate_css.
-
#generate_md ⇒ Object
Returns the value of attribute generate_md.
-
#html ⇒ Object
Returns the value of attribute html.
-
#html_path ⇒ Object
Returns the value of attribute html_path.
-
#input ⇒ Object
Returns the value of attribute input.
-
#open_browser ⇒ Object
Returns the value of attribute open_browser.
-
#pdf ⇒ Object
Returns the value of attribute pdf.
-
#pdf_path ⇒ Object
Returns the value of attribute pdf_path.
-
#port ⇒ Object
Returns the value of attribute port.
-
#serve_only ⇒ Object
Returns the value of attribute serve_only.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #boolean_generate_css_option(parser) ⇒ Object
- #boolean_generate_md_option(parser) ⇒ Object
- #boolean_html_option(parser) ⇒ Object
- #boolean_open_browser_option(parser) ⇒ Object
- #boolean_pdf_option(parser) ⇒ Object
- #boolean_serve_only_option(parser) ⇒ Object
- #boolean_verbosity_option(parser) ⇒ Object
- #define_options(parser) ⇒ Object
-
#initialize ⇒ ScriptOptions
constructor
A new instance of ScriptOptions.
- #specify_chrome_path_option(parser) ⇒ Object
- #specify_input_css_option(parser) ⇒ Object
- #specify_output_html_option(parser) ⇒ Object
- #specify_output_pdf_option(parser) ⇒ Object
- #specify_server_port_option(parser) ⇒ Object
Constructor Details
#initialize ⇒ ScriptOptions
Returns a new instance of ScriptOptions.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/parser.rb', line 9 def initialize self.chrome_path = nil self.html = true self.pdf = true self.open_browser = true self.css_path = default_css_path self.pdf_path = Pathname.new('resume.pdf'). self.html_path = Pathname.new('resume.html'). self.verbose = false self.serve_only = false self.input = nil self.port = 3000 self.generate_md = true self.generate_css = false end |
Instance Attribute Details
#chrome_path ⇒ Object
Returns the value of attribute chrome_path.
6 7 8 |
# File 'lib/parser.rb', line 6 def chrome_path @chrome_path end |
#css_path ⇒ Object
Returns the value of attribute css_path.
6 7 8 |
# File 'lib/parser.rb', line 6 def css_path @css_path end |
#generate_css ⇒ Object
Returns the value of attribute generate_css.
6 7 8 |
# File 'lib/parser.rb', line 6 def generate_css @generate_css end |
#generate_md ⇒ Object
Returns the value of attribute generate_md.
6 7 8 |
# File 'lib/parser.rb', line 6 def generate_md @generate_md end |
#html ⇒ Object
Returns the value of attribute html.
6 7 8 |
# File 'lib/parser.rb', line 6 def html @html end |
#html_path ⇒ Object
Returns the value of attribute html_path.
6 7 8 |
# File 'lib/parser.rb', line 6 def html_path @html_path end |
#input ⇒ Object
Returns the value of attribute input.
6 7 8 |
# File 'lib/parser.rb', line 6 def input @input end |
#open_browser ⇒ Object
Returns the value of attribute open_browser.
6 7 8 |
# File 'lib/parser.rb', line 6 def open_browser @open_browser end |
#pdf ⇒ Object
Returns the value of attribute pdf.
6 7 8 |
# File 'lib/parser.rb', line 6 def pdf @pdf end |
#pdf_path ⇒ Object
Returns the value of attribute pdf_path.
6 7 8 |
# File 'lib/parser.rb', line 6 def pdf_path @pdf_path end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/parser.rb', line 6 def port @port end |
#serve_only ⇒ Object
Returns the value of attribute serve_only.
6 7 8 |
# File 'lib/parser.rb', line 6 def serve_only @serve_only end |
#verbose ⇒ Object
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/parser.rb', line 6 def verbose @verbose end |
Instance Method Details
#boolean_generate_css_option(parser) ⇒ Object
138 139 140 141 142 |
# File 'lib/parser.rb', line 138 def boolean_generate_css_option(parser) parser.on('--[no-]generate-css', 'Generate CSS template.') do |v| self.generate_css = v end end |
#boolean_generate_md_option(parser) ⇒ Object
132 133 134 135 136 |
# File 'lib/parser.rb', line 132 def boolean_generate_md_option(parser) parser.on('--[no-]generate-md', 'Generate markdown template.') do |v| self.generate_md = v end end |
#boolean_html_option(parser) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/parser.rb', line 111 def boolean_html_option(parser) # Boolean switch. parser.on('--[no-]html', 'Do [not] write html output') do |v| self.html = v end end |
#boolean_open_browser_option(parser) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/parser.rb', line 125 def boolean_open_browser_option(parser) # Boolean switch. parser.on('--no-open', 'Do not automatically open browser when starting server') do |v| self.open_browser = v end end |
#boolean_pdf_option(parser) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/parser.rb', line 104 def boolean_pdf_option(parser) # Boolean switch. parser.on('--no-pdf', 'Do [not] write pdf output') do |v| self.pdf = v end end |
#boolean_serve_only_option(parser) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/parser.rb', line 118 def boolean_serve_only_option(parser) # Boolean switch. parser.on('--serve-only') do |v| self.serve_only = v end end |
#boolean_verbosity_option(parser) ⇒ Object
98 99 100 101 102 |
# File 'lib/parser.rb', line 98 def boolean_verbosity_option(parser) parser.on('-v', '--[no-]verbose', 'Run verbosely') do |v| self.verbose = v end end |
#define_options(parser) ⇒ Object
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 |
# File 'lib/parser.rb', line 25 def (parser) parser. = 'Usage: md_resume command filename [options...]' parser.separator '' parser.separator 'Commands:' parser.separator "serve\t\t\tStart a local server to preview your resume" parser.separator "build\t\t\tBuild your resume in html and pdf formats." parser.separator "generate\t\tGenerate a template with given file name," parser.separator "\t\t\tdefaults to generating only a markdown template." parser.separator '' parser.separator 'Specific options:' # add additional options specify_chrome_path_option(parser) boolean_pdf_option(parser) boolean_html_option(parser) specify_output_pdf_option(parser) specify_output_html_option(parser) specify_input_css_option(parser) specify_server_port_option(parser) # TODO: remove this? boolean_serve_only_option(parser) boolean_open_browser_option(parser) boolean_verbosity_option(parser) boolean_generate_md_option(parser) boolean_generate_css_option(parser) parser.separator '' parser.separator 'Common options:' # No argument, shows at tail. This will print an options summary. # Try it and see! parser.on_tail('-h', '--help', 'Show this message') do puts parser exit end end |
#specify_chrome_path_option(parser) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/parser.rb', line 60 def specify_chrome_path_option(parser) # Specifies an optional option argument parser.on('--chrome-path=PATH', 'Path to Chrome executable') do |path| full_path = Pathname.new(path). self.chrome_path = full_path end end |
#specify_input_css_option(parser) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/parser.rb', line 82 def specify_input_css_option(parser) parser.on('--css-path=PATH', 'Path of css inputs.') do |path| input_dir = Pathname.new(path). self.css_path = input_dir end end |
#specify_output_html_option(parser) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/parser.rb', line 68 def specify_output_html_option(parser) parser.on('-h PATH', '--html-path=PATH', 'Path of html output') do |path| input_dir = Pathname.new(path). self.html_path = input_dir end end |
#specify_output_pdf_option(parser) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/parser.rb', line 75 def specify_output_pdf_option(parser) parser.on('-p PATH', '--pdf-path=PATH', 'Path of pdf output') do |path| input_dir = Pathname.new(path). self.pdf_path = input_dir end end |
#specify_server_port_option(parser) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/parser.rb', line 89 def specify_server_port_option(parser) parser.on('--server-port=PORT', 'Specify the localhost port number for the server') do |port| port = port.to_i raise OptionParser::InvalidArgument unless (1..65_535).cover?(port) self.port = port end end |