Class: Slim::Smart::Parser Private

Inherits:
Parser
  • Object
show all
Defined in:
lib/slim/smart/parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Parser

#call

Constructor Details

#initialize(opts = {}) ⇒ Parser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Parser.



8
9
10
11
12
13
14
15
# File 'lib/slim/smart/parser.rb', line 8

def initialize(opts = {})
  super
  word_re = options[:implicit_text] ? '[_a-z0-9]' : '\p{Word}'
  attr_keys = Regexp.union(@attr_shortcut.keys.sort_by { |k| -k.size })
  @attr_shortcut_re = /\A(#{attr_keys}+)((?:\p{Word}|-)*)/
  tag_keys = Regexp.union((@tag_shortcut.keys - @attr_shortcut.keys).sort_by { |k| -k.size })
  @tag_re = /\A(?:#{attr_keys}(?=-*\p{Word})|#{tag_keys}|\*(?=[^\s]+)|(#{word_re}(?:#{word_re}|:|-)*#{word_re}|#{word_re}+))/
end

Instance Method Details

#unknown_line_indicatorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/slim/smart/parser.rb', line 17

def unknown_line_indicator
  if @line =~ /\A>( ?)/
    # Found explicit text block.
    @stacks.last << [:slim, :text, :explicit, parse_text_block($', @indents.last + $1.size + 1)]
  else
    unless options[:implicit_text]
      syntax_error! 'Illegal shortcut' if @line =~ @attr_shortcut_re
      super
    end
    # Found implicit smart text block.
    if line = @lines.first
      indent = (line =~ /\A\s*\Z/ ? @indents.last + 1 : get_indent(line))
    end
    @stacks.last << [:slim, :text, :implicit, parse_text_block(@line, indent)]
  end
end