Class: Slamdown::Conversion::ConfigurationValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/slamdown/conversion/configuration_validator.rb

Overview

Performs small, section-local checks and normalisation before conversion code receives any options.

Constant Summary collapse

TOP_LEVEL_KEYS =
[:inline, :headings, :entities, :html_indent, :urls, :tables, :elements, :classes, :ids].freeze
HEADING_KEYS =
[:start, :compact].freeze
URL_KEYS =
[:scheme, :host, :path, :force].freeze
TABLE_KEYS =
[:format, :max_width].freeze
ELEMENT_RULE_KEYS =
[:action, :attributes].freeze
ELEMENT_ACTIONS =
[:convert, :preserve, :unwrap, :inline, :drop].freeze
ATTRIBUTE_ACTIONS =
[:preserve, :drop].freeze
ENTITY_MODES =
[:symbolic, :character, :numeric].freeze
URL_FORCES =
[:relative, :absolute].freeze
TABLE_FORMATS =
[:auto, :html].freeze
HTML_NAME =
/\A[a-z][a-z0-9._:-]*\z/.freeze
ATTRIBUTE_NAME =
/\A[a-z_:][a-z0-9._:-]*\z/.freeze
HTML_WHITESPACE =
/[\t\n\f\r ]/.freeze
DEFAULTS =
Immutable.copy(
	:inline => false,
	:headings => {:start => 2, :compact => true},
	:entities => :character,
	:html_indent => "\t",
	:urls => {:scheme => nil, :host => nil, :path => nil, :force => :relative},
	:tables => {:format => :auto, :max_width => 150},
	:elements => {},
	:classes => {},
	:ids => {}
)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ConfigurationValidator

Returns a new instance of ConfigurationValidator.



34
35
36
# File 'lib/slamdown/conversion/configuration_validator.rb', line 34

def initialize(options)
	@options = options
end

Instance Method Details

#validateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/slamdown/conversion/configuration_validator.rb', line 38

def validate
	expect_hash(@options, "options")
	@options = normalise_option_keys(@options, TOP_LEVEL_KEYS, "options")

	Configuration.new(
		:inline => boolean_option(:inline),
		:headings => validate_headings,
		:entities => closed_option(:entities, ENTITY_MODES),
		:html_indent => validate_html_indent,
		:urls => validate_urls,
		:tables => validate_tables,
		:elements => validate_elements,
		:classes => validate_name_rules(:classes),
		:ids => validate_name_rules(:ids)
	)
end