class Slimi::Parser::Factory
Convert human-friendly options into machine-friendly objects.
Constants
- EMBEDDED_TEMPLATE_ENGINE_NAMES
Attributes
attribute_delimiters[R]
@return [Hash]
ruby_attribute_delimiters[R]
@return [Hash]
Public Class Methods
new(attribute_delimiters:, default_tag:, ruby_attribute_delimiters:, shortcut:)
click to toggle source
@param [Hash] attribute_delimiters
@param [String] default_tag @param [Hash] ruby_attribute_delimiters
@param [Hash] shortcut
# File lib/slimi/parser.rb, line 604 def initialize(attribute_delimiters:, default_tag:, ruby_attribute_delimiters:, shortcut:) @attribute_delimiters = attribute_delimiters @default_tag = default_tag @ruby_attribute_delimiters = ruby_attribute_delimiters @shortcut = shortcut end
Public Instance Methods
additional_attributes()
click to toggle source
@return [Hash] e.g. ‘{ “.” => { “a” => “b” }}`
^^^ ^^^ ^^^ | | `- attribute value | `- attribute key `- marker
# File lib/slimi/parser.rb, line 616 def additional_attributes @additional_attributes ||= @shortcut.each_with_object({}) do |(marker, details), result| result[marker] = details[:additional_attrs] if details.key?(:additional_attrs) end end
attribute_delimiter_regexp()
click to toggle source
@return [Regexp] Pattern that matches to attribute delimiter.
# File lib/slimi/parser.rb, line 643 def attribute_delimiter_regexp delimiters_regexp = ::Regexp.union(@attribute_delimiters.keys) /[ \t]*(#{delimiters_regexp})/ end
attribute_name_regexp()
click to toggle source
@return [Regexp]
# File lib/slimi/parser.rb, line 649 def attribute_name_regexp @attribute_name_regexp ||= begin characters = ::Regexp.escape(@attribute_delimiters.flatten.uniq.join) %r{[ \t]*([^\0 \t\r\n"'<>/=#{characters}]+)} end end
attribute_shortcut_regexp()
click to toggle source
@return [Regexp] Pattern that matches to attribute shortcuts part.
# File lib/slimi/parser.rb, line 657 def attribute_shortcut_regexp markers = attribute_shortcuts.keys.sort_by { |marker| -marker.size } markers_regexp = ::Regexp.union(markers) %r{(#{markers_regexp}+)((?:\p{Word}|-|/\d+|:(\w|-)+)*)} end
attribute_shortcuts()
click to toggle source
@return [Hash] e.g. ‘{ “.” => [“class”] }`
^^^ ^^^^^^^ | `- attribute name `- marker
# File lib/slimi/parser.rb, line 626 def attribute_shortcuts @attribute_shortcuts ||= @shortcut.each_with_object({}) do |(marker, details), result| result[marker] = Array(details[:attr]) if details.key?(:attr) end end
embedded_template_regexp()
click to toggle source
@return [Regexp]
# File lib/slimi/parser.rb, line 669 def embedded_template_regexp /(#{::Regexp.union(EMBEDDED_TEMPLATE_ENGINE_NAMES)})(?:[ \t]*(?:(.*)))?:([ \t]*)/ end
quoted_attribute_regexp()
click to toggle source
@return [Regexp]
# File lib/slimi/parser.rb, line 674 def quoted_attribute_regexp /#{attribute_name_regexp}[ \t]*=(=?)[ \t]*("|')/ end
ruby_attribute_delimiter_regexp()
click to toggle source
@return [Regexp]
# File lib/slimi/parser.rb, line 679 def ruby_attribute_delimiter_regexp ::Regexp.union(@ruby_attribute_delimiters.keys) end
ruby_attribute_regexp()
click to toggle source
@return [Regexp]
# File lib/slimi/parser.rb, line 664 def ruby_attribute_regexp /#{attribute_name_regexp}[ \t]*=(=?)[ \t]*/ end
tag_name_regexp()
click to toggle source
@return [Regexp] Pattern that matches to tag header part.
# File lib/slimi/parser.rb, line 684 def tag_name_regexp markers = tag_shortcuts.keys.sort_by { |marker| -marker.size } markers_regexp = ::Regexp.union(markers) /#{markers_regexp}|\*(?=[^ \t]+)|(\p{Word}(?:\p{Word}|:|-)*\p{Word}|\p{Word}+)/ end
tag_shortcuts()
click to toggle source
@return [Hash] e.g. ‘{ “.” => “div” }`
^^^ ^^^^^ | `- tag name `- marker
# File lib/slimi/parser.rb, line 636 def tag_shortcuts @tag_shortcuts ||= @shortcut.transform_values do |details| details[:tag] || @default_tag end end