mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Remove literal tag (raw is more performant)
This reverts commit c00a650492.
This commit is contained in:
@@ -45,7 +45,6 @@ module Liquid
|
||||
PartialTemplateParser = /#{TagStart}.*?#{TagEnd}|#{VariableStart}.*?#{VariableIncompleteEnd}/
|
||||
TemplateParser = /(#{PartialTemplateParser}|#{AnyStartingTag})/
|
||||
VariableParser = /\[[^\]]+\]|#{VariableSegment}+\??/
|
||||
LiteralShorthand = /^(?:\{\{\{\s?)(.*?)(?:\s*\}\}\})$/
|
||||
end
|
||||
|
||||
require 'liquid/drop'
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
module Liquid
|
||||
|
||||
class Literal < Block
|
||||
|
||||
# Class methods
|
||||
|
||||
# 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 %}"
|
||||
def self.from_shorthand(literal)
|
||||
literal =~ LiteralShorthand ? "{% literal %}#{$1}{% endliteral %}" : literal
|
||||
end
|
||||
|
||||
# Public instance methods
|
||||
|
||||
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 # parse
|
||||
|
||||
end
|
||||
|
||||
Template.register_tag('literal', Literal)
|
||||
end
|
||||
@@ -55,7 +55,7 @@ module Liquid
|
||||
# Parse source code.
|
||||
# Returns self for easy chaining
|
||||
def parse(source)
|
||||
@root = Document.new(tokenize(Liquid::Literal.from_shorthand(source)))
|
||||
@root = Document.new(tokenize(source))
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
@@ -41,9 +41,4 @@ class RegexpTest < Test::Unit::TestCase
|
||||
assert_equal ['var', '["method"]', '[0]'], 'var["method"][0]'.scan(VariableParser)
|
||||
assert_equal ['var', '[method]', '[0]', 'method'], 'var[method][0].method'.scan(VariableParser)
|
||||
end
|
||||
|
||||
def test_literal_shorthand_regexp
|
||||
assert_equal [["{% if 'gnomeslab' contains 'liquid' %}yes{% endif %}"]],
|
||||
"{{{ {% if 'gnomeslab' contains 'liquid' %}yes{% endif %} }}}".scan(LiteralShorthand)
|
||||
end
|
||||
end # RegexpTest
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
class LiteralTagTest < Test::Unit::TestCase
|
||||
include Liquid
|
||||
|
||||
def test_empty_literal
|
||||
assert_template_result '', '{% literal %}{% endliteral %}'
|
||||
assert_template_result '', '{{{}}}'
|
||||
end
|
||||
|
||||
def test_simple_literal_value
|
||||
assert_template_result 'howdy',
|
||||
'{% literal %}howdy{% endliteral %}'
|
||||
end
|
||||
|
||||
def test_literals_ignore_liquid_markup
|
||||
expected = %({% if 'gnomeslab' contain 'liquid' %}yes{ % endif %})
|
||||
template = %({% literal %}#{expected}{% endliteral %})
|
||||
|
||||
assert_template_result expected, template
|
||||
end
|
||||
|
||||
def test_shorthand_syntax
|
||||
expected = %({% if 'gnomeslab' contain 'liquid' %}yes{ % endif %})
|
||||
template = %({{{#{expected}}}})
|
||||
|
||||
assert_template_result expected, template
|
||||
end
|
||||
|
||||
# Class methods
|
||||
def test_from_shorthand
|
||||
assert_equal '{% literal %}gnomeslab{% endliteral %}', Liquid::Literal.from_shorthand('{{{gnomeslab}}}')
|
||||
end
|
||||
|
||||
def test_from_shorthand_ignores_improper_syntax
|
||||
text = "{% if 'hi' == 'hi' %}hi{% endif %}"
|
||||
assert_equal text, Liquid::Literal.from_shorthand(text)
|
||||
end
|
||||
end # AssignTest
|
||||
Reference in New Issue
Block a user