Haml
http://haml.hamptoncatlin.com/
今天花了点时间读了遍Reference:http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html
对haml的印象彻底改变了,说句老实话,之前懒得看这个东西,一直认为它没啥意思,今天才发现,使用他,代码简洁多了,而且很容易上手,成本比较低。
!!! XML
!!!
%html
%head/
%body
#main
.articles
.article.title
Hello World
.article.date
2008-8-12 14:10:58
.article.content
Content goes here
生成如下的代码:
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head />
<body>
<div id='main'>
<div class='articles'>
<div class='article title'>
Hello World
</div>
<div class='article date'>
2008-8-12 14:10:58
</div>
<div class='article content'>
Content goes here
</div>
</div>
</div>
</body>
</html>
在haml中,我们还可以直接写textile文本,如
#main
.articles
.article.title
:redcloth
h2. Hello World
.article.date
:markdown
_2008-8-12 14:10:58_
生成
<div id='main'>
<div class='articles'>
<div class='article title'>
<h2>Hello World</h2>
</div>
<div class='article date'>
<p><em>2008-8-12 14:10:58</em></p>
</div>
</div>
</div>
资料:
http://redcloth.org/
http://www.rubyinside.com/redcloth-4-released-962.html
来个更复杂点的内容(来自Radiant的application.html.haml):
!!!
%html{html_attrs}
%head
%meta{"http-equiv"=>"Content-type", :content=>"text/html; charset=utf-8"}/
%title= @page_title || default_page_title
- @stylesheets.uniq.each do |stylesheet|
= stylesheet_link_tag stylesheet
- @javascripts.uniq.each do |javascript|
= javascript_include_tag javascript
/[if lt IE 7]
%script{:type=>"text/javascript", :src=>"/admin/javascripts/pngfix.js"}
- if @content_for_page_scripts
= javascript_tag @content_for_page_scripts
- if @content_for_page_css
%style{:type => "text/css"}= @content_for_page_css
%body
#page
#header
#site-title= link_to_unless_current title, admin_url
#site-subtitle= subtitle
- if logged_in?
#navigation= links_for_navigation
%hr{:class=>"hidden"}/
#main
- if flash[:notice]
#notice
%p= flash[:notice]
- if flash[:error]
#error
%p= flash[:error]
#content
= find_and_preserve(yield)
%hr{:class=>"hidden"}/
#footer
%p
This site was made with Ruby and is powered by
%a{:href=>"http://radiantcms.org"} Radiant CMS
version
= Radiant.loaded_via_gem? ? "#{Radiant::Version} (gem)." : "#{Radiant::Version}."
%p#site-links
- if logged_in?
- if admin?
= nav_link_to 'Users', user_index_url
%span.separator=" | "
= nav_link_to 'Extensions', extension_index_url
- else
= nav_link_to 'Preferences', user_preferences_url
%span.separator=" | "
= nav_link_to 'Log Out', logout_url
%span.separator=" | "
= link_to image('view-site.gif', :alt => "View Site", :title => ''), homepage_url
- if @content_for_popups
#popups
= yield :popups
Radius
http://radius.rubyforge.org/
Radius 是一个强大的基于标签的模板语言。
我们引用下文档中的示例:
require 'radius'
context = Radius::Context.new do |c|
c.define_tag 'hello' do
'Hello world'
end
c.define_tag 'repeat' do |tag|
number = (tag.attr['times'] || '1').to_i
result = ''
number.times { result << tag.expand }
result
end
end
在页面中,我们编写如下代码:
<radius:repeat times="3">
* <radius:hello />!
</radius:repeat>
生成
引用
* Hello world!
* Hello world!
* Hello world!
有人问,这个东西和helper不一样吗?
恩... 差不多,但是如果你的应用程序涉及到客户编码的话,那么提供这一堆tag应该还是不个不错的主意,譬如最常见的,用户自定义模板、皮肤等,现在的博客仅仅是规定死的布局和内容,无法用户完全自定义的。
分享到:
相关推荐
Haml2Html 一个易于使用的编译器,用于使用Haml&Sass开发静态页面。要求需要以下内容:安装将存储库克隆到本地计算机。 在您的终端中,导航到/haml2html 。 跑步 ./install这将检查需求并安装未安装的需求。用法将...
Haml是一个HTML的模板引擎
PHP实现的HAML模板语言类库,感兴趣的朋友们可以下载下来,用到自己的项目中。
ruby -- 在编译时使用haml gem,还有指南针 安装 安装haml & sass gem: gem install haml gem install compass 安装依赖: cd angular_c3_nvd3_crossfilter npm install bower install 测试(业力) grunt ...
前端项目-clientside-haml-js,Haml compiler for client side javascript and coffeescript view templates
NULL 博文链接:https://hlee.iteye.com/blog/602211
使用 Ryby 的最小 Http 服务器类:Haml & Coffeescript & SSE & AJAX——不到 200 行代码! 服务器将运行它自己的线程,而不会弄乱您的代码任何额外的 EventMachine 样式的依赖项。 您可以使用 AJAX 和 SSE 轻松...
用于Webpack的Ruby Haml加载程序 将Haml文件作为模块导入Webpack项目中。 返回渲染的模板。 这很慢。 它是为临时使用而创建的,直到转换为Jade。 此自述文件基于自述文件。 设置 添加到您的webpack配置模块....
将Haml与Rails一起使用要将Haml与Rails一起使用,只需将Haml添加到您的Gemfile中并运行bundle 。 gem 'haml' 如果您想用Haml替换基于Rails基于Erb的生成器,请将也添加到您的Gemfile中。格式化Haml的最基本元素是...
编写类似于ruby的haml实现的代码 在错误的标签嵌套上失败,例如table> td> tr 图书馆支持 请参阅如果您将对haml-to-php.com的支持添加到框架中,我想参考您的工作。 我知道的相关工作 请参阅此处。 最引人注目。 ...
除草剂 用Haskell编写的HAML到ERB转换器。 该程序将模板转换为 。 为什么 很多人更喜欢HAML而不是ERB。 但不是每个人,也不是每个情况都如此。...但是,使用Haskell,可以为HAML标记编写一个相当不错的解析器-翻
Yii 框架的 HAML 视图渲染器 yii-haml是扩展,它为您的视图带来了功能。 基于项目的分支。 使用 Composer 安装 将此添加到您的composer.json : " repositories " : [ { " type " : " composer " , " url " : ...
gulp-ruby-haml 这是一个,将使用该插件haml命令行脚本编译Haml的文件转换成HTML。 您需要同时安装Ruby和Haml才能使用此功能。 尝试gem install haml 。 如果使用 ,请将gem 'haml'添加到Gemfile中,然后运行bundle...
前端开源库-ewg-haml-coffee-gulpEWG HAML咖啡吞咽,EWG HAML咖啡模块
PHP实现的HAML模板语言类库
HAML.jl JuliaHTML抽象标记语言。 受启发。 建立状态测试范围概要在Julia中使用HAML的最简单方法是haml""宏的形式。 只需内联编写HAML代码,它将扩展为字符串: julia > using HAMLjulia > link = " ...
CakePHP HAML视图类 CakePHP 2.x的模板引擎。 基于 ,这是PHP的HAML实现。 安装 将插件包含在您的作曲家文件中: { " require " : { " tiutalk/haml " : " dev-master " } } 该软件包具有Composer依赖性,请...
HAML-Lint haml-lint是一种帮助保持文件清洁和可读的工具。 除了特定于 HAML 的样式和 lint 检查之外,它还与集成以将其强大的静态分析工具带到您的 HAML 文档中。 您可以从命令行手动运行haml-lint ,也可以将其...
杰基尔·哈姆尔(Jekyll Haml Markup) 插件,使成为布局,局部和页面的标记选项。 安装 添加到您的Gemfile: gem 'jekyll-haml-markup' , group : :jekyll_plugins 用法 用.haml扩展名命名布局,分页和页面。 该...
Laravel开发-laravel-blade-haml 使用Blade语法样式包装mthaml以便于在Laravel 5中使用