jimsynz / hamlbars Goto Github PK
View Code? Open in Web Editor NEWSome extensions to HAML to allow generation of Handlebars templates.
Home Page: https://github.com/jamesotron/hamlbars.git
License: MIT License
Some extensions to HAML to allow generation of Handlebars templates.
Home Page: https://github.com/jamesotron/hamlbars.git
License: MIT License
Hello all,
Is it possible to have an empty Handlebars link-to helper? Right now, I've got this:
=hb 'link-to "someResource.index" class="navbar-brand"' do
\
Is there a better way to get an empty anchor tag without escaping the empty line? I'm doing this to add a CSS background image instead of text. Thanks so much.
I have this
{{#ifValue product_type is="installment"}}
where product_type
is a data attribute I'm passing in to the custom ifValue
helper. Is this possible yet with hamlbars?
This gem seems to be more maintained than https://github.com/thegorgon/hamlbars but it has one advantage, it supports Rails helpers. Obviously the support is imperfect because there is no request while the template is building, but it is very helpful.
Thoughts?
Both the closure and precompile modules are not firing as expected. I believe I tracked it down to the evaluate_without_precompile/closure method already being defined. For precompiling, I was able to get it to work properly by changing the evaluate alias to use _with_js_precompiler, however the same hack on the closure module did not help.
Without closures (I'm pretty sure this would not fine with a closure), on page load, the HandlebarsTemplates object does not yet exist, so HandlebarsTemplates[] fails on assignment.
The handlebars_assets gem also ensures the object already exists inside their closure:
(function() {
this.HandlebarsTemplates || (this.HandlebarsTemplates = {});
this.HandlebarsTemplates["..."] = ...
With normal HAML, you can disable inputs in the definition by doing:
%button{:disabled => disabled ? true : nil}
but in Hamlbars I can't see a way to achieve the same.
I have resorted to <button {{#if disabled}}disabled{{/if}}>
which kind of defeats the purpose of using hamlbars - is there any way to achieve this? Part of the problem is browsers intepret disabled=""
or disabled="false"
as disabled="disabled"
.
my initializer, hamlbars.rb has this:
if defined? Hamlbars
Hamlbars::Template.template_destination = 'Handlebars.blah'
end
yet the compiled javascript (in the browser) results to this:
Handlebars.templates["product"] = Handlebars.compile("testtest");
(the 'testtest' string is a good sign, as my products.js.hamlbars template and its content is being loaded properly)
i did some digging around in the hamlbars gem source itself with a colleague, and we couldn't figure out why the override wasn't working. though it does look like @template_destination never gets used in template.rb.
{{#if author}}
{{location.address}}
{{else}}
{{location.approx_area}}
{{/if}}
This parses as haml prior to handlebars.runtime, so the nesting breaks haml.
One can wrap this in :plain, or not nest conditionals. Neither are ideal.
when you do a RAILS_ENV=production rake assets:precompile
in Rails4 you will get a minified version of JS files. I just realized that hamlbars is not involved in this compilation. I can see haml syntax inside the compiled file:
data.buffer.push("%h1.ui.header.dash-header Posts List\n\n");
This way templates are not rendered in browser. While hamlbars works correctly in development environment and ember didn't log any errors, it took me hours to find out where the problem is.
Can you help?
@aaronjensen @blakink @joliss I'm planning on cleaning up the remaining issues and doing a 1.1 release some time this month. Can I have some comments or thoughts from you guys on what you think needs doing?
I am seriously thinking of ripping out a lot of the code we have here and instead depending on projects like haml_assets
and handlebars_assets
and ember-rails
to do all the work that needs working. Thoughts?
Working on an app with ~30 medium sized hamlbars files, hamlbars takes 26 seconds to compile. We're running it as bundle exec haml -I. -r hamlbars
, with Haml 4.x., from the command line.
Is this normal, or is there something we should be looking at/doing better? Our raw haml files are smaller, but proportionally compile much faster.
Hi,
I tried to use hamlbars, with the latest version of haml :
gem 'haml', '>= 3.2.0.beta'
gem 'hamlbars'
.. and got the following error, when launching rails :
[...]/gems/hamlbars-1.0.0/lib/hamlbars/ext/compiler.rb:9:in `<module:Haml>': Compiler is not a module (TypeError)
from [...]/gems/hamlbars-1.0.0/lib/hamlbars/ext/compiler.rb:8:in `<top (required)>'
from [...]/gems/hamlbars-1.0.0/lib/hamlbars.rb:16:in `<module:Hamlbars>'
from [...]/gems/hamlbars-1.0.0/lib/hamlbars.rb:4:in `<top (required)>'
It works fine with haml 3.1.x.
I've been going through the process of upgrading to ember.js master branch, and it appears that Handlebars.templates no longer exists, which causes an error when hamlbars attempts to set Handlebars.templates["path/to/template"].
It could very well be that something else in my code is busted, but I wanted to ask if you could point me anywhere to make sure that the handlebars library still supports setting paths via Handlebars.templates?
When I compile my hamlbars template (app/assets/javascripts/templates/flash/notice.js.jst.hamlbars
):
.alert.alert-success{"data-auto-dismiss" => "true"}
%a{:class => "close", :href => "#", "data-dismiss" => "alert"} x
%p= hb "msg"
I get the following:
(function() {
this.JST || (this.JST = {});
this.JST["templates/flash/notice"] = <div class='alert alert-success' data-auto-dismiss='true'>
<a class='close' data-dismiss='alert' href='#'>x</a>
<p>{{msg}}</p>
</div>;
}).call(this);
Notice the quotes are missing and it errors out in the JS.
I'm using Hamlbars 2.0.0 along with handlebars_assets 0.7.1.
Anything I'm doing wrong?
Hello,
I'm trying to use Hamlbars in a Ember/Rails project to write my Handlebars templates in HAML, but I can't figure out how to make it work (see below for version numbers).
I've installed Hamlbars using Bundler (gem is hamlbars 1.1.0), then added Hamlbars::Template.render_templates_for :ember
to an initializer, but the HAML code does not seem to be compiled.
Here is my app/assets/javascripts/templates/toto.handlebars.hamlbars
:
#mycontainer
%h1 Toto
And this template (called by a Ember.View) displays :
Ember.TEMPLATES["templates/choose_resort"] = Ember.Handlebars.compile("
\n
Toto
\n
");
(this appears uncompiled on my webpage, and even if it has been compiled, there's no div
nor h1
markup)
Here is what I would have expected instead :
<div id="mycontainer">
<h1>Toto</h1>
</div>
Anyway, could you please tell me if newer Ember.js are not working with Hamlbars, or if I'm missing something here ? Did I mis-named the template file ? Did I forgot to manually call some compiler ? Or am I just trying to do something that is not supposed to be done ?
Thanks a lot in advance.
Tried to get hamlbars 2.0 with latest ember-rails to run (rails 3.2.13).
I was expecting hamlbars to compile the template to handlebars, as described in the documentation. I used the extension .js.hbs.hamlbars.
But instead, I was getting the raw content of the file when I had config.assets.debug disabled. With config.assets.debug enabled, the browser is trying to load ".js.hamlbars.js" files?! I tried with config.handlebars.precompile enabled and disabled, but that doesn't make any difference.
Any idea why? I can't get .haml or .hamlbars assets in my javascripts to work, they seem to be rendering the application layout for some reason...
I get this exception when the application.js is included:
<%= javascript_include_tag "application" %>
I'm using hamlbars with handlebars_assets to use in javascript (backbone). I'm using Rails 3.2.11 and Haml 3.1.7, Hamlbars 2.0.0
Hello,
I'm trying to use this gem with backbone, and it would be useful for me if the javascripts could be into the assets folder, so I can link them in my manifest.
If this is not a problem internally, I would love ithis :)
Looks like hamlbars-2012.3.21 was deleted and changed the version to hamlbars-1.0
I am now getting this error via the emberjs-rails gem when trying to push to Heroku:
Could not find hamlbars-2012.3.21 in any of the sources
Is there another work around for this?
Thanks!
Like ember-rails do: https://github.com/emberjs/ember-rails#architecture
If I have this file app/assets/javascripts/templates/admin_panel.hamlbars, the translated version is:
Ember.TEMPLATES['templates/admin_panel'] = "...";
I think that you could do add some logic like Hamlbars::Template.templates_root = 'templates' and the result be:
Ember.TEMPLATES['admin_panel'] = "...";
Hello, maybe I'm missing something, but the template options doesn't seem to work at my project. I created an initializer with:
Hamlbars::Template.template_destination = 'Ember.TEMPLATES'
Hamlbars::Template.template_compiler = 'Ember.Handlebars.compile'
Hamlbars::Template.template_partial_method = 'Ember.Handlebars.registerPartial'
I'm using ember-rails (not emberjs-rails) - https://github.com/emberjs/ember-rails, the output javascript comes like this:
Handlebars.templates["ember_templates_sessions_logged_out_box"] = Handlebars.compile...
I was expecting something like this:
Ember.TEMPLATES["ember/templates/sessions/logged_out_box"] = Handlebars.template...
did I miss anything or this is not supposed to work this way?
currently,
= hb "if condition" do
%h1 ZOMG
= hb "else" do
%p oh no
compiles to
{{#if condition}}
<h1>ZOMG</h1>
{{/if}}
{{#else}}
<p>oh no</p>
{{/else}}
I didn't see anything in the README or specs for handling this.
Hi,
I've upgraded to the latest version of Hamlbars and the hb blocks are now escaped.
I've seen you made a spec for that - 70f7e8b - however It doesn't work on my rails app :
%script{ type: 'text/x-handlebars' }
= hb 'if a_thing_is_true' do
= hb 'hello'
%a{:bind => {:href => 'aController'}}
returns me :
<script type="text/x-handlebars">
{{#if a_thing_is_true}}{{hello}}
<a {{bindAttr href="aController"}}></a>{{/if}}
</script>
I'll try to dive into that problem, and keep you inform..
The syntax of the {{action}} helper was recently changed (83b7a61a), so Hamlbars doesn't work with Ember master anymore.
Should we just update it to use the context
option as the first argument to {{action}}?
I'm honestly a bit unhappy with the verbosity of our current syntax, so I wonder if we should improve it along with this change.
Right now we have
event: {action: 'edit', context: 'model'}
to yield
{{action edit context="model"}} // old
{{action edit model}} // new
How about this instead?
action: 'edit model'
So there's no surrounding event
. We lose the ability to have multiple actions, but at least in Ember, this isn't supported anyway to my understanding.
Options could be inline, like so:
action: 'edit model href=true'
Hello, I'm getting this error message when trying to compile my .js.hamlbars file:
throw Error("NoMethodError: undefined method `output_buffer=' for #<#<Class:0x007fd1c69bc428>:0x007fd1c7e41bc8>\n (in ........./app/assets/javascripts/ember/templates/sessions/login_box.js.hamlbars)")
My template looks like this:
.loginbox#loginbox
= form_for(User.new, :url => user_session_path()) do |f|
= f.label :email, :class => 'fm-lbl'
= f.text_field :email, :class => 'fm-txt'
= f.label :password, :class => 'fm-lbl'
= f.password_field :password, :class => 'fm-txt'
.remember
= f.check_box :remember_me
= f.label :remember_me, 'Lembrar meu login'
= f.submit 'Entrar', :class => 'fm-sub bt-default'
I had the helpers enabled with
Hamlbars::Template.enable_rails_helpers!
because I need some assets handling helpers
Ember-rails supports the .hbs extension for plain Handlebars templates. It seems reasonable to me to interpret "hbs" as standing for Handlebars, rather than the less common Hamlbars.
How about dropping .hbs support in Hamlbars to avoid ambiguity?
I created this rake task for quickly generating .hamlbars files in /templates
. If you want to use this let me know and I'll fork and PR.
I think you'll run into problems if you ever want to switch to normal version numbers, since 2012.3.21 > 1.0, I presume.
To avoid major pains for users when this gem becomes more popular, how about switching now (releasing 0.1 or 1.0) and yanking all 2012.* versions?
Here's what I've done:
gem 'hamlbars', '~> 2.1'
. We're already using handlebars_assets
.app/assets/javascripts/test.js.hbs.hamlbars
.%p Testing
.When I open the project in my browser, I get the following error:
throw Error("Haml::SyntaxError: Illegal nesting: nesting within plain text is illegal.\n (in /Users/landonschropp/Development/quve/app/assets/javascripts/test.js.hbs.hamlbars)")
I've also tried removing everything from the test
file and I still get the same error.
In case there's a conflict, these are all of the asset gems we're using:
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'haml-rails'
gem 'handlebars_assets'
gem 'gon'
gem 'autoprefixer-rails'
gem 'roadie'
gem 'redcarpet'
gem 'hamlbars', '~> 2.1'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'videojs_rails'
gem 'pickadate-rails', "~> 1.2.0"
gem 'datejs-rails'
I'm trying to use hamlbars with handlebars_assets, but so far have failed to get them to integrate properly.
Out of the box, I tried including both gems:
gem 'handlebars_assets'
gem 'hamlbars'
And when I create a file with a .hamlbars file, it gets compiled properly, but by the handlebars_assets Tilt template, not the hamlbars Template class.
If I change the extension to "file.js.hbs.hamlbars" (as described here https://github.com/jamesotron/hamlbars#chaining-compilation-using-the-rails-asset-pipeline), I get "file.js.haml.js" as my include, and "file.js" cannot even be downloaded directly.
I then decided to pull the latest version of handlebars_assets which changes the initialization order so that the hamlbars template gets used. I did this by changing my gemfile to point to the latest commit in this branch: https://github.com/leshill/handlebars_assets/tree/fix-sprockets-register
as described in issue leshill/handlebars_assets#73
gem 'handlebars_assets', git: 'https://github.com/leshill/handlebars_assets.git', ref: '510fb66d96b881e08af67867d6773cf7a1a17ba2'
gem 'hamlbars'
But that doesn't do the trick. If I keep the filename as "file.hamlbars" no files are included by
If I switch to "file.js.hbs.hamlbars", I run into this issue #42 (Illegal nesting: nesting within plain text is illegal). If I follow the advice in that thread, and switch "file.js.hbs.hamlbars" to ".js.hamlbars" but then the handlebars template gets returned uncompiled to the browser.
If anyone has any tips about how to use both gems together, I would really appreciate it. I have cross-posted this to the other gem's forum too (leshill/handlebars_assets#85) for tracking.
The demo site linked in the README ( http://hamlbars-demo.herokuapp.com/ ) doesn't seem to exist.
hb 'linkTo "map.content.plinks"', 'tagName' => 'li' do
%a{_action: '"showAnimated" "map.content.plinks" model "content"', bind: {href: "view.href"}} Plinks
leads during test mode to a Error: Barber::PrecompilerError: Pre compilation failed error:
{{#linkTo "map.content.plinks" tagName="li"}}<a {{bind-attr href="view.href"}} {{action ""showAnimated"" "map.content.plinks" model "content"}}>Plinks</a>{{/linkTo}}
The _hb part seems to work / the _action seems to change the quotation
hamlbars (2.1.1)
ember-data-source (0.14)
ember-rails (0.14.1)
ember-source (1.2.0)
ruby-2.1.1
%a{:_action => 'someAction context="object" target="controller"'}Click Me
target gets specified fine, but the context object doesn't get passed through :(
hamlbars 2.0.0 includes vendor/javascripts/handlebars.js
.
Handlebars.VERSION; //=> "1.0.beta.5"
This file causes the problem that this path is resolved before the another one defined by handlebars-source in my project.
Could you bump next version?
DEPRECATION WARNING: Sprockets method register_engine
is deprecated.
Please register a mime type using register_mime_type
then
use register_compressor
or register_transformer
.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from module:Hamlbars at /[PATH_TO_GEMS]/hamlbars-2.1.1/lib/hamlbars.rb:19)
In the readme, there is an example that says
= hb 'else' / Notice this line is indented within the original if statement.
But it should read
= hb 'else' do / Notice this line is indented within the original if statement.
Hi, I just wanted to give you a heads up that Haml 4.0 stable is going to be released on Wednesday. Keep in mind that since your gemspec references "haml" with no version, anybody installing your gem after Wednesday will get Haml 4.0 rather than 3.1.x, so you might want to double check to be that your gem is compatible, and if it's not, update your dependency to < 4.0
until you've had time to patch.
If you come across any issues and/or have questions about the latest release, please feel free to ask me.
https://gist.github.com/spundun/6301220
This gist is not working. Based on the few examples of hamlbars that I can find, this should work.
Is stand alone haml not supported? Am I doing something wrong?
I'm using:
I get this error when starting up server. adding the following line to hamlbars.rb fixes it:
require 'sprockets/engines'
When integrating with the latest handlebars_assets
the following error occurs:
Uncaught Template was precompiled with an older version of Handlebars than the current runtime. Please update your precompiler to a newer version (>= 1.0.0) or downgrade your runtime to an older version (== 1.0.0-rc.3).
It'd be great to borrow precompilation from https://github.com/leshill/handlebars_assets
I'm having a very strange error when I try to precompile assets using hamlbars.
If I rename the templates to jst.eco, everything runs fine:
$bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
But, if I move them back to .js.hamlbars, this is what I get:
$bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
File to import not found or unreadable: clearfix.
Load path: Sass::Rails::Importer(/.../app/assets/stylesheets/layout.scss)
(in /.../app/assets/stylesheets/layout.scss)
/.../app/assets/stylesheets/mixins/_mixins.scss:1
/.../app/assets/stylesheets/layout.scss:2
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/import_node.rb:64:in `rescue in import'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/import_node.rb:42:in `import'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/import_node.rb:25:in `imported_file'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/visitors/perform.rb:149:in `rescue in visit_import'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/visitors/perform.rb:154:in `visit_import'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/visitors/base.rb:37:in `visit'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/visitors/perform.rb:18:in `visit'
/.../.rvm/gems/ruby-1.9.3-p125@tudogostoso/gems/sass-3.1.16/lib/sass/tree/visitors/perform.rb:146:in `block in visit_import'
...
It seems that, when I use it, sass get lost loading it's includes. This only happens if I request the templates on my js manifest, and only when compiling assets. In development mode I get no error at all.
Am I the only one having this issue?
The latest handlebars doesn't define a Handlebars.templates object, which causes hamlbars to fail.
I am planning to use the "@Index" used in the first answer to the question in this page http://stackoverflow.com/questions/11884960/how-to-get-index-in-handlebars-each-helper
I get the unexpected token error. So how do i represent that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.