I am currently using Yeoman with HAML (utilising grunt-contrib-haml) and would like to include HAML files to make things more DRY.
I am not that familiar with HAML, so after reading online it appears best to use =render, like so:
=render(partial="shared/ga")
however I am receiving the message that HAML lacks a native render() function:
Warning: Exception on line 75: undefined method `render' for #<Object:0x00000003474a98>
Is there a simple way to include HAML files from inside another HAML file, which will work with Yeoman/grunt-contrib-haml? and/or extending an existing HAML template to make things more DRY?
I had the same issue. I found that the simplest approach to this issue is to use js to import the files instead of the haml method. I'm using Angular.js so I can use it's imports and skip HAML's.
In the HAML template you write something like this (for Angular):
%div#publish{ng-include: 'views.someview', ng-controller: 'SomeCtrl'}
Works like a charm.
Related
I just tried to use HAML in my django project, which works fine^^
But while writing beautiful HAML code PyCharm refuse to offer any code completion or syntax highlighting for django template tags like in HTML files.
Do I need to configure PyCharm differently or is it just not possible to get the "Django Support" in HAML files with PyCharm?
Thanks in advance
I've found an older issue related to this one.
"At the moment the HAML support is part of the RubyMine code and can't be
used in other products. We have an issue for making it independent:
http://youtrack.jetbrains.net/issue/RUBY-6432"
Not sure if they managed to extract the HAML support to PyCharm or not. Their tracker is overloaded so I couldn't check it.
I have this in one of my HAML templates:
:markdown
#{render 'home.md'}
and in home.md I have:
There are **#{#photo_count}** photos.
When viewing the site, it literally outputs that. How can I get the #photo_count variable to be interpolated?
For a pure Markdown file, I don't think you'll be able to do what you want as the format itself won't support your Ruby variable.
If you don't mind changing your markdown file to a HAML partial file (no need to change its content), you could do something like this (I've used something similar to the code below using the RDiscount gem; your mileage may vary with other Markdown gems...):
app/controllers/pages_controller.rb
def home
#photo_count = 10
end
app/views/pages/home.html.haml
:markdown
#{render 'home_page'}
app/views/pages/_home_page.html.haml
There are **#{#photo_count}** photos.
See also this StackOverflow Q&A for other ideas:
How can I automatically render partials using markdown in Rails 3?
I know how to use jquery alone but since I am pretty new to Rails 3.1 I have only little idea how to integrate jquery into Rails.
So far I have come up with following steps but the first (naive) way of programing things are usually wrong :-)
datepicker plugin for jquery (e.g. jquery-ui-timepicker-addon.js) into app/assets/javascripts
add line //= jquery-ui-timepicker-addon to application.js
When I want date picker in some VIEW I will create app/assets/javascripts/VIEW.js and in there I will use standard jQuery to hook up date picker
Is there a more elegant way?
You can try this:
Add the jquery-ui .js file to the app/javascripts folder. Which you can download [here][1]
[1]: http://jqueryui.com/download. Maybe your jquery-ui-timepicker-addon.js will do as well.
You don't need to add code to application.js. As all .js files in the javascripts folder
will be included and compiled automatically
Add the following line to
app/javascripts/{viewname}.js.coffee
$ -> $('.date').datepicker()
The line above is the coffeescript equivalent of:
$("#datepicker").datepicker();
I'm trying to generate haml views with devise, but it always use erb instead. I'm running rails 3.1 & ruby 1.9.2. Rails generators (like scaffold) generates haml. I tried setting the template engine :
config.generators do |g|
g.template_engine :haml
end
But still doesn't work. If you have an idea, it is most welcomed.
Thanks for your time !
It's not possible to generate them out of the box. However, there is a short tutorial on how to convert the erb views from devise to haml layout using html2haml and a simple bash script.
That means that Devise doesn't have templates for HAML. However like #halfdan said it's pretty easy to convert with html2haml...
I'm looking for a templating engine. What are the important factors to consider when choosing among HAML, SASS/Compass and ERB?
To summarize:
Haml is a markup language
Sass is a set of CSS extensions that compile into standard CSS
Compass is a wrapper for Sass around things like Blueprint
Erb is simply HTML with embedded Ruby code.
Generally, you'll be looking at Haml or Erb (though you can mix and match them if you need to), and CSS or Sass. Compass is simply an add-on to Sass.
I'd recommend starting with Haml and Sass, as Haml takes most of the annoying, bug-prone aspects of HTML and ditches them. Once you get used to writing in Haml, using Erb feels very wordy.
As for CSS, pick a framework (such as Blueprint), and use it as-is to start. You can always add Compass on later if you feel that you need it.