Class: ValidateWebsite::Parser
- Inherits:
-
Object
- Object
- ValidateWebsite::Parser
- Defined in:
- lib/validate_website/option_parser.rb
Overview
Internal class for parse command line args
Constant Summary collapse
- VALID_TYPES =
%i[crawl static].freeze
- DEFAULT_OPTIONS =
{ site: 'http://localhost/', pattern: '**/*.html', exclude: nil, user_agent: nil, markup: true, css_syntax: false, # crawler: log not found url (404 status code) # static: log not found url (not on filesystem, `pwd` considered # as root " / ") not_found: false, file: nil, # regex to ignore certain validation errors ignore: nil, color: true, html5_validator: 'tidy', # internal verbose for ValidateWebsite verbose: false }.freeze
Class Method Summary collapse
- .boolean_options(opt) ⇒ Object
-
.command_line_parse_crawl(_args) ⇒ Hash
Parse command line for validate-website bin.
-
.command_line_parse_static(_args) ⇒ Hash
Parse command line for validate-website-static bin.
- .default_args ⇒ Object
- .ignore_html5_options(opt) ⇒ Object
- .markup_syntax(opt) ⇒ Object
-
.parse(options, type) ⇒ Object
Generic parse method for crawl or static options.
- .verbose_option(opt) ⇒ Object
- .version_help(opt) ⇒ Object
Class Method Details
.boolean_options(opt) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/validate_website/option_parser.rb', line 71 def self.(opt) opt.bool('-n', '--not-found', "Log not found url (default: #{DEFAULT_OPTIONS[:not_found]})", default: DEFAULT_OPTIONS[:not_found]) opt.bool('--color', "Show colored output (default: #{DEFAULT_OPTIONS[:color]})", default: DEFAULT_OPTIONS[:color]) end |
.command_line_parse_crawl(_args) ⇒ Hash
Parse command line for validate-website bin
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/validate_website/option_parser.rb', line 100 def self.command_line_parse_crawl(_args) default_args do |opt| opt.string('-s', '--site', "Website to crawl (default: #{DEFAULT_OPTIONS[:site]})", default: DEFAULT_OPTIONS[:site]) opt.string('-u', '--user-agent', 'Change user agent', default: DEFAULT_OPTIONS[:user_agent]) opt.regexp('-e', '--exclude', 'Url to exclude (ex: "redirect|news")') opt.string('-c', '--cookies', 'Set defaults cookies') end end |
.command_line_parse_static(_args) ⇒ Hash
Parse command line for validate-website-static bin
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/validate_website/option_parser.rb', line 116 def self.command_line_parse_static(_args) default_args do |opt| opt.string('-s', '--site', "Website to crawl (default: #{DEFAULT_OPTIONS[:site]})", default: DEFAULT_OPTIONS[:site]) opt.string('-p', '--pattern', "Filename pattern (default: #{DEFAULT_OPTIONS[:pattern]})", default: DEFAULT_OPTIONS[:pattern]) opt.regexp('-e', '--exclude', 'Url to exclude (ex: "redirect|news")') end end |
.default_args ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/validate_website/option_parser.rb', line 41 def self.default_args Slop.parse do |opt| yield opt if block_given? markup_syntax(opt) (opt) (opt) verbose_option(opt) version_help(opt) end end |
.ignore_html5_options(opt) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/validate_website/option_parser.rb', line 52 def self.(opt) opt.regexp('-i', '--ignore', 'Validation errors to ignore (ex: "valign|autocorrect")') opt.string('-x', '--html5-validator', 'Change default html5 validator engine (ex: tidy or nu)', default: DEFAULT_OPTIONS[:html5_validator]) opt.string('-5', '--html5-validator-service-url', 'Change default html5 validator service URL for "nu" engine') end |
.markup_syntax(opt) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/validate_website/option_parser.rb', line 62 def self.markup_syntax(opt) opt.bool('-m', '--markup', "Markup validation (default: #{DEFAULT_OPTIONS[:markup]})", default: DEFAULT_OPTIONS[:markup]) opt.bool('--css-syntax', "Css validation (default: #{DEFAULT_OPTIONS[:css_syntax]})", default: DEFAULT_OPTIONS[:css_syntax]) end |
.parse(options, type) ⇒ Object
Generic parse method for crawl or static options
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/validate_website/option_parser.rb', line 30 def self.parse(, type) raise ArgumentError unless VALID_TYPES.include?(type) # We are in command line (ARGV) if .is_a?(Array) send("command_line_parse_#{type}", ) else # for testing or Ruby usage with a Hash DEFAULT_OPTIONS.merge() end end |
.verbose_option(opt) ⇒ Object
80 81 82 83 84 |
# File 'lib/validate_website/option_parser.rb', line 80 def self.verbose_option(opt) opt.bool('-v', '--verbose', "Show validator errors (default: #{DEFAULT_OPTIONS[:verbose]})", default: DEFAULT_OPTIONS[:verbose]) end |
.version_help(opt) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/validate_website/option_parser.rb', line 86 def self.version_help(opt) opt.on('--version', 'Display version.') do puts ValidateWebsite::VERSION exit end opt.on('-h', '--help', 'Display this help message.') do puts opt exit end end |