Giter Club home page Giter Club logo

handlebars's Introduction

Sublime Text 2 / 3 Handlebars.js bundle

  • Colours of Handlebars expressions are selected to be in contrast with the surrounding HTML.
  • Handlebars expressions get syntax highlighting in HTML attributes.
  • Parameters passed to block expressions get syntax highlighting too.
  • Works both with individual template files and inline templates in script tags.
  • Key bindings for {{! Handlebars comments }} (Sublime only)
  • Tab triggers for
    • if{{#if }}
    • ifel{{#if }} {{else}}
    • el{{else}}
    • elif{{else if }}
    • un{{#unless }}
    • ea{{#each }}
    • wi{{#with }}
    • par{{> }} (for partials)
    • x-temp<script type="text/x-handlebars" data-template-name="$1"> (inline script tag in HTML files using the Ember recommended data-template-name attribute)
    • x-id<script type="text/x-handlebars-template" id="$1"> (inline script tag in HTML files using the legacy id attribute)

Since (as of February 2017) the syntax definitions in this repository are driving the highlights on Github and in Visual Studio Code, it's fair game to open issues related to either of these 😺

About Handlebars.js

It's a great JavaScript templating engine, based on Mustache, but amongst others adding the ability to precompile templates and to create custom helpers.

Official website: handlebarsjs.com

Sublime Text installation

Get it through Sublime Package Control.

If you haven't used it yet, just install it from the link above and then:

  1. Press Shift + Cmd + P (OS X) or Shift + Ctrl + P (Windows)
  2. Type install, to bring up the Package Control: Install Package option, and press Enter
  3. Look for Handlebars, and press Enter to install it.
  4. Choose Handlebars in the bottom right corner with one of your template files open (or in case you have inline templates use Handlebars instead of HTML, it's gracefully extending it so you shouldn't lose anything)
  5. Profit

Package Control will also auto-update the package from this point on!

Known problems and workarounds

Sublime: No auto-complete on closing HTML tags (#23 & #49)

Problem: when closing an HTML tag, the tag name doesn't get auto-completed after typing / (or when using the Cmd + Alt + . (OS X) shortcut anywhere), even though this is the default behaviour with the HTML package.

Solution: installing the Tag package re-instates these functionalities and seems to be working well with this one.

Sublime: HTML tag pair doesn't get highlighted (#48)

Problem: moving the cursor over an HTML tag doesn't highlight its pair.

Solution: installing the BracketHighlighter package nicely solves the problem and adds much more powerful bracket matching than the built-in one.

Sublime: Expand selection to tag doesn't work (#47)

Problem: Expanding selection to tag doesn't work (Sublime command: expand_selection {"to": "tag"}).

Solution: if you install the Emmet package you can use the Match Tag Pair functionality by pressing Ctrl + D (OS X) or Ctrl + Shift + A (Windows).

Sublime: .sublime-build in the build system menu (#73)

Problem: a useless and confusing item named .sublime-build is added to the build system menu. This is because the package internally uses a custom build configuration to be able to target both Atom and Sublime and this gets exposed. Though it's only needed for development, Sublime doesn't seem to offer an option to hide this as the package gets installed.

Solution: delete the file from the package by running zip -d Handlebars.sublime-package ".sublime-build" in the folder it's installed or by any other means.

Testing / contribution

I've recently stopped heavily using Handlebars at my day job and became a father, so any contributions are more than welcome! I'm still using Github so will make sure to keep on being responsive on issues and pull requests.

There are some sample templates in test/ folder. It's possible to see the different supported and yet to be implemented use cases there.

Sublime Text

If you want to work on the package you should install PackageDev either from Github or from Package Control. With that you can edit the JSON version (grammars/Handlebars.json) and let it export the Plist (grammars/Handlebars.tmLanguage) with the ST Build System.

Sublime Text does not use the Plist format (grammars/Handlebars.tmLanguage); rather, it uses the Sublime-Syntax file (grammars/Handlebars.sublime-syntax). This file was originally generated with the Plugin Development: Convert Syntax to .sublime-syntax Sublime command, but it has since diverged in order to fix a Sublime Text specific bug (#110). Ideally, the two versions will track each other, but Pull Requests which effect only one version are still appreciated.

The nicest development setup I found so far is to have the package installed via Package Control and then symlinking the development Git repo to Sublime settings folder > Packages, which then overrides the installed one so you can toggle between them easily.

Another great trick I found out about recently is the Show scope name shortcut (Shift + Ctrl + P (OS X) or Shift + Ctrl + Alt + P (Windows)) which will display the language scope on the status bar based on where your cursor is. If you're getting tired of pressing all these keys all the time, there are a few brilliant packages which do this automatically like the more subtle ScopeAlways or the full on ScopeHunter – note: both need to be activated via the Command Palette.

Precompilation

This package does not offer any Handlebars precompilation functionality to keep things simple, but you can use Ruby Guard (which is a file system watcher) and Guard-Steering (a Handlebars precompiler from yours truly) to have all templates precompiled as you save them.

There's also a Guard package for Sublime if you want integration, but I don't personally use this as I'm happy with Guard running in a terminal window I can access from anywhere.

There are of course Node.js / Grunt / Gulp based compilers too (like this and this), but I haven't personally used any yet for precompilation.

Credits

Adapted from the great sublime-text-handlebars package by Nicholas Westlake.

Thanks a lot to all the generous contributors!

License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

handlebars's People

Contributors

bittersweetryan avatar bsradcliffe avatar calumbrodie avatar daaain avatar duncanbeevers avatar hlvnst avatar iamntz avatar jamesl1001 avatar jonschlinkert avatar matthiasportzel avatar pchaigno avatar samselikoff avatar utkarshkukreti avatar zeppelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

handlebars's Issues

no support for {{!-- --}} style commenting

alt-command-slash (Mac) on text-selection should wrap the selection in a {{!-- --}} type comment. This allows commenting code blocks which contain other hbs expressions.

Highlighting of these type of comments would also be great!

CMD + Alt + . Keyboard Shortcut is Disabled

I can't figure out why - but when I have a file type set to Handlebars, the standard Sublime keyboard shortcut of CMD + Alt + . - which is the shortcut for Edit > Tag > Complete Tag does not function at all.

I've been able to verify this with a couple of people to ensure it's not just my environment, but I'm not sure what other info I can provide to debug.

I'm on Sublime 2.0.2 build 2221

Using command + / on an HTML comment results in it being surrounded by a Handlebars comment

Steps:

  1. Create a template, template.hbs
  2. Open it in Sublime
  3. Add a comment with HTML in it:
<!-- <a href="http://moo.cow.com/">Link</a> -->
  1. Select the comment (from < to >) and press command + /

Result:

Selection is wrapped in Handlebars comment:

{{! <!-- <a href="http://moo.cow.com/">Link</a> --> }}

Expected:

Selection is uncommented:

<a href="http://moo.cow.com/">Link</a>

Changing Tab triggers

Hey great work here!
I would like to change the output of tab triggers like if, par and so on, but couldn't find where.
I use modified syntax, so for example
par → {{> }}
I need
par → {{ }}

anyway, I think you understood what I'm after.

Good luck with the dad thing btw 👍

Variable/expression as tag name

<{{tag}} attr="asdf">asdf</{{tag}}>

GitHub uses this project/repo for its Handlebars highlighting in case you didn't know, so the above code block will reflect the status of this error.

Atom not working

How do you make this work in atom?
Activating your plugin does not show up Handlebars in the list of possible editors.

Block comments don't exist for Handlebars

Instead of wrapping one selection of multiple lines in one pair of {{! }}, which Handlebars doesn't allow, could this instead wrap each line from first to last character, like Javascript comments?

{{! {{#if foo}} }}
{{! <h1>foo</h1> }}
{{! {{/if}} }}

Instead of...

{{! {{#if foo}}
<h1>foo</h1>
{{/if}} }}

Sublime does not enable extension in correct context

I find that I have to manually change the detected syntax to handlebars to get this to work.

I have two scenarios.

  1. Files with the extension 'handlebars.twig' - which are handlebars files written using the twig templating language

  2. (solving this would also solve the above I think) - Within html files where my handlebars template is defined inline, within a script tag with the appropriate type i.e (text/x-handlebars)

<!DOCTYPE html>
  <head>
    <meta charset="utf-8" />
    <title>Ordr: Rstaurant Mnu Systm</title>
  </head>
  <body>

    <script type="text/x-handlebars" data-template-name="application">

     <!-- snippets should be useable inside this scope -->

      <h1>Ordr</h1>
      {{ outlet }}
    </script>

    <script src="js/libs/jquery-1.8.3.min.js"></script>
    <script src="js/libs/handlebars-1.0.0.rc.2.js"></script>
    <script src="js/libs/ember.js"></script>
    <script src="js/libs/ember-data.js"></script>
    <script src="js/app.js"></script>
  </body>
</html>

Tags within HTML comments are styled as normal

Steps:

  1. Create a template, template.hbs
  2. Open it in Sublime
  3. Add a comment with HTML in it:
<!-- <a href="http://moo.cow.com/">Link</a> -->

Result:

HTML tags contained within the comment are styled as normal.

Expected:

HTML tags within comments should be gray (or similar, depending on your theme).

Mustache Compatible? Example Usage?

Since Handlebars is based on Mustache, I am wondering if this package inherently supports Mustache.

Also I'm wondering about the usage. Mustache documentation says to include the following script tag in the markup -

<script id="entry-template" type="text/x-handlebars-template"> template content </script>

Whereas, I have a separate .html file, loaded with ajax, which contains multiple mustache script tags like so -

<script id="template_1" type="text/html"> {{opt_text}} </script> <script id="comment_subtype_0" type="text/html">
  • {{li_text}}
  • </script>

    This may be beyond the scope of what the package is supposed to do, I'm just wondering what is the true use case for the package.

    Error message: unable to load Handlebars.tmLanguage

    I'm using Sublime Text 3 build 3083 on Ubuntu. In recent days when I start the editor, I'm getting an error message:

    error: Error loading syntax file "Packages/Handlebars/Handlebars.tmLanguage": Unable to open Packages/Handlebars/Handlebars.tmLanguage
    

    I've tried uninstalling and re-installing the Handlebars package via package manager, but I still get the same error.

    Version number is 2015.05.31.18.29.42. What other information would be helpful for me to supply?

    Tag auto-closing

    Minor detail, but I noticed that in HTML files, tags will close when typing < after the opening tag. This doesn't happen in HBS files though using the Handlebars syntax.

    div

    DOCTYPE declaration gets reported as wrong

    Hey! Thanks for the great package.

    I noticed that, when applied to HTML documents, your syntax highlighting will "report" the opening bracket in <!DOCTYPE html> as if there were an error in it. It's nothing major, but at times it kind of bothers my side vision since I use the same red errors to spot when there's unattended whitespace around. Here's how it looks:

    example

    In the default HTML package it looks like this:

    example

    I know you're probably really busy and this is somewhat of a nitpick, but if you've got some spare time could you please have a look into it? 😄

    Thank you very much and keep up the good work!

    Curly brackets not highlighted?

    Hi, I just installed the Handlebars package for ST3 but I'm not sure I'm getting the correct color highlighting for the curly brackets.

    Here's a screenshot of a sample file:

    image

    I'm using the Spacegray/base16-ocean.dark theme. Is this what other people are seeing?

    Any help would be appreciated.

    Is there a reference for keybindings?

    Is there a reference I can look at for key bindings?

    To insert a comment, {{!-- --}}, we can use Command + /. How can I insert plain curly brackets?

    {{}}
    

    Is there a keyboard binding for this? Or a reference for keyboard bindings?

    Emmet doesn't work within <script> template

    I have the following template within a server side handlebars template, index.hbs:

    <script type="text/x-handlebars-template" id="question-form-template">
      <p>\{{ question }}</p>
    </script>
    

    While syntax highlighting works, Emmet doesn't. I'm not sure how to make it work. I've tried this solution on handlebars.tmlanguage:

    http://www.sublimetext.com/forum/viewtopic.php?f=2&t=4057

    To no avail, unfortunately.

    Note: I'm using Handlebars both on the server (via express-hbs) as well as on the front end with Backbone, hence a Handlebars template within a Handlebars template :)

    Highlighting only works for first block

    I feel like this used to work, though I'm new to handlebars so I haven't used it much. Perhaps it's a ST thing, but only the first block of text is being colored:

    image

    Wonky curly brace matching within a block

    screen recording 2015-02-26 at 12 47 pm

    I'm seeing some funny curly brace matching behaviour when I try to add them within a block containing HTML. I think the gif describes the issue pretty well.

    Please let me know if I can do anything else to help diagnose the issue and thank you for a really great plugin!

    fix highlighting inside embedded script tags

    javascript like this isn't highlighted:

    <script type="text/javascript">
      var _gaq = _gaq || [];
      var pluginUrl =
        '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
      _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
      _gaq.push(['_setAccount', '{{site.google.analytics}}']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script');
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(ga, s);
      })();
    </script>

    Use of handlebars with re-indent?

    Hello,

    This is more of a newbie question than an issue, but I wonder if it is possible to have the handlebars syntax follow/work with the reindentation feature of sublime? When I use this feature (I get a frustrating amount of improperly indented code to work with, with several handlebars if/else statements), anything within the handlebars conditional isn't indented one tab.

    Not an issue, just a low priority request.

    Reindent functionality doesn't work inside templates

    When using this plugin, or the standard html plugin, "reindent" functionality does not work inside script blocks. For example, in the example code below, using "reindent" on any of the opening or closing div tags does not move the tag out. Reindent on a large block of template markup just flattens it out to the same level as the script tag.

    <html>
       <script type="text/x-handlebars" data-template-name="test">
    
       <div>
       <div>
       </div>
       </div>
    
       </script>
    </html>
    

    This is pretty critical for users for the sublemacspro (emacs keybindings), as tab is defaulted to reindent to match emacs functionality. If you have any thoughts on what the solution is I might be able to look into the fix, I just don't really know where to get started.

    data attributes aren't highlighted correctly

    It seems that data- attributes aren't being highlighted correctly in general.

    I tend to use data- attributes as functional hooks separate from CSS/style hooks like classes and id attributes.

    Sublime Text - build 3059 with the latest Sublime Handlebars package installed via Package Control.

    sublime-handlebars-error-on-data-tag-highlighting

    highlighting for {{@key}}?

    You can use {{#each}} on objects, and you use {{@key}} to access the key of the current pair, currently it's just rendering plain white, which I believe is unintended?

    Expand selection to tag doesn't work

    Expanding selection to tag doesn't work when I set the syntax to be a Handlebars template.

    The specific command is:
    command: expand_selection {"to": "tag"}

    which i have bound to cmd+shift+a.

    Recognize .handlebars.html files

    I am trying to make Sublime be smarter about which template my files are as soon as they're opened and play nice with frameworks that don't recognize the .handlebars extension. One idea brought up was to name files with a .handlebars.html extension.

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.