Class: Liquid::Literal

Inherits:
Block show all
Defined in:
lib/liquid/tags/literal.rb

Constant Summary

Constants inherited from Block

Block::ContentOfVariable, Block::FullToken, Block::IsTag, Block::IsVariable

Instance Attribute Summary

Attributes inherited from Tag

#nodelist

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Block

#block_delimiter, #block_name, #create_variable, #end_tag, #render, #unknown_tag

Methods inherited from Tag

#initialize, #name, #render

Constructor Details

This class inherits a constructor from Liquid::Tag

Class Method Details

.from_shorthand(literal) ⇒ Object

Converts a shorthand Liquid literal into its long representation.

Currently the Template parser only knows how to handle the long version. So, it always checks if it is in the presence of a literal, in which case it gets converted through this method.

Example:

Liquid::Literal "{{{ hello world }}}" #=> "{% literal %} hello world {% endliteral %}"


14
15
16
# File 'lib/liquid/tags/literal.rb', line 14

def self.from_shorthand(literal)
  literal =~ LiteralShorthand ? "{% literal %}#{$1}{% endliteral %}" : literal
end

Instance Method Details

#parse(tokens) ⇒ Object

Public instance methods



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/liquid/tags/literal.rb', line 20

def parse(tokens) # :nodoc:
  @nodelist ||= []
  @nodelist.clear

  while token = tokens.shift
    if token =~ FullToken && block_delimiter == $1
      end_tag
      return
    else
      @nodelist << token
    end
  end

  # Make sure that its ok to end parsing in the current block.
  # Effectively this method will throw and exception unless the current block is
  # of type Document
  assert_missing_delimitation!
end