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

Add # inline comment tag. #1498

Merged
merged 4 commits into from
Apr 28, 2022
Merged

Add # inline comment tag. #1498

merged 4 commits into from
Apr 28, 2022

Conversation

charlespwd
Copy link
Contributor

@charlespwd charlespwd commented Dec 16, 2021

This PR adds a new tag named # that behaves like a comment.

Therefore it behaves as you'd expect any tag would work. The difference with the comment tag is that the comment is in the tag markup and that there is no block delimiter.

What it looks like in practice:

{%- # this is an inline comment -%}
{% # this too is an inline comment %}
{% #the space is not required %}
{%
  ###############################################
  # Therefore you can write them like this too. #
  ###############################################
%}

{% liquid
  # required args:
  assign product = product

  # optional args:
  assign should_show_border = should_show_border | default: true
  assign should_show_cursor = should_show_cursor | default: true
%}

{% liquid
  # This is a very long comment that spans multiple lines.
  # It looks very similar to what it would look like if you wrote
  # ruby code instead of liquid. But it doesn't have all the clunk
  # of having an open tag and a close tag with so many characters.
%}

It's a follow up of #1401 (thanks @dylanahsmith !) with passing unit tests. Like #1401, this depends on a liquid-c PR from Dylan (that I rebased in inline-comment-fresh)

@dylanahsmith
Copy link
Contributor

It's a follow up of #1401 (thanks @dylanahsmith !) with passing unit tests.

The only reason that PR had failing tests is because @tobi pushed ab45548 which is basically the scope creep that prevented an initial version from shipping that just supported # whole tag comments without precluding adding support for a comment suffix. If that disagreement has been resolved, I could revert that commit to make the tests pass again.

@richxrich
Copy link

Very much like this feature, anything I can do to assist?

Copy link
Contributor

@dylanahsmith dylanahsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an entry to History.md for the change as well.

Other than that and my review comments, LGTM.

test/integration/tags/inline_comment_test.rb Show resolved Hide resolved
invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
render: "Syntax error in tag 'render' - Template name must be a quoted string"
Copy link
Contributor

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.

Gemfile Outdated Show resolved Hide resolved
charlespwd and others added 4 commits April 28, 2022 09:38
This commit adds a new tag named `#` that behaves like a comment.

Therefore it behaves as you'd expect any tag would work. The difference
with the comment tag is that the comment is in the tag markup and that
there is no block delimiter.

What it looks like in practice:

```liquid
{%- # this is an inline comment -%}
{% # this too is an inline comment %}

{% liquid
  # required args:
  assign product = product

  # optional args:
  assign should_show_border = should_show_border | default: true
  assign should_show_cursor = should_show_cursor | default: true
%}

{% liquid
  # This is a very long comment that spans multiple lines.
  # It looks very similar to what it would look like if you wrote
  # ruby code instead of liquid. But it doesn't have all the clunk
  # of having an open tag and a close tag with so many characters.
%}
```

Co-authored-by: Dylan Thacker-Smith <Dylan.Smith@shopify.com>
Copy link
Contributor

@dylanahsmith dylanahsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed commits to address my minor review suggestions. I've also merged the corresponding liquid-c PR and updated this PR to test against liquid-c master again.

@dylanahsmith dylanahsmith merged commit 05d768c into master Apr 28, 2022
@dylanahsmith dylanahsmith deleted the feature/new-comment-syntax branch April 28, 2022 13:47
@t-kelly
Copy link

t-kelly commented Apr 29, 2022

🥳

@isaacbowen
Copy link

The Mechanic community - https://apps.shopify.com/mechanic - is going to be puuuuumped about this. Been a requested feature for eons, and we've been holding off after seeing this in development. Thank you!

@dylanahsmith
Copy link
Contributor

Note that this has been deployed and is available to use in Shopify now, even though the documentation hasn't yet been updated to mention this feature.

@ADTC
Copy link
Contributor

ADTC commented Jun 2, 2022

Will this work? If not, what's the best alternative?

{% #
This is a very long comment that spans multiple lines.
Technically it should be possible if the hash symbol tag
has the parser ignore everything until the closing symbol
in the last line. (Or will it break after the "if customer"?)
<script>
{% if customer %}
function myFunction() {
    console.log('{{ shop.name }}`);
}
myFunction();
{% endif %}
</script>
%}

@charlespwd
Copy link
Contributor Author

@ADTC. No this is still best served by the {% comment %} block (which also supports nested comments)

Inline comments are for smaller comments and every line must be prefixed by #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants