Closed g10 closed 11 years ago
I am not sure I understand what's going on here, can you provide a bit more information? From your example there, it seems that it works.
The last example is the expected result, but the grunt task fails to transpile the main.haml
file. It always throws the window is not defined
error.
Should the partial.haml
be pre-transpiled with target: 'js'
perhaps, before attempting the +include 'partial'
?
I put up a basic example project: https://github.com/g10/grunt-haml-partials-test (which should work according to the usage description, but is not)
@mehcode any idea what the cause is? (or the proper usage?)
@g10 I need to apologize for my comment before. Direct rendering of the haml file to html is not actually supported by https://github.com/netzpirat/haml-coffee and is an improvement that resides in this project. It follows that since the compiler believes it is making a template function it can't know to inline the templates for partials. Something like this could be easily added to the haml-coffee project though (eg. like a --render
option). I maintain that project as well -- I'm not going to have time to add that until about Wednesday. But I'll get to it within the week.
@mehcode thanks, this would be a handy addition!
Would you consider a +render 'partial'
syntax for this, in line with =render 'partial'
used by rails and haml-contrib?
Haven't had time to get to this yet but I added an issue on haml-coffee to resolve this when I do. See https://github.com/netzpirat/haml-coffee/issues/74
Apologies if this has been resolved but I am attempting to include partials as well similar to @g10 and running into similar issues. Are there any updates to this addition?
Here as well :) Very much needed this for static site development.
Working on it right now. Apologies for the delay on this. Once https://github.com/netzpirat/haml-coffee/pull/80 gets merged in this will start working in grunt-haml. I'll push a new version with the updated haml-coffee dependeny once available.
Looks like its working now. I pushed 0.8.0
with the support.
Use as follows:
# main.haml
%h1 Main content
+include 'path/to/partial.haml'
# partial.haml
%h2 Partial content
# transpiles to main.html
<h1>Main content</h1>
<h2>Partial content</h2>
There is no inclusion context support in haml-coffee so the path is relative to your gruntfile. This is definitely an improvement to make with haml-coffee if anyone is feeling adventurous. I'll probably get to it eventually though.
just updated to 0.8.0 and test, doesnt seem to work correctly.
# index.haml
%h1 hello world
+include "includes/test.haml"
# includes/test.haml
%h2 hello world 2
# compiled to index.html
<h1>hello world</h1>+include "includes/test.haml"
Are you using language: coffee
? The default language is javascript and that doesn't have support for partials.
Check https://github.com/concordusapps/grunt-haml/blob/master/gruntfile.js#L94-L105 for an example config.
According to this comment, grunt-haml is able to include partials (using haml-coffee by adding the
language: 'coffee'
option, with the default targettarget: 'html'
).Somehow this throws the following error when executing the grunt task:
>> ReferenceError: window is not defined
Is it not possible to transpile the partial directly in the resulting main.html file?