Class: ForkedSlim::Parser Private

Inherits:
Object
  • Object
show all
Includes:
Temple::Mixins::Options
Defined in:
lib/hamlet/forked_slim_parser.rb

Overview

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.

Parses Slim code and transforms it to a Temple expression

Direct Known Subclasses

Hamlet::Parser

Defined Under Namespace

Classes: SyntaxError

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ 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.



33
34
35
36
# File 'lib/hamlet/forked_slim_parser.rb', line 33

def initialize(options = {})
  super
  @tab = ' ' * @options[:tabsize]
end

Instance Method Details

#call(str) ⇒ Array

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.

Compile string to Temple expression



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hamlet/forked_slim_parser.rb', line 42

def call(str)
  # Set string encoding if option is set
  if options[:encoding] && str.respond_to?(:encoding)
    old = str.encoding
    str = str.dup if str.frozen?
    str.force_encoding(options[:encoding])
    # Fall back to old encoding if new encoding is invalid
    str.force_encoding(old_enc) unless str.valid_encoding?
  end

  result = [:multi]
  reset(str.split($/), [result])

  parse_line while next_line

  reset
  result
end