Stuck with haml patterns

I want to convert some haml files (* .html.haml) to xhtml. The haml command says: "Usage: haml [options] [INPUT] [OUTPUT]". So I tried this with the following answer:

Exception on line 1: undefined method `content_for' for #<Object:0xb730af2c> 

I noticed that there are different formats that are all called haml. I noticed one that uses angle brackets. Do I need some preprocessing?

Here is an example html.haml file that I want to convert:

 - content_for :head do = stylesheet_link_tag 'jquery.autocomplete' = javascript_include_tag 'jquery.autocomplete' - javascript_behaviour '$("input#user_full_name").autocomplete("project_roles/auto_complete_for_user_full_name")' 

Note. I know how Google is, so I am looking for specific advice.

+4
source share
2 answers

You use the rails helper, content_for, so when you call haml using the command line, it does not know what that means. So either add a haml gem to your gemfile and save the template in a .html.haml template and try rendering it or replace the content_for with the html result created by the rails.

+1
source

You would like to convert Haml to Erb, a Ruby template language that looks like HTML. Haml does not do this, so he tried to turn your haml template into xhtml instead of converting it to another template.

You could use haml2erb gem to do the conversion. It will look like this:

 Dir["**/*.haml"].each do |filename| File.open(filename.gsub(/haml$/, 'erb'),'w') do |f| f.puts Haml2Erb.convert( File.read(filename) ) end end 
0
source

All Articles