How can I auto compile my HAML files into HTML files in a tiny project that doesn't run on RoR?

邮差的信 提交于 2019-12-12 08:24:52

问题


I have only today started playing with compass and haml. While I am quite familiar with the way sass works and I get the idea of what compass is for sass and how to use it, I've hit a little bit of a road block when it comes to using haml efficiently.

Of course I am hoping that someone here already knows the answer to my problem and can give me a little jump start into haml.

Here is what I'd like to accomplish: Auto compile my HAML files when I save them.

The project however is just a tiny static site (couple of pages) to build up a template set for a later integration into the ExpressionEngine CMS (a php based solution).

So keeping in mind that myself using HAML to simply speed up the initial "Design to HTML/CSS" process, what is a good way to auto compile my HAML files into HTML, basically something that gives me a haml watch command that I can run on my project?

Is there even something like this out there?

As for the platform I am running on, I've got a Mac running OS X 10.6.6.

Thanks for reading, any ideas, suggestions, help would be very much appreciated.


回答1:


Thank you both @Jacob and @Jonathan, I ultimately ended up using neither of your approaches in favour of using middleman, hence the answer to my own question.

For those reading this topic having a similar question in mind, the reason I like middleman so much is that it effectively combines my entire workflow into 1 mini-server app. Using mm-ini project_name and then mm-server in the directory I instantly have access to Compass, HAML and SASS all with the option of simply outputting it to plain html at any given time.

Here is more info about middleman : http://middlemanapp.com/

Staticmatic and Nanoc also do HAML but as far as I could find out they do not 'out of the box' support Compass (SASS) compilation, which for some might be an upside but for me wasn't.

Again, thanks for your answers, here is however the answer that I ultimately chose to follow.




回答2:


If you have Ruby installed you could use the watchr gem.

With the help of a little nice script that I found here you can start a process that recognizes any changes to your haml file.

Beneath you can find my customized watchr.rb

def compile_haml
  %x[haml index.haml index.html]
end

def do_growl(message)
  growlnotify = `which growlnotify`.chomp
  title = "Watchr Message"
  passed = message.include?('0 failures, 0 errors')
  image = passed ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
  severity = passed ? "-1" : "1"
  options = "-w -n Watchr --image '#{File.expand_path(image)}'"
  options << " -m '#{message}' '#{title}' -p #{severity}"
  system %(#{growlnotify} #{options} &)
end

do_growl "Watching folders and waiting for changes..."

watch(".*\.haml$") { |x|
  compile_haml
  do_growl "Compiled HAML!"
}

If you do not have growl installed just leave that part away




回答3:


I've found StaticMatic to be really good for building static web sites in HAML.




回答4:


Maybee a bit more manual that you'd like, but you could always install the fs-events gem and do something along the lines of

require 'rb-fsevent'
require "open3"

include Open3

fsevent = FSEvent.new
fsevent.watch Dir.pwd do |directories|
  puts "Detected change inside: #{directories.inspect}"
  popen3('haml',
         '..parameters..',
         '..parameters..') do |stdin, stdout, stderr|
    stdout.read.split("\n").each do |line|
      puts line
    end
  end
end
fsevent.run

using values in the directoriesobject to call the hamlexecutable on changed files.




回答5:


Although you've apparently found what you were looking for I'll still post another approach because middleman might not be the perfect solution for everyone. My approach uses Rake. I've written a simple rakefile including a 'watch' task that recompiles my sass (or compass) and haml files whenever a file changes. Plus it reloads the browser preview :) (I don't know if middleman can do that).

The rakefile is on github: https://gist.github.com/1635301/




回答6:


Codekit is what I use, it's fantastic and handles SASS, Compass, HAML, as well as many other things.



来源:https://stackoverflow.com/questions/5649398/how-can-i-auto-compile-my-haml-files-into-html-files-in-a-tiny-project-that-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!