Class: Twig::TokenParser::AutoEscape

Inherits:
Base
  • Object
show all
Defined in:
lib/twig/token_parser/auto_escape.rb

Instance Attribute Summary

Attributes inherited from Base

#parser

Instance Method Summary collapse

Instance Method Details

#parse(token) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/twig/token_parser/auto_escape.rb', line 6

def parse(token)
  lineno = token.lineno
  stream = parser.stream

  if stream.test(Token::BLOCK_END_TYPE)
    value = :html
  else
    expr = parser.parse_expression

    unless expr.is_a?(Node::Expression::Constant)
      raise Error::Syntax.new(
        'An escaping strategy must be a string or false.',
        stream.current.lineno,
        stream.source
      )
    end

    value = expr.attributes[:value]
    value = value.to_sym if value.is_a?(String)
  end

  stream.expect(Token::BLOCK_END_TYPE)
  body = parser.subparse(method(:decide_block_end), drop_needle: true)
  stream.expect(Token::BLOCK_END_TYPE)

  Node::AutoEscape.new(value, body, lineno)
end

#tagObject



34
35
36
# File 'lib/twig/token_parser/auto_escape.rb', line 34

def tag
  'autoescape'
end