leshill / handlebars_assets Goto Github PK
View Code? Open in Web Editor NEWUse handlebars.js templates with the Rails asset pipeline.
License: MIT License
Use handlebars.js templates with the Rails asset pipeline.
License: MIT License
After playing with hamlbars for a while, I started getting the sense that it was a bit too hacky for my taste.
I recently discovered Emlem.js (https://github.com/machty/emblem.js), which feels a bit like HAML. I was thinking about seeing how hard it would be to hook it into handebars_assets, but before I go too far down this rabbit hole I am curious if you have any thoughts on supporting emblem.js
Does this gem work in Rails 3.2? I'm not getting any errors, but I'm not getting it to work either.
I am sure you just forgot to run your test suite ;)
Here is a complementary backtrace. (0.5.0) still works
/Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/handlebars_assets-0.6.0/lib/handlebars_assets/tilt_handlebars.rb:50:in `relative_path' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/handlebars_assets-0.6.0/lib/handlebars_assets/tilt_handlebars.rb:54:in `template_name' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/handlebars_assets-0.6.0/lib/handlebars_assets/tilt_handlebars.rb:24:in `evaluate' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/context.rb:177:in `block in evaluate' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `evaluate' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:12:in `initialize' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `new' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `block in build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:262:in `circular_call_protection' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:240:in `build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:106:in `block in build_required_assets' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:100:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:100:in `build_required_assets' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:16:in `initialize' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `new' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `block in build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:262:in `circular_call_protection' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:240:in `build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/bundled_asset.rb:16:in `initialize' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `new' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/actionpack-3.2.6/lib/sprockets/static_compiler.rb:23:in `block in compile' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:212:in `block in each_logical_path' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:200:in `block (2 levels) in each_file' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each_entry' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:198:in `block in each_file' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each_file' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/sprockets-2.1.3/lib/sprockets/base.rb:210:in `each_logical_path' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/actionpack-3.2.6/lib/sprockets/static_compiler.rb:18:in `compile' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/actionpack-3.2.6/lib/sprockets/assets.rake:56:in `internal_precompile' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/actionpack-3.2.6/lib/sprockets/assets.rake:70:in `block (3 levels) in ' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /Users/trcarden/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@quizzes/gems/actionpack-3.2.6/lib/sprockets/assets.rake:60:in `block (3 levels) in ' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' /Users/trcarden/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.2.2/bin/rake:33:in `' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/bin/rake:19:in `load' /Users/trcarden/.rvm/gems/ruby-1.9.2-p180@global/bin/rake:19:in `' Tasks: TOP => assets:precompile:primary
Hi all -
I updated my gem file, and now my partial handlebar assets aren't loading. I've got a partial in a "/shared" directory that loads fine in development, but not in production (not on heroku nor on a custom linode instance).
Both production sites give this error:
Uncaught Error: The partial nav_strip could not be found
I'm using rails 3.2.6, handlebars_assets 0.5.0, and sprockets 2.1.3
It worked fine using 3.2.6, handlebars_assets 0.5.0, and sprockets 2.1.2 (not sure what combination worked in the past on production, but it did)
Any idea why?
Here's detail on the error:
Uncaught Error: The partial nav_strip could not be found /assets/application-01f8505027960848c2f1be6ecf70aff4.js:20
Handlebars.VM.invokePartial /assets/application-01f8505027960848c2f1be6ecf70aff4.js:20
(anonymous function) /assets/application-01f8505027960848c2f1be6ecf70aff4.js:23
(anonymous function) /assets/application-01f8505027960848c2f1be6ecf70aff4.js:20
Financials.Views.Home.r.render /assets/application-01f8505027960848c2f1be6ecf70aff4.js:23
e /assets/application-01f8505027960848c2f1be6ecf70aff4.js:23
Financials.Routers.Accounts.n.index /assets/application-01f8505027960848c2f1be6ecf70aff4.js:23
s.extend.route /assets/application-01f8505027960848c2f1be6ecf70aff4.js:21
(anonymous function) /assets/application-01f8505027960848c2f1be6ecf70aff4.js:21
S.some.S.any /assets/application-01f8505027960848c2f1be6ecf70aff4.js:21
s.extend.loadUrl /assets/application-01f8505027960848c2f1be6ecf70aff4.js:21
s.extend.start /assets/application-01f8505027960848c2f1be6ecf70aff4.js:21
window.Financials.init /assets/application-01f8505027960848c2f1be6ecf70aff4.js:22
(anonymous function) /assets/application-01f8505027960848c2f1be6ecf70aff4.js:22
s.Callbacks.d /assets/application-01f8505027960848c2f1be6ecf70aff4.js:16
s.Callbacks.v.fireWith /assets/application-01f8505027960848c2f1be6ecf70aff4.js:16
i.extend.ready /assets/application-01f8505027960848c2f1be6ecf70aff4.js:16
n.addEventListener.k
If I understand things correctly, Sprockets will process Ruby in JavaScript files if .erb
is appended to the end. It seems to me that this can be enabled by simply changing some of the file name checks to allow for .erb
to be present at the end, and then Sprockets will handle the rest. Does this seem accurate? Or does handlebars_assets run before that sort of processing would occur? I'd be happy to attempt to implement it if you think it would be useful.
Trying to get this gem working in our Rails 3 app, but the global namespace for templates is coming back as 'undefined,' both in my coffee files and in my Chrome console.
My application.js.coffee
looks like this:
#= require './lib/jquery.min'
#= require './lib/underscore.min'
#= require './lib/backbone.min'
#= require './lib/marionette.min'
#= require 'handlebars'
#= require_tree ./templates
#= require_tree ./models
#= require_tree ./collections
#= require_tree ./views
#= require 'connectors.app'
I've tried moving the ./templates
directory up and down the list, and nothing fixes it. Everything else functions just fine (I'm able to call Backbone.Model
, for instance).
This is in my dev environment. My development.rb
looks like this:
Connectors::Application.configure do
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true
end
Thanks for any help!
I am submitting this issue to promote discussion...
Mainly wondering if it would make more sense to build a more generic Adapter interface for various libv8/javascript rendered asset pipelines (e.g. merge handlebar_assets and mustache_assets etc...)
Any thoughts?
But I get this error whenever my app tries to parse a .jst.hbs file:
ActionView::Template::Error (Error: Usage: /var/folders/j7/y4hnjr3j1fq6bhz2zrmrq6sc0000gn/T/execjs20110911-14138-1e6b2y7.js FILE
(in /Users/chicks/Projects/adjutant/app/assets/javascripts/templates/identities/show.jst.hbs)):
3: <head>
4: <title>Adjutant</title>
5: <%= stylesheet_link_tag "application" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body class="container_12">
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__436811332128615094_2173991620'
Manifest file:
//= require jquery
//= require jquery_ujs
//= require handlebars
//= require ./lib/underscore
//= require ./lib/backbone
//= require_tree ./app
//= require_tree ./models
//= require_tree ./collections
//= require_tree ./views
//= require_tree ./routers
//= require_tree ./templates
Template file (app/assets/javascripts/templates/show.jst.hbs):
This is {{handlebars}}
I'm on rails 3.1 rc8 and mri 1.9.2
Thoughts?
If you make a blank .hbs
files, it will throw an exception. It would be great if you just skip blank files.
When using the require directive to embed a template file in another file the initial template source is altered (a newline is appended).
It may seem harmless but it may cause undesired and visible effects.
Example.
# base.js.coffee
#= require templates/foo
text = document.createTextNode(JST['foo']())
el = document.getElementById('container')
el.appendChild(text)
# templates/foo
no newline after this phrase
In the example above the text node will be
"no newline after this phrase
"
instead of "no newline after this phrase"
We have currently decided to trim the compiled template output before using it with text nodes. But is there another way around?
Using the following require is the only way to get the templates added to the global namespace automatically.
//= require_tree ./templates
HandlebarsTemplates'contacts/new';
What if we don't want to include all the templates in our application? An example is a Rails site that may have multiple backbone apps. We don't always want to pull in all the templates.
If we specify
//= require ./templates/foo/bar
then HandlebarsTemplates'foo/bar'; should work, but it doesn't because for some reason HandlebarsTemplates becomes undefined.
Hey hey
Im trying to use the .hamlbars extension, but it doesnt seem to be working. .haml files are working fine.
I think it has to do with the fact that .hamlbars isnt included at line 18 of https://github.com/leshill/handlebars_assets/blob/master/lib/handlebars_assets.rb
otherwise, this gem is awesome, and being able to use .hamlbars will be even awesomer
PS: I am definitely using v0.8.1
I have a slimbars template like so:
li
a.profile-button
img src="/assets/profile.png"
span.menu-link My Profile
This loads the asset from my rails server. I am deployed on Heroku, and push all my assets to S3, so the assets are available, and fingerprinted, on S3 by the asset pipeline, but I can't figure out how to use asset pipeline'd assets from within my templates.
This is my main template:
ul.dropdown
| {{> _menu_list_items }}
In the partial template I render image tags which I would like to server from S3.
I tried adding a .erb
on the end of the template and inserting it that way, but resulted in the template being inserted into my view as a giant slimbars string. It was processed by erb, but that prevented the processing by slim.
Here is the partial:
li
a.profile-button
img src="<%= asset_path('/assets/profile.png') %>"
span.menu-link My Profile
became the following in the final DOM (local, so not hitting S3, but it did evaluate the asset_path
:
<ul class="dropdown">li
a.profile-button
img src="/assets/profile.png"
span.menu-link My Profile
</ul>
Hoping I missed something obvious, because it seems like this would be a common need, yet I haven't been able to find anything by googling.
Hey guys,
Firstly, thanks for the time you've invested in this gem. It really simplified the process of getting Handlebars in a my Sinatra app.
I had one problem, though, and that was informing my Sprockets::Environment
instance of the asset path supplied by this gem. I eventually got it working after delving into the source code, but it's quite a hack:
handlebars_path = HandlebarsAssets::Handlebars.send(:assets_path).join("javascripts")
environment.append_path(handlebars_path)
How did you guys intend for the asset path to be included? Let me know and I'll be happy to update the README to include instructions and send a pull request.
I am trying to use handlebars_assets with requirejs-rails + backbone + backbone.marionette and am having a lot of trouble.
It seems like everything is working except I have no access to my template namespace within my require closures.
This stackoverflow question does a pretty good job of going over the problem. However if I use the solution there I lose all of the benefits of handlebars_assets and the asset pipeline.
Is there a way to make handlebars_assets require.js/AMD friendly? Or is it already and I've missed something?
we need this commit in handlebars handlebars-lang/handlebars.js@5a6e4f1
could you please update the bundled handlebar.js to even better let us override the vendored handlebar by passing the path to the newer/customized version
hey there
just some days ago I upgraded to handlebars_assets 0.12.1 and now I've got a problem with wrong compilerInfo being generated.
I've got a private gem (really just a rails engine file and some templates) and all templates from within the gem are generated with the old compilerInfo, [2, 1.0.0.rc3]
, causing handlebars to raise an exception.
Here's a accurate summary:
gem 'rails', '3.2.12'
# ...
# Gemfile, outside of asset group
gem 'handlebars_assets', '0.12.1'
I'm using an initializer to change HandlebarsTemplates to JST:
# config/handlebars_assets.rb
HandlebarsAssets::Config.template_namespace = 'JST'
inside my application.coffee I'm requiring the main file from inside my own gem:
# application.coffee
#= require fail_bowl
the main file in my gem actually requires all necessary templates:
# fail_bowl.coffee
#= require_tree ./templates
Now to the interesting parts:
The app & the gem contain templates -
all templates inside the main application get the following, correct compilerInfo:
this.compilerInfo = [3,'>= 1.0.0-rc.4'];
all templates from the gem get the wrong compiler info:
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
when I change the template the file is regenerated, but the wrong compilerInfo sticks around!
I'm thankful for all suggestions :)
cheers,
Raphael
We have a web site that has several "mini apps" that currently use backbone over rails, leveraging handlebars_assets.
We're wanting to add to this app (might not be an ideal solution) so that our new "mini apps" work with ember instead of backbone.
I'm having problems getting handlebars_assets to play nice in that environment. On one hand, I can get the backbone app to work as it has in the past.
To get ember to work properly, I need an initializer for Handlebars that's configured to help ember, but that changes how the backbone templates are loaded, thereby breaking them.
Is there a way to set how handlebars_assets compiles templates so that both client front ends are happy?
Thanks for any ideas...
currently everything works swell in development but it's broken in production. it simply just doesn't want to precompile and include the template asset files while in production.
as such, I'm getting JavaScript errors like this: ReferenceError: HandlebarsTemplates is not defined
I'm having trouble figuring out exactly what needs to be done to allow this to work in production. if you could assist me, it'd be greatly appreciated.
currently, I have handlebar_assets JavaScript assets loading in application.js
and I have the template assets in assets/templates
any ideas? where should I start?
thanks in advance
Hey Les,
Any chance I could convince you to take the .rvmrc out of the repo? Seems like a per-environment kinda file.
-B
As Rails 4.0.0.rc2
Hi there,
I see a number of references here to JST[template_name]
, however in master the templates live in HandlebarsTemplates
. I tried to look through the repo history for this change, but I couldn't find it.
Could you add a configuration option to choose the name of the template namespace? We're trying to share some JS code between a Rails 3.0 app running Jammit and a Rails 3.2 app with Sprockets, and it would be nice if they could both reference JST
.
You want me to submit a pull request?
Whenever I use {{outlet}} in a slimbars file I get
Unknown line indicator
(TEMPLATE), Line 4, Column 0
{{outlet}}
^
and if I use ==outlet instead I get
undefined local variable or method `outlet'
group :assets do
gem 'handlebars_assets'
end
If you do that, the rails app will not work in development mode, as handlebars.runtime is not found.
The fix is to not put the gem in the assets group.
This is with rails 3.2.9.
When using the default access method for Backbone I get a Handlebars parsing error. The following is the output from Rails.
Error: Parse error on line 13:
... <li {{#if this.get('language')}}cla
----------------------^
Expecting 'ID', got 'undefined'
This is inside an #each
helper where the object being iterated on is a standard array of Backbone models (array generated from underscore filter method).
Using this.attributes.language
outputs the correct value. Doesn't seem like the best way for this to work.
Is there a way to get Rails form helpers (or SimpleForm/ Formtastic for that matter) into the .hbs templates?
This would greatly simplify building forms, since it would take care of routing/ input id-ing etc.
Maybe this should be an opt-in feature for the erb-processor in sprockets - I'm not sure.
Not sure if this is a bug, or a limitation of how Hamlbars and Slimbars are compiled
My understanding is that file extensions .hamlbars and .slimbars first go through the HAML and SLIM templating engine, then that generated HTML w/ Handlebars markup is passed to Handlebars for precompilation.
The issue is this:
The Handlebars helpers don't work on a Haml element tag. Probably because the if logic isn't run until the template is compiled by handlebars. Since HAML compilation happens first it breaks.
Not sure on a fix.
uncaught Error: Haml::SyntaxError: Illegal nesting: nesting within plain text is illegal.
Hamlbars template
{{#if true}}
.notification-message
{{else}}
.notification-message.message-read
{{/if}}
.header
.title
{{title}}
.close
x
.content
{{content}}
%span
2 Days Ago
.details
44 Hosts Found
The docs says the generate template_name will be:
HandlebarsTemplates'contacts/new';
But I am getting:
templates/common/default_slides
templates/common/error_overlay
Which is full path. I am including using:
//= require_tree ./templates/common
Hey, I get some strange errors when using this in combination with JST. After a lot of debugging I found, that the pipeline creates code that looks e.g. like this:
Handlebars.template = Handlebars.VM.template;
;
(function() {
this.JST || (this.JST = {});
this.JST["users/_chat_message"] = <div class="message {{#user_is_yourself user}}yourself{{/user_is_yourself}}" style="background-image:url('/assets/{{user_avatar_image user "chat"}}');" title="{{created_at}}">
<div class="popover {{#user_is_yourself user}}right{{else}}left{{/user_is_yourself}}" style="display: block;">
...
So in the 4th line there is an assignment which is just missing some kind of quotes or String delimiter at all. Any ideas on why that is?
I followed structure in the readme but the JST is not available in javascript (Rails 3.1 with Ruby 1.9.2).
I tried "rake assets:precompile" and it adds Handlebars in the generated application-xxx.js
Luigi
I have justs upgraded an application to Rails 3.2.6 (previous was in 3.2.3) and I have begun to have weird problems with
my handlebars templates.
The problem is that it seems not to get data that come from nested records in the json object.
I have templates lake this:
<div data-role="content">
<h3 data-role="header">{{ customerName }}</h3>
<ul id="contacts" data-role="listview" data-inset="true">
{{#contacts}}
<li>
<h3>{{ name }}</h3>
<p>{{ job }}</p>
<p>{{ phone}} {{ mobile }}</p>
<p>{{ email }} </p>
</li>
{{/contacts}}
</ul>
</div>
I have manually check if the problem is with one of the gems that have been upgrade and found nothing.
The jason object that is generated for the templates is the same for the app with rails 2.3.2 and the app with rails 2.3.6
and I generate it with Rabl.
I have a separate .js file that gets compiled, called shared.js. If I add handlebars.runtime and require my views in that file, it won't work.
Getting this error:
undefined method `to_json' for #String:0x000001015e2188
After setting HandlebarsAssets::Config.ember = true.
in rvm/gems/ruby-1.9.3-p194/bundler/gems/handlebars_assets-7ac9c4b12a26/lib/handlebars_assets/tilt_handlebars.rb:32:in `evaluate'
Is ruby 1.8.7 supported by this gem because the linecache19 dep doesn't.
Are there workarounds to make handlebars_assets work with ruby 1.8.7?
The haml isn't turned into HTML. Handlebars_assets should support haml though, correct?
My templates are organized like this (per backbone-on-rails
, I believe):
app/
assets/
images/
javascripts/
styles/
templates/
So in my application.js, I have require_tree ../templates
. It worked fine with 0.13.0
and stopped with 0.14.0
. Apparently due to c1cea5d.
Is possible to access to the handlebars templates server side?. I mean the equivalent of poirot or stache which use mustache instead of handlebars
<%= template_include_tag 'post_list' %>
Can this be extended to support Sinatra Apps using sprockets?
Hi!
The readme states the following:
Add the template code to the HandlebarsTemplates global under the name contacts/new
But in my little project this is not the case. Maybe I do something wrong, I would really appreciate if you could take a look.
I have a simple config.ru
:
require 'sprockets'
require 'handlebars_assets'
project_root = File.expand_path(File.dirname(__FILE__))
assets = Sprockets::Environment.new(project_root) do |env|
env.logger = Logger.new(STDOUT)
end
HandlebarsAssets::Config.template_namespace = 'Ember.TEMPLATES'
assets.append_path(File.join(project_root, 'app', 'assets'))
assets.append_path(File.join(project_root, 'app', 'assets', 'javascripts'))
assets.append_path(File.join(project_root, 'app', 'assets', 'stylesheets'))
assets.append_path(File.join(project_root, 'vendor', 'assets'))
assets.append_path(File.join(project_root, 'vendor', 'assets', 'javascripts'))
assets.append_path(File.join(project_root, 'vendor', 'assets', 'stylesheets'))
assets.append_path HandlebarsAssets.path
map "/assets" do
run assets
end
map "/" do
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
end
When I require all my templates in my application.js.coffee
with #= require_tree ./templates
I get the following output:
this.Ember.TEMPLATES["javascripts/templates/application"] = ...
I would love to remove the "javascripts/templates" part from the name, is this possible?
Thanks for your time and awesome gem!
Using 0.6.6
, for some reason my templates like template.jst.hbs
are getting precompiled to template.hbs.js
. I'm actually able to access template.js
so it's getting precompiled correctly, it's just the filename is wrong. So somehow, hbs
is not getting removed from filename. Anyone know what's going on?
What's interesting is that simply template.hbs
will become template.js
properly. Does that mean it's likely a sprockets issue?
I'm getting a new error:
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-rc.3) or downgrade your runtime to an older version (<= 1.0.rc.2).
I tried changing the version to <= 1.0.rc.2 which got rid of the error but returned an empty string.
Any help would be appreciated, thanks.
I've tried several different things, but can't get my partial to be recognized by Handlebars. I'm using handlebars_assets 0.6.6 and rails 3.2.3 (although I've also tried against 3.2.8). My templates are working, just not partials. My partial is in a subdirectory named goals and is named _steps.jst.hbs. I'm trying to access it as goal_steps.
I'm getting an exception in invokePartial() of Handlebars.js that the partial can't be found. The partials array is empty.
I am using the JST namespace. I set a breakpoint in tilt_handlebars after reading another issue, and I see the call to register_partial with the correct partial name.
What else should I try?
I'm sure this is something simple but I haven't been able to figure this out quickly so it might be worth a mention in the README or docs somewhere.
How does one register a helper to be used with templates?
Thanks!
Upgrading from Rails 3.2.3 to 3.2.6 seems to cause the following error when loading pages in production
mode:
Sprockets::FileNotFound: couldn't find file 'handlebars.runtime'
With the following line in our top-level JS file:
//= require handlebars.runtime
Works fine on development
, using Sprockets v2.1.3 and handlebars_assets v0.4.4. I wonder if something about the Rails asset search path changed... anyone else seeing this?
I'm using this gem with https://github.com/codebrew/backbone-rails. For some reason I can't get it to work, exec_js dies with a cryptic error TypeError: Cannot read property 'name' of null
.
I'm not sure this error arises in this gem, but AFAIK rails-backbone doesn't use exec_js (at least it's not listed in their Gemfile), so it's likely. How do I get to the bottom of this?
I'm running this successfully on local, but when pushing to Heroku, I'm getting:
couldn't find file 'handlebars.runtime'
If I add the handlebars.runtime in my libaries, it says that HandlebarsTemplates is undefined. So it seems like the gem is not working at all.
Any tips for fixes? Running Rails 3.1.
So after some fiddling, I figured out that handlebars conditionals will work if you do this:
| {{#if something}}
h1 This works
| {{/if}}
But why not this?:
{{#if something}}
h1 This does not work
{{/if}}
The above gives me this error:
Unknown line indicator
(__TEMPLATE__), Line 1, Column 0
{{#if isNew}}
^
I don't know if this is the intended behavior or not... but it seems odd.
Hi Les, it turns out the quirks of the assets precompile stage on Heroku can make things a little tricky if you are using HandlebarsAssets to customize the compiler. I thought I'd share the findings, and maybe you could include a note in the docs to make life easier for others.
This is not a bug of any sort, just sharing info gained.
The issue is while in "development" putting the following in an initialiser or config
HandlebarsAssets::Config.options = { data: true }
works perfectly fine, but they won't compile that way on Heroku if you aren't precompiling prior to pushing, because Heroku's compile step runs prior, and usually most people have
config.assets.initialize_on_precompile = false
and HandlebarsAssets is usually in the "assets" group in Gemfile, so not available in Production
My solution is to add a form of the following:
if "assets" == ENV["RAILS_GROUPS"] || ["development", "test"].include?(ENV["RAILS_ENV"])
HandlebarsAssets::Config.options = { data: true }
end
Now assets:precompile under every scenario I've encountered compiles with the custom options. Hope this is useful.
Hi,
commit @88a2ea5 breaks things for me when using handlebars_assets without Rails. Line 13 seems to be the problem.
irb(main):001:0> defined?(Rails)
=> nil
irb(main):002:0> defined?(::Rails::Engine)
=> nil
irb(main):003:0> defined?(Rails && ::Rails::Engine)
=> "expression"
irb(main):004:0> defined?(Rails) && ::Rails::Engine
=> nil
irb(main):005:0> defined?(Rails) && defined?(::Rails::Engine)
=> nil
Notice the third case, which evaluates to true and subsequently leads to an uninitialized constant Rails
error when it does continue with require 'handlebars_assets/engine'
, which it shouldn't.
Both cases four and five work for me but I haven't tested with Rails.
Maybe I'm doing something wrong, but this is my Gemfile configuration:
group :assets do
gem 'sass-rails','~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
gem 'handlebars_assets'
gem 'execjs'
end
The problem is that neither bundle install nor bundle update install the Gems at all and not errors are thrown. Any ideas?
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.