-
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
Add #
inline comment tag.
#1498
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1f0a0ad
Add `#` inline comment tag.
charlespwd 21f3337
Test a blank line in a comment tag
dylanahsmith 23a8438
Use liquid-c master branch again, it now has inline comment support
dylanahsmith 54414df
Add changelog entry, making the next release a feature release
dylanahsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Liquid | ||
class InlineComment < Tag | ||
def initialize(tag_name, markup, options) | ||
super | ||
|
||
# Semantically, a comment should only ignore everything after it on the line. | ||
# Currently, this implementation doesn't support mixing a comment with another tag | ||
# but we need to reserve future support for this and prevent the introduction | ||
# of inline comments from being backward incompatible change. | ||
# | ||
# As such, we're forcing users to put a # symbol on every line otherwise this | ||
# tag will throw an error. | ||
if markup.match?(/\n\s*[^#\s]/) | ||
raise SyntaxError, options[:locale].t("errors.syntax.inline_comment_invalid") | ||
end | ||
end | ||
|
||
def render_to_output_buffer(_context, output) | ||
charlespwd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
output | ||
end | ||
|
||
def blank? | ||
true | ||
end | ||
end | ||
|
||
Template.register_tag('#', InlineComment) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
# frozen_string_literal: true | ||
|
||
module Liquid | ||
VERSION = "5.3.0" | ||
VERSION = "5.4.0.alpha" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class InlineCommentTest < Minitest::Test | ||
charlespwd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
include Liquid | ||
|
||
def test_inline_comment_returns_nothing | ||
assert_template_result('', '{%- # this is an inline comment -%}') | ||
assert_template_result('', '{%-# this is an inline comment -%}') | ||
assert_template_result('', '{% # this is an inline comment %}') | ||
assert_template_result('', '{%# this is an inline comment %}') | ||
end | ||
|
||
def test_inline_comment_does_not_require_a_space_after_the_pound_sign | ||
assert_template_result('', '{%#this is an inline comment%}') | ||
end | ||
|
||
def test_liquid_inline_comment_returns_nothing | ||
assert_template_result('Hey there, how are you doing today?', <<~LIQUID) | ||
{%- liquid | ||
# This is how you'd write a block comment in a liquid tag. | ||
# It looks a lot like what you'd have in ruby. | ||
|
||
# You can use it as inline documentation in your | ||
# liquid blocks to explain why you're doing something. | ||
echo "Hey there, " | ||
|
||
# It won't affect the output. | ||
echo "how are you doing today?" | ||
-%} | ||
LIQUID | ||
end | ||
|
||
def test_inline_comment_can_be_written_on_multiple_lines | ||
assert_template_result('', <<~LIQUID) | ||
{%- | ||
# That kind of block comment is also allowed. | ||
# It would only be a stylistic difference. | ||
|
||
# Much like JavaScript's /* */ comments and their | ||
dylanahsmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# leading * on new lines. | ||
-%} | ||
LIQUID | ||
end | ||
|
||
def test_inline_comment_multiple_pound_signs | ||
assert_template_result('', <<~LIQUID) | ||
{%- liquid | ||
###################################### | ||
# We support comments like this too. # | ||
###################################### | ||
-%} | ||
LIQUID | ||
end | ||
|
||
def test_inline_comments_require_the_pound_sign_on_every_new_line | ||
assert_match_syntax_error("Each line of comments must be prefixed by the '#' character", <<~LIQUID) | ||
{%- | ||
# some comment | ||
echo 'hello world' | ||
-%} | ||
LIQUID | ||
end | ||
|
||
def test_inline_comment_does_not_support_nested_tags | ||
assert_template_result(' -%}', "{%- # {% echo 'hello world' %} -%}") | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For future reference, it is better to do this reordering/refactoring in a separate commit from the commit to add a feature.