Skip to content

Handlebars scanner #103

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Handlebars scanner #103

wants to merge 1 commit into from

Conversation

dgeb
Copy link

@dgeb dgeb commented Dec 17, 2012

I've written a new scanner for the Handlebars templating language. I will submit a corresponding pull request to coderay-scanner-tests very soon.

Just let me know if you have any questions or suggestions. Thanks!

'h' => :c,
'haml' => :haml,
'handlebars' => :handlebars,
'hbs' => :handlebars,
Copy link
Member

Choose a reason for hiding this comment

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

Who came up with this abbreviation? Is it really used? I mean, we're not on DOS any more…

Copy link
Member

Choose a reason for hiding this comment

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

Wow, seems to be standard: https://github.com/donpark/hbs, https://github.com/leshill/handlebars_assets. Well, back to 1985 then…

Copy link
Author

Choose a reason for hiding this comment

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

haha - I blame lazy typists ;)

@korny
Copy link
Member

korny commented Feb 17, 2013

Thanks for your pull request! I got a few questions.

  • Handlebars is a free template language, but your scanner assumes it's outputting HTML. That's true in a lot (most?) of cases, it's possible to use it for HAML, JavaScript, or even Ruby code. (The same argument could be made for ERb, though.) What do you think? Should we mark the scanner as HTML+Handlebars or something, like Pygments does? Should the output language be a parameter?
  • Your scanner only highlights comments and general tags. I think it would be great to have more colors here, for example for blocks, functions, arguments, path components. Do you want to add that?

@dgeb
Copy link
Author

dgeb commented Jun 25, 2013

@korny I am so sorry for letting this PR fall through the cracks. You asked some good questions that I didn't have immediate answers to and then I let this slip to the bottom of my stack. I've just rebased this PR and will try to follow through more promptly this time.

I hear what you're saying regarding Handlebars as a free template language. I really tried to follow the pattern set for erb to keep this simple and because it's directly analogous. I think that if we were to generalize one, we should generalize both scanners in the same way. Are any other scanners this flexible? Can we start simple and then pursue the flexibility later?

You're also right that I've kept the actual highlighting pretty simple. I'm highlighting delimiters ({{, }}, {{#, /}}, {{{, }}}), attributes names and values, and comments. I'm reusing the html scanner within handlebars blocks in order to highlight attribute names and values. We could choose to highlight blocks like {{#each comments}} ... {{/each}} differently from non-block expressions {{comment}}, but I'm not sure we could go much further. Because almost any word can be registered as a helper, it's impossible to distinguish a helper's name from a simple path expression without context. Maybe there are other opportunities for highlighting that I'm missing... please let me know if you can provide some examples. Also, let me know if you want to differentiate block vs. non-block expressions.

I'll try to see this through ASAP now, assuming you're interested in merging it. Thanks in advance.

@dustinfarris
Copy link

@korny Would it be appropriate to merge this in even in its current state. Sort of as an MVP that can be improved in future pull requests?

@korny
Copy link
Member

korny commented Jan 8, 2014

I'm interested in merging it, but I don't like to add "beta" scanners. It should be more complete before it is included in CodeRay, see my comments above.

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

Successfully merging this pull request may close these issues.

3 participants