-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow #
to be used as an inline comment tag
#1401
Changes from 5 commits
31f7be8
fff6c56
6ddfaec
5e8e5e8
ab45548
0fc45ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class InlineCommentTest < Minitest::Test | ||
include Liquid | ||
|
||
def test_tag_in_different_styles | ||
assert_template_result('', '{% # This text gets ignored %}') | ||
assert_template_result('', '{%# This text gets ignored #%}') | ||
assert_template_result('', '{%# This text gets ignored %}') | ||
assert_template_result('', '{%#- This text gets ignored -#%}') | ||
end | ||
|
||
def test_test_syntax_error | ||
assert_template_result('fail', '{% #This doesnt work %}') | ||
|
||
assert false | ||
rescue | ||
# ok good | ||
end | ||
Comment on lines
+15
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, this test is saying that a space is required after |
||
|
||
def test_tag_ws_stripping | ||
assert_template_result('', ' {%#- This text gets ignored -#%} ') | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the reason you are proposing supporting this style. Does it have any semantic difference? Other than this test case, it seems like {%#- This is clearly a comment
echo "but how about this line?" -#%} I'm also unsure if you are proposing that the |
||
end | ||
|
||
def test_comment_inline_tag | ||
assert_template_result('ok', '{% echo "ok" # output something from a tag %}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth noting that this removes a lot of the benefit of treating This also has implications for the API, since we'd have to either
The second of these may still be the right call, but special-casing those tags could be more complex in Liquid-C. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly is the benefit of treating it as a tag? My (limited!) experience with parser creation suggests that comments are usually dropped very early in the process of parsing/lexing and this feels like the right approach for liquid as well. |
||
|
||
assert_template_result('ok', '{% # this sort of comment also | ||
echo "ok" %}') | ||
end | ||
|
||
def test_comment_inline_variable | ||
assert_template_result('ok', '{{ "ok" # output something from a variable }}') | ||
assert_template_result('ok', '{{ "OK" | downcase # output something from a variable }}') | ||
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 | ||
|
||
def test_multiline | ||
assert_template_result('', '{% # this sort of comment also | ||
# will just work, because it parses | ||
# as a single call to the "#" tag %}') | ||
|
||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's is the plan here? Will you merge it remove current change so it point to master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The liquid-c change can be safely merged first, then I'll update this to point back to master before merging.