Tag: 哈姆

在独立于Rails的HAML文件中使用布局

我的最终目标是创build几个静态的HTML文件,以供其他人使用。 但是对于我的工作stream程,我希望将HAML作为基本的源文件。 在这样做的时候,我希望至less在我身边干掉这个过程。 现在我有很多页面将最终共享一个共同的布局,我想知道如何合并布局。 这是我现在的代码: ./compile.rb #!/usr/bin/env ruby require 'rubygems' require 'rake' require 'haml' FileList.new('./src/*.html.haml').each do |filename| if filename =~ /([^\/]+)\.haml$/ File.open($1, 'w') do |f| f.write Haml::Engine.new(File.read(filename)).render end end end ./src/layout.html.haml !!! %html %head %title Yay %body = yield ./src/home.html.haml = render :layout => 'header' do %p This is awesome 现在,这显然不起作用,因为渲染方法是没有定义的Rails的上下文,但我希望它能够得到我想要做的事情。 有什么build议么?

哈默默认

有没有一种方法来configurationrails默认使用哈姆,即当一个脚手架生成时,会产生scaffold_name/index.html.haml而不是scaffold_name/index.html.erb 。 类似于您可以将config.sass.preferred_syntax = :sass添加到config/application.rb并且默认生成scaffold_name.sass 。 尝试添加以下config/application.rb config.generators do |g| g.template_engine :haml end 但与以下结果 $ rails generate scaffold foo name:string invoke active_record create db/migrate/20120208152550_create_foos.rb create app/models/foo.rb invoke test_unit create test/unit/foo_test.rb create test/fixtures/foos.yml route resources :foos invoke scaffold_controller create app/controllers/foos_controller.rb error haml [not found] invoke test_unit create test/functional/foos_controller_test.rb invoke helper create app/helpers/foos_helper.rb invoke test_unit create test/unit/helpers/foos_helper_test.rb […]

把haml标签放在link_to helper里面

是否有可能在HAML的link_to helper中添加html内容? 我试过这个,但我得到的是一个语法错误: = link_to "Other page", "path/to/page.html" %span.icon Arrow 预期产出: <a href="path/to/page.html">Other Page<span class="icon">Arrow</span></a>

Ruby HAML的空属性

我正在使用HAML在Ruby项目上实现Schema微格式,但无法弄清楚如何在标签上设置一个空属性。 我尝试了零和错误,但他们根本没有显示。 例如: <div itemscope> 我打算设置一个空的itemscope属性。 通过@StrangeElement评论添加的代码: 我的代码: .agency.premium{:itemscope => true, :itemtype => 'schema.org/ProfessionalService';} :itemscope => true似乎是HAML文档推荐的方法。 我得到和我一样的结果:itemscope => '' ,一个有空值的XHTML有效属性(即<div itemscope=""> )。 也许很好,但我宁愿把它放在Schema文档中logging的空。

如何为HAML中的元素设置内联样式

这是我的代码: <div class='some' style='position: absolute; left: 300; top: 300;'>..</div> 它只parsingstyle='position: absolute' ,并不parsing其他样式。 我怎样才能做到这一点?

HAML中的JavaScript内的Ruby方法

我有一个jQuery脚本,将一个新的字段添加到窗体,并且这个字段包含一个数组的dynamic信息。 问题是,我不知道如何添加一个array.each来填充select字段的选项,而不会打破HAML缩进并导致错误。 这是我最好的尝试,不起作用: %script(type="text/javascript") $('#mylink').click(function() { $('#mylink').after('<select> – myarray.each do |options| <option value="#{options.id}">#{options.name}</option> </select>); )}; 也尝试过与:JavaScript的filter没有运气。

如何在Rails中使用haml制作图像链接标记?

我在application.html.haml中有这样的东西: #header = image_tag("header.jpg") 例如,如何将该链接指向www.google.com? 谢谢

如何在Haml中编写if条件?

如何在Haml中为Ruby on Rails应用程序编写if和if语句?

有没有一个好的HAML – > ERB / HTML转换器?

我正在寻找一种可靠的方法将HAML模板转换为等效的ERB / HTML模板? 有没有人遇到过吗?

我如何在Haml制作dynamicID?

#item 创build一个ID为“item”的div .box#item 用class =“box”和id =“item”创build一个div .box#="item "+x 用class =“box”和注释“#=”item“+ x'创build一个div .box# ="item"+x 抛出“非法元素:类和id必须有值”。 我如何将id设置为一个variables?