Class: Hamlet::Parser Private
- Inherits:
-
ForkedSlim::Parser
- Object
- ForkedSlim::Parser
- Hamlet::Parser
- Defined in:
- lib/hamlet/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.
Constant Summary collapse
- CLASS_ID_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A\s*(#|\.)(\w[\w:-]*)/
Instance Method Summary collapse
-
#call(str) ⇒ Array
private
Compile string to Temple expression.
Methods inherited from ForkedSlim::Parser
Constructor Details
This class inherits a constructor from ForkedSlim::Parser
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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hamlet/parser.rb', line 16 def call(str) # Set string encoding if option is set if [:encoding] && str.respond_to?(:encoding) old = str.encoding str = str.dup if str.frozen? str.force_encoding([: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]) while @lines.first && @lines.first =~ /\A\s*\Z/ @stacks.last << [:newline] next_line end if @lines.first and @lines.first =~ /\A<doctype\s+([^>]*)>?/i if !$'.empty? and $'[0] !~ /\s*#/ fail("did not expect content after doctype") end @stacks.last << [:html, :doctype, $1] next_line end parse_line while next_line reset result end |