Class: Slimi::Parser

Inherits:
Temple::Parser
  • Object
show all
Defined in:
lib/slimi/parser.rb

Defined Under Namespace

Classes: Factory

Instance Method Summary collapse

Constructor Details

#initialize(_options = {}) ⇒ Parser

Returns a new instance of Parser.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/slimi/parser.rb', line 26

def initialize(_options = {})
  super
  @file_path = options[:file] || '(__TEMPLATE__)'
  factory = Factory.new(
    attribute_delimiters: options[:attr_list_delims] || {},
    default_tag: options[:default_tag] || 'div',
    ruby_attribute_delimiters: options[:code_attr_delims] || {},
    shortcut: options[:shortcut] || {}
  )
  @attribute_delimiters = factory.attribute_delimiters
  @attribute_shortcuts = factory.attribute_shortcuts
  @tag_shortcuts = factory.tag_shortcuts
  @attribute_shortcut_regexp = factory.attribute_shortcut_regexp
  @attribute_delimiter_regexp = factory.attribute_delimiter_regexp
  @quoted_attribute_regexp = factory.quoted_attribute_regexp
  @tag_name_regexp = factory.tag_name_regexp
  @attribute_name_regexp = factory.attribute_name_regexp
  @ruby_attribute_regexp = factory.ruby_attribute_regexp
  @ruby_attribute_delimiter_regexp = factory.ruby_attribute_delimiter_regexp
  @ruby_attribute_delimiters = factory.ruby_attribute_delimiters
  @embedded_template_regexp = factory.embedded_template_regexp
end

Instance Method Details

#call(source) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/slimi/parser.rb', line 49

def call(source)
  @stacks = [[:multi]]
  @indents = []
  @scanner = ::StringScanner.new(source)
  parse_block until @scanner.eos?
  @stacks[0]
end