如何在一个不在 RoR 上运行的小项目中将 HAML 文件自动编译为 HTML 文件?
我今天才开始使用 compass
和 haml
。虽然我非常熟悉 sass
的工作方式,并且了解 compass
对于 sass
的作用以及如何使用它,但我'在有效使用 haml
方面,我们遇到了一些障碍。
当然,我希望这里有人已经知道我的问题的答案,并且可以帮助我快速入门 haml
。
这是我想要完成的任务: 保存 HAML 文件时自动编译它们。
然而,该项目只是一个很小的静态站点(几个页面),用于构建模板集,以便稍后集成到 ExpressionEngine CMS(基于 php
的解决方案)中。
因此请记住,我自己使用 HAML 只是为了加速最初的“设计为 HTML/CSS”过程,将我的 HAML 文件自动编译为 HTML 的好方法是什么,基本上可以为我提供一个 haml 手表 我可以在我的项目上运行的命令?
有没有类似的东西?
至于我运行的平台,我有一台运行 OS X 10.6.6 的 Mac。
感谢您的阅读,任何想法、建议、帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
谢谢@Jacob 和@Jonathan,我最终没有使用你们的方法,而是使用
中间人
,因此回答了我自己的问题。对于那些阅读本文的人主题有一个类似的问题,我如此喜欢
middleman
的原因是它有效地将我的整个工作流程整合到 1 个迷你服务器应用程序中。在目录中使用
mm-ini project_name
和mm-server
我可以立即访问 Compass、HAML 和 SASS,并且可以随时将其简单地输出为纯 html给定时间。以下是有关
middleman
的更多信息:http://middlemanapp.com/Staticmatic 和 Nanoc也做 HAML,但据我所知,它们并不“开箱即用”支持 Compass (SASS) 编译,这对某些人来说可能是一个好处,但对我来说却不是。
再次感谢您的回答,但这就是我最终选择遵循的答案。
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 thenmm-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.
如果您安装了 Ruby,则可以使用 watchr gem。
借助一个不错的脚本,我在这里找到了您可以启动一个进程来识别 haml 文件的任何更改。
在下面你可以找到我定制的 watchr.rb
如果你没有安装咆哮就离开那部分
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
If you do not have growl installed just leave that part away
我发现 StaticMatic 非常适合在 HAML 中构建静态网站。
I've found StaticMatic to be really good for building static web sites in HAML.
也许您需要更多的手册,但您始终可以安装 fs-events gem 并执行以下操作类似于
使用
directories
对象中的值来调用更改文件上的haml
可执行文件。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
using values in the
directories
object to call thehaml
executable on changed files.尽管您显然已经找到了所需的内容,但我仍然会发布另一种方法,因为中间人可能不是适合每个人的完美解决方案。
我的方法是使用 Rake。我编写了一个简单的 rakefile,其中包括一个“监视”任务,每当文件更改时,该任务都会重新编译我的 sass (或 compass)和 haml 文件。另外,它会重新加载浏览器预览:)(我不知道中间人是否可以做到这一点)。
rakefile 位于 github 上: https://gist.github.com/1635301/
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/
我使用的是 Codekit,它非常棒,可以处理 SASS、Compass、HAML 以及许多其他东西。
Codekit is what I use, it's fantastic and handles SASS, Compass, HAML, as well as many other things.