-
Notifications
You must be signed in to change notification settings - Fork 159
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
render templates server side for rails #46
base: master
Are you sure you want to change the base?
render templates server side for rails #46
Conversation
using ExecJS and the handlebars javascript source the handlebars templates is rendered on the server objective is to keep templates DRY. same template on the client and server
fixes #10 |
have not written any tests sorry. TODO
tried initializer 'handlebars.prepend_views_path', :after => :add_view_paths do |app|
ActionController::Base.class_eval do
before_filter do |controller|
prepend_view_path 'app/assets/javascripts/templates'
end
end
end and initializer 'handlebars.append_assets_path', :after => :append_assets_path, :group => :all do |app|
Dir[Rails.root.join("app", "views", "*")].each do |path|
app.assets.paths << path
end
end
How to you peeps share templates on the client and the server ? |
@deepak glad my code was of some help to you. A few notes though:
|
thanks @zohararad I liked the convention for I am using active_model_serializer I tried using |
Hi @deepak, Looks good, but needs at least a minimal rendering test :) |
A note from someone who was a duplicate set of erb/hbs templates: This is a killer feature. |
This would be really nice to have. |
You could actually make the ActionView Handler less concrete; but that is a matter of opinion. My changes ( #67 ) should help with this as well as asset-url and other rails helpers are able to be passed in during precompile which helps a fair bit. You should also do a conditional check to save resources + not need another required gem; otherwise 👍 I was going to write this today... If this is dead I wouldn't mind taking it over as well 😄 ^ another note I should probably add is we should be running against the precompiled templates instead of recompiling in the ActionView handling. |
Hi @AlexRiedler, That would be great! |
This is done @ http://github.com/AlexRiedler/handlebars_assets I just need to make sure everything is working ... it is quite a big change and may only make it into the release of JSAssets in the end (I need to clean it up). |
I'd love to see this feature. What's the current status? Is this PR from @deepak good, just waiting for tests? Or is the fork from @AlexRiedler furthest along? What are the missing pieces that someone could help with to see this feature in the main project? |
@turadg I have been working on it the past week or so; there is still some kinks in it that I am trying to workout. Short List (of hacks I don't like):
I believe the correct way to do this is probably give a folder e.g. "javascripts/templates"; or say everything that registered with HandlebarAssets in Sprockets should be loaded into the context. Downsides to this are on boot-up the application must precompile all the templates (which means not so great compilation errors, especially coming out of the ExecJS context).
I also am quite busy in my personal life (shit happens); I will see what I can do this week to my branch to make it a little more sane. |
👍 I hope this makes it in soon! |
Little update! I tried to use @AlexRiedler's fork as-is in my project (by directing the gem statement to that repo). It didn't work: I was getting Failing that, I tried adding @deepak's changes into my local copy of
and do this in a view,
The handlebars template will be rendered. However, I haven't been able to figure out how to pass an object rather than key value pairs like This is a really cool feature, I'd love to be able to have just one EDIT: today is the day!
where |
I might be able to get around to this relatively soon (by end of the month); I have been battling some personal issues over the last couple months and hence why the lack of movement in the project. I still would like to get this actively working though as well. I had it working with my personal branch but it did require some additional modifications to the rails setup environment (to which I can no longer remember quite perfectly); and I also ran into some issues with development environment not refreshing properly in various cases which was bothersome. |
Ready to close? :) (it's showing up in my list of open issues in which I've been mentioned) |
using ExecJS and the handlebars javascript source
the handlebars templates is rendered on the server
objective is to keep templates DRY. same template
on the client and server
stole code from https://github.com/zohararad/handlebarer/blob/master/lib/handlebarer/renderer.rb#L24-L34
to introspect locals and controller variables
no need to pass in a special
handlebars
local like https://github.com/railsware/sht_railscopied the api for https://github.com/pixeltrix/steering as well
thanks @zohararad and @pixeltrix :-)