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

WIP: Update handlebars syntax for Glimmer and Ember syntaxes #3099

Closed

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Apr 3, 2021

It seemed that the handlebars syntax here is pretty old, this PR aims to update it to all the features currently available to Glimmer and Ember projects

Changes

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

Comment on lines 296 to 299
className: 'template-tag',
begin: /<:?/,
end: />/,
contains: [ OPENING_BLOCK_MUSTACHE_CONTENTS, BLOCK_PARAMS, KEYWORD_CONTENTS ]
Copy link
Member

Choose a reason for hiding this comment

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

You can't put an empty block like KEYWORD_CONTENTS here, it'll do nothing because it has no match or begin tags. If you ant to match keywords here you'd put keywords at the top-level.

Suggested change
className: 'template-tag',
begin: /<:?/,
end: />/,
contains: [ OPENING_BLOCK_MUSTACHE_CONTENTS, BLOCK_PARAMS, KEYWORD_CONTENTS ]
className: 'template-tag',
keywords: // keywords go here
begin: /<:?/,
end: />/,
contains: [ OPENING_BLOCK_MUSTACHE_CONTENTS, BLOCK_PARAMS ]

@joshgoebel
Copy link
Member

@nknapp Would you be around to help review this when it's ready?

@joshgoebel
Copy link
Member

If you get overwhelmed here I'd suggest to start with smaller chunks (ie, try to accomplish these things a few at a time) vs a huge PR that does it all. For example you could perhaps clean up the keyword situation first, without trying to add any new tags, etc... so far the PR is "ok" (clean enough for review) but if it gets too complex then we'd ask you to break it into smaller pieces anyways just so we can see what you did and be able to properly review it, etc.

But since this is your first commit and "idk what I'm doing" I'd suggest taking it slow and working in small chunks. (which can be more easily reviewed and merged - which will build momentum and a sense of achievement).

Food for thought.

@joshgoebel
Copy link
Member

You'll likely need to add $pattern back at some point... may want to review the commit log to see why it was added and what problem it's solving.

@joshgoebel
Copy link
Member

Also, is this official handlebars are are these Ember and Glimmer specific extensions?

@@ -324,6 +333,12 @@ export default function(hljs) {
end: /\}\}/,
keywords: 'else if'
},
{
className: 'bulit_in',
Copy link
Member

Choose a reason for hiding this comment

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

typo :-)

Website: https://handlebarsjs.com
Category: template
Website: https://handlebarsjs.com, https://emberjs.com
Category: common, template
Copy link
Member

@joshgoebel joshgoebel Apr 3, 2021

Choose a reason for hiding this comment

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

Please revert, this is not your decision to make - which languages are in our common set. If you just want to add handlebars to the build your an do so on the console:

./tools/build -t node :common handlebars

Etc. Builds common + handlebars.


Also what is embers relationship to Handlebars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also what is embers relationship to Handlebars?

ember has similar syntax, but has built a bunch of stuff on top, as a result, the handlebars syntax in highlight.js ~7 years out of date :(
(but that's why I'm making a PR!) :D

Copy link
Member

Choose a reason for hiding this comment

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

as a result, the handlebars syntax in highlight.js ~7 years out of date

I'm not sure that's a correct statement [in the general sense]. I know @nknapp put a lot of work into it just last year to improve it.

https://handlebarsjs.com

AFAIK Handlebar exists as it's own independent project and there are surely those using it outside of Ember - like our very own project, actually. So the question then becomes whether this is appropriate to be added to Handlebars at all or whether a separate Ember grammar may be needed. I'm curious if nknapp has any thoughts on that.

In any case I can certainly see how this would be helpful for Ember users, but if we decide it's not appropriate as part of Handlebars proper then it would need to be distributed as a 3rd party Ember grammar - rather than mixed with our existing support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's totally fair! Most editors have an ember-variant to use for hbs highlighting

@@ -205,7 +205,7 @@ export default function(hljs) {
};

const SUB_EXPRESSION_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, {
className: 'name',
className: 'function',
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure that your PR explanation justifies (visual) changes like this and explains why they are necessary...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can do!

In this particular case, helpers are functions (and take args), and not actually just a name, like you'd have with the name of a Component invocation.

@NullVoxPopuli
Copy link
Contributor Author

Thanks for the early comments! these are helpful!!

You'll likely need to add $pattern back at some point... may want to review the commit log to see why it was added and what problem it's solving.

I'll check it out 👍

Also, is this official handlebars are are these Ember and Glimmer specific extensions?

handlebars doesn't have components, so about everything I'm doing is going to be on top of handlebars, but for ember and glimmer (they use the same hbs file extension though).

I saw there was an HTMLBars syntax, but it looked like it was going to be removed.

I can move all of this into a new ember/glimmer specific syntax, if that's desired and try extending from handlebars.

@NullVoxPopuli
Copy link
Contributor Author

I have a test template that I'm working through here in the developer.html:
image
(taken from: joukevandermaas/vim-ember-hbs#13)

My plan was to get the whole thing looking correct before taking the PR out of draft.
Most of it should "just" be adding component invocation support

@joshgoebel
Copy link
Member

I saw there was an HTMLBars syntax, but it looked like it was going to be removed.

Correct, also it's only an alias of Handlebars at this point.

I can move all of this into a new ember/glimmer specific syntax, if that's desired and try extending from handlebars.

That is indeed the question. Though at that point it becomes a 3rd party module so I wouldn't worry about "extending" anything (you could, but we don't really encourage or support run-time dependencies)... at that point you'd just be "forking" the grammar essentially and then carrying it forward as Ember/Glimmer specific. But perhaps that's all you meant by "extending" in the first place. :-)

@NullVoxPopuli
Copy link
Contributor Author

I'm gonna move all this to a new file, called glimmer.js, and that way we don't need to worry about handlebars maintenance / maintainers also having to deal with ember/glimmer stuff.
It also gives me a chance to start over, and make sure only what's needed is implemented -- handlebars has some features that ember/glimmer no longer has

@joshgoebel
Copy link
Member

joshgoebel commented Apr 3, 2021

handlebars has some features that ember/glimmer no longer has

This definitely seems to seal the deal that this is an entirely separate grammar, not Handlebars (though I was already leaning that way in my thinking).

At this point you'd be creating a 3rd party grammar module (in your own repository) so I'd check out our documentation on doing that:

https://github.com/highlightjs/highlight.js/blob/main/extra/3RD_PARTY_QUICK_START.md

@NullVoxPopuli
Copy link
Contributor Author

Cool! thanks for having all this documentation written up!

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.

2 participants