mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
Test parsing of Liquid code in comments
This commit is contained in:
@@ -15,15 +15,19 @@ module Liquid
|
|||||||
attr_reader :variable
|
attr_reader :variable
|
||||||
|
|
||||||
def initialize(tag_name, markup, parse_context)
|
def initialize(tag_name, markup, parse_context)
|
||||||
|
puts "Initializing Echo tag"
|
||||||
super
|
super
|
||||||
@variable = Variable.new(markup, parse_context)
|
@variable = Variable.new(markup, parse_context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
|
puts "Render Echo tag"
|
||||||
@variable.render_to_output_buffer(context, +'')
|
@variable.render_to_output_buffer(context, +'')
|
||||||
end
|
end
|
||||||
|
|
||||||
class ParseTreeVisitor < Liquid::ParseTreeVisitor
|
class ParseTreeVisitor < Liquid::ParseTreeVisitor
|
||||||
|
puts "ParseTreeVisitor Echo tag"
|
||||||
|
|
||||||
def children
|
def children
|
||||||
[@node.variable]
|
[@node.variable]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class CommentTagTest < Minitest::Test
|
||||||
|
include Liquid
|
||||||
|
|
||||||
|
def test_single_line_comments_parse
|
||||||
|
assert_template_result('Before comment', <<~LIQUID)
|
||||||
|
Before comment
|
||||||
|
{%- comment -%}
|
||||||
|
Regular text comment
|
||||||
|
Liquid in comment: {% echo 'Hi from comment' %}
|
||||||
|
{%- endcomment -%}
|
||||||
|
LIQUID
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_multi_line_comments_parse
|
||||||
|
assert_template_result('Before comment', <<~LIQUID)
|
||||||
|
Before comment
|
||||||
|
{%- comment -%} Regular text comment {%- endcomment -%}
|
||||||
|
{%- comment -%} Liquid in comment: {% echo 'Hi from comment' %} {%- endcomment -%}
|
||||||
|
LIQUID
|
||||||
|
end
|
||||||
|
end # CommentTagTest
|
||||||
Reference in New Issue
Block a user