Closed dnagir closed 13 years ago
Multiple templates as a single input is out of scope for core Haml-js. You should be easily able to make a wrapper that accepts an array of [filename, body] pairs and returns a single Object.
Here is a node-based example that does something similar to what you want: https://github.com/aaronblohowiak/shared-views
The commenter on your project that said you should not have one template per file seemed to suggest that Haml was only needed to condense long views, which I heartily disagree with. No other Rails template language supports multiple template sources per file, so I would not work too hard to support that. Having one template output file for multiple source files does make sense to me, though (and for that, see shared-views.)
Unless there is something we need to do to support running Haml-js in the ruby-supported JS engines, I'm going to close this issue for now.
Thanks a lot. It all makes sense.
Cheers.
I have done some work RE integrating hamljs as a first citizen for Rails 3.1 Assets Pipeline.
And one of the suggestions I received is that templates are too small to have them in separate files. So I thought putting multiple templates into one would be useful.
But not sure how to better approach it. I probably can split it manually and compile as separate ones, but just wondering if there are better ways.
Also any feedback that would help to solve most common problem is greatly appreciated.
In two words what it does:
Precompiled HAML templates (Rails 3.1 Assets Pipeline)
Assuming you have a file
app/assets/javascripts/comment.js.hamljs
on the server with the content:When this asset is
require
-d, it will give you access to plainTemplates.comment
function allowing you to write JavaScript like:The name of the template function is derrived from the file name. If the file name is weird, you still can access it via
Templates['what ever it is!']
.