mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Implement the inline comment tag
This commit is contained in:
@@ -4,8 +4,8 @@ require 'English'
|
||||
|
||||
module Liquid
|
||||
class BlockBody
|
||||
LiquidTagToken = /\A\s*(\w+)\s*(.*?)\z/o
|
||||
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(\w+)(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om
|
||||
LiquidTagToken = /\A\s*(\w+|#)\s*(.*?)\z/o
|
||||
FullToken = /\A#{TagStart}#{WhitespaceControl}?(\s*)(\w+|#)(\s*)(.*?)#{WhitespaceControl}?#{TagEnd}\z/om
|
||||
ContentOfVariable = /\A#{VariableStart}#{WhitespaceControl}?(.*?)#{WhitespaceControl}?#{VariableEnd}\z/om
|
||||
WhitespaceOrNothing = /\A\s*\z/
|
||||
TAGSTART = "{%"
|
||||
|
||||
15
lib/liquid/tags/inline_comment.rb
Normal file
15
lib/liquid/tags/inline_comment.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Liquid
|
||||
class InlineComment < Tag
|
||||
def render_to_output_buffer(_context, output)
|
||||
output
|
||||
end
|
||||
|
||||
def blank?
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
Template.register_tag('#', InlineComment)
|
||||
end
|
||||
22
test/integration/tags/inline_comment_test.rb
Normal file
22
test/integration/tags/inline_comment_test.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class InlineCommentTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_tag
|
||||
assert_template_result('', '{% # This text gets ignored %}')
|
||||
end
|
||||
|
||||
def test_inside_liquid_tag
|
||||
source = <<~LIQUID
|
||||
{%- liquid
|
||||
echo "before("
|
||||
# This text gets ignored
|
||||
echo ")after"
|
||||
-%}
|
||||
LIQUID
|
||||
assert_template_result('before()after', source)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user