Creating a Rake Task to Convert ERB to HAML

by woody2shoes on March 18, 2011

This is a basic demonstration of adding a rake task to Ruby on Rails. Some of the same principles apply to Rake in general. You also see how to call out to the command line and how to convert ERB and HTML to HAML.

Download 51.9 MB
Download (iPod & iPhone) 30.8 MB

  • http://www.google.com/profiles/inkel.ar Leandro (inkel)

    Nice screencast, nice introduction to get into coding your own Rake tasks.

    I do have a tip, however: when you do `bundle exec html2haml #{file} | cat > {#file.gsub(…)}` piping to cat is unnecessary, you can redirect html2haml STDOUT to the new file directly. :)

    • http://teachmetocode.com Charles Max Wood

      That’s a great tip. How do you do it? I’m assuming it’s something like this:

      html2haml #{file} > /path/to/file

      If there’s another/better way, I’d love to know about it.

      • http://www.google.com/profiles/inkel.ar Leandro (inkel)

        Yeap, exactly like that. A similar thing happens with `rake /T`, if you like to see all the erb tasks you can do `rake -T erb` and it will show only those tasks.

        • http://teachmetocode.com Charles Max Wood

          Another good one to know. Thanks!

  • http://www.google.com/profiles/inkel.ar Leandro (inkel)

    Nice screencast, nice introduction to get into coding your own Rake tasks.

    I do have a tip, however: when you do `bundle exec html2haml #{file} | cat > {#file.gsub(…)}` piping to cat is unnecessary, you can redirect html2haml STDOUT to the new file directly. :)

    • http://teachmetocode.com Charles Max Wood

      That’s a great tip. How do you do it? I’m assuming it’s something like this:

      html2haml #{file} > /path/to/file

      If there’s another/better way, I’d love to know about it.

      • http://www.google.com/profiles/inkel.ar Leandro (inkel)

        Yeap, exactly like that. A similar thing happens with `rake /T`, if you like to see all the erb tasks you can do `rake -T erb` and it will show only those tasks.

        • http://teachmetocode.com Charles Max Wood

          Another good one to know. Thanks!

  • Bob Maerten

    Not so easy to do podcast recording while young kids hanging around ;-)

    • http://teachmetocode.com Charles Max Wood

      LOL, I’ve pretty much given up on having it quiet when I’m recording. Most of the time I’m happy if they’re not screaming while I’m recording.

  • http://blog.sledge.fr Bob Maerten

    Not so easy to do podcast recording while young kids hanging around ;-)

    • http://teachmetocode.com Charles Max Wood

      LOL, I’ve pretty much given up on having it quiet when I’m recording. Most of the time I’m happy if they’re not screaming while I’m recording.

  • http://www.deploymentzone.com Charles Feduke

    What, no “Ruby Haml.bundle”? Good screen cast, picked up some useful bits of information. My dogs especially liked your child[ren] in the background.

  • http://www.deploymentzone.com Charles Feduke

    What, no “Ruby Haml.bundle”? Good screen cast, picked up some useful bits of information. My dogs especially liked your child[ren] in the background.

  • http://profiles.google.com/gosha2311 Gosha Arinich

    Great screencast, man. But why not to use Dir.glob (http://ruby-doc.org/core/classes/Dir.html#M000629 ) instead of `find . -iname *.html.erb` ?

  • Anonymous

    Great screencast, man. But why not to use Dir.glob (http://ruby-doc.org/core/classes/Dir.html#M000629 ) instead of `find . -iname *.html.erb` ?

  • Pingback: Conversion of all .html.erb to .html.haml « Ruby on Rails

Previous post:

Next post: