Class: Sal::Parser

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

Instance Method Summary collapse

Instance Method Details

#call(str) ⇒ Array

Compile the string to a Temple expression

Parameters:

  • str (String)

    Html code

Returns:

  • (Array)

    Temple expression representing the code



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sal/parser.rb', line 13

def call(str)
  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]
  parse_nodeset([result], Nokogiri::XML(str))
  result
end