Skip to content
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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ group :test do
gem 'rubocop-performance', require: false

platform :mri, :truffleruby do
gem 'liquid-c', github: 'Shopify/liquid-c', ref: 'master'
gem 'liquid-c', github: 'Shopify/liquid-c', ref: 'inline-comment'
Copy link
Member

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?

Copy link
Contributor Author

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.

end
end
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Liquid Change Log

## Unreleased

### Features
* Allow `#` to be used as an inline comment tag (#1401) [Dylan Thacker-Smith]

## 5.0.0 / 2021-01-06

### Features
Expand Down
4 changes: 2 additions & 2 deletions lib/liquid/block_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

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 = "{%"
Expand Down
15 changes: 15 additions & 0 deletions lib/liquid/tags/inline_comment.rb
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
27 changes: 27 additions & 0 deletions test/integration/tags/inline_comment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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

def test_no_space_after_hash_symbol
assert_template_result('', '{% #immediate text %}')
assert_template_result('', '{% liquid #immediate text %}')
end
end