Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3637392
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:09:10+00:00 2026-05-19T01:09:10+00:00

I feel quite excited about HAML and CoffeeScript and am working on tutorial showing

  • 0

I feel quite excited about HAML and CoffeeScript and am working on tutorial showing how to use them in non-Rails environment.
So, haml has easy to use command-line utility

haml input.haml output.html.

And, what is great, there exist a project (one of many forks: https://github.com/aussiegeek/coffee-haml-filter) aimed at providing custom filter that converts CoffeeScript into JS inside of HAML files.
Unfortunately (or am I missing something?) haml doesn’t allow specifying custom filters on the command line or with some configuration file.

I (not being a Ruby fan or even knowing it enough) managed to solve it (based on some clever suggestion somewhere on SO) with this helper script:
haml.rb

require 'rubygems'
require 'active_support/core_ext/object/blank'
require 'haml'
require 'haml/filters/coffee'

template = ARGV.length > 0 ? File.read(ARGV.shift) : STDIN.read
haml_engine = Haml::Engine.new(template)
file = ARGV.length > 0 ? File.open(ARGV.shift, 'w') : STDOUT
file.write(haml_engine.render)
file.close

Which is quite straightforward, except of requires in the beginning.

Now, the questions are:

1) should I really use it, or is there another way to have on-demand HAML to HTML compilation with custom filters?

2) What about HAML watch mode? It’s great and convenient. I can, of course, create a polling script in python that will watch the directory changes and call this .rb script, but it looks like a dirty solution.

In addition to reply by Heikki, my solution follows:
https://gist.github.com/759002

Feel free to use, if you find it useful

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:09:10+00:00Added an answer on May 19, 2026 at 1:09 am

    1) I’d say yes. (I didn’t have luck with command line options either)

    2) I got this example working with coffee script filter. File watching is done with fssm gem. It tracks changes to HAML files recursively in input folder and renders them to output folder with .html file extension.

    watch.rb:

    require 'rubygems'
    require 'fssm'
    require 'haml'
    require 'coffee-haml-filter'
    require 'active_support/core_ext/object/blank'
    
    def render(input_dir, output_dir, relative)
      input_path = File.join(input_dir, relative)
      output_path = File.join(output_dir, relative).gsub(/\.haml$/, ".html")
      haml_engine = Haml::Engine.new(File.read(input_path))
      puts "Rendering #{input_path} -> #{output_path}"
      FileUtils.makedirs(File.dirname(output_path))
      File.open(output_path, 'w') do |file|
        file.write(haml_engine.render)
      end
    end
    
    input_dir = File.expand_path(ARGV.length > 0 ? ARGV.shift : '.')
    output_dir = File.expand_path(ARGV.length > 0 ? ARGV.shift : input_dir)
    
    puts "Input folder:  '#{input_dir}'"
    puts "Output folder: '#{output_dir}'"
    
    FSSM.monitor(input_dir, '**/*.haml') do
      create {|base, relative| render(input_dir, output_dir, relative) }
      update {|base, relative| render(input_dir, output_dir, relative) }
      delete {|base, relative|
        output_path = File.join(output_dir, relative).gsub(/\.haml$/, ".html")
        puts "Deleting #{output_path}"
        File.delete(output_path)
      }
    end
    

    Usage:

    ruby watch.rb input_folder output_folder
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.