haml

Using Rails 3 and Haml 3, how do I configure Haml?

ⅰ亾dé卋堺 提交于 2019-12-03 12:36:50
问题 I'm using Rails 3.0.0.beta3 and Haml 3.0.0.rc.2, and I can't find where I need to place the configuration lines for Haml (nor what they are in the new version, for that matter). Using Rails 2.3.5 and Haml 2, I would do Haml::Template.options[:format] = :html5 in environment.rb. Or, in Sinatra, set :haml, {:format => :html5} in my main file. But in Rails 3 everything's been changed around, and no matter where I put that configuration line, I get an undefined method or undefined object error.

How to add an image to the contents using HAML?

久未见 提交于 2019-12-03 10:40:29
New to this tagging language, and I'm having trouble finding documentation mentioning how to work with images. An example or two would be fantastic. Btw, I did refer to this discussion , but not sure if that's what I need. Outside any kind of framework: %img(src="/images/loading.gif") The older, more verbose but flexible syntax: %img{:src => "/images/loading.gif"} If you’re using Rails, it will generate the tag itself: =image_tag "loading.gif" 来源: https://stackoverflow.com/questions/10561121/how-to-add-an-image-to-the-contents-using-haml

Best way to handle data attributes in Slim

吃可爱长大的小学妹 提交于 2019-12-03 10:26:47
问题 I was evaluating Slim as a replacement for HAML in a personal project, and it doesn't appear to handle HTML5 data attributes as gracefully as HAML. I was hoping someone may have also run into this, or may have known about an option/syntax I haven't yet found in their docs. HAML allows you to define HTML 5 data attributes simply by using nested hashes like so: %a{data: {key1: 'val', key2: 'val'}} resulting in <a data-key1='val' data-key2='val'></a> 回答1: There are multiple ways in Slim As Hash

How to do an if/else in HAML without repeating indented code

筅森魡賤 提交于 2019-12-03 10:19:26
Depending on if a user is signed in or not, I'd like to print a different kind of %body-tag. This is how I currently do it: - if defined? @user %body(data-account="#{@user.account}") %h1 Welcome -# all my content - else %body %h1 Welcome -# all my content As you can see there's a lot of duplicated code in there. How can I eliminate this? I already tried the following: - if defined? @user %body(data-account="#{@user.account}") - else %body %h1 Welcome -# all my content Unfortunately, this doesn't work since HAML interprets it as if the %h1 and the content is part of the else-statement, which of

Rails: Is it possible to write view helpers with HAML syntax?

跟風遠走 提交于 2019-12-03 10:00:00
During refactoring it would be quite handy just to copy part of HAML template and paste it to helper's code. Currently in such cases 1) I have to rewrite that part of view from scratch 2) I have to use that verbose syntax like content_tag or haml_tag. I know that it's possible to define partials with HAML systax that will serve as helper. Though 1) as for me it's inconvinient to create a separate file for each small tiny function 2) invocation syntax for partial is quite verbose. Ideally i'd like my *_helper class to look like this: - def some_helper(*its_args) .some_class = some_ruby

Match an option in select form with boolean values

拥有回忆 提交于 2019-12-03 09:55:32
I have the following piece of code %br = f.label :active, 'Status' = f.select :active, ['Active','Inactive'] Symbol :active is a boolean type var. How can i match Active => 1/True, and Inactive => 0/False , for the database adding. Sorry for the newbie question, but i can't figure it out. You can provide a pair of values for each options: first will be used as label (inner text of <option> tag), second will be used as a value attribute: = f.select :active, [['Active', true], ['Inactive', false]] It'll render something like: <select name="model[active]"> <option value="true">Active</option>

HAML: form_tag dilemma (indentation?)

人盡茶涼 提交于 2019-12-03 09:54:02
I'm making "user settings form", and stuck with HAML: = form_tag('/') - [1,2,3].each do |i| = check_box_tag "accept#{i}" = submit_tag This results in "syntax error, unexpected kENSURE, expecting $end". The working variant is = form_tag('/') - [1,2,3].each do |i| = check_box_tag "accept#{i}" = submit_tag Results in <input id="accept1" name="accept1" type="checkbox" value="1" /> <input name="commit" type="submit" value="Save changes" /> <input id="accept2" name="accept2" type="checkbox" value="1" /> <input name="commit" type="submit" value="Save changes" /> <input id="accept3" name="accept3"

Specifying a layout and a template in a standalone (not rails) ruby app, using slim or haml

随声附和 提交于 2019-12-03 09:30:39
问题 I'm trying to do something like this in a standalone (not rails) app: layout.slim: h1 Hello .content = yield show.slim: = object.name = object.description I can't figure out how to specify a layout and a template. Is this possible with slim (or haml)? Thanks. 回答1: The layout.slim file looks like: h1 Hello .content == yield The contents.slim file looks like: = name This can be shortened, but I separated to individual steps for explanation purposes. require 'slim' # Simple class to represent an

haml with markdown claims rdiscount not found

荒凉一梦 提交于 2019-12-03 09:12:18
I've specified gem 'haml' gem 'rdiscount' in my Gemfile and ran bundle install The relevant code is .welcome-message :markdown Welcome **#{current_user.email}** When I access the page I get Can't run Markdown filter; required 'rdiscount' or 'peg_markdown' or 'maruku' or 'bluecloth', but none were found I'm using rails 3.0.5, what am I missing? Turns out I'm an idiot. All that was needed was to restart the server. Carry on everyone. 来源: https://stackoverflow.com/questions/5424504/haml-with-markdown-claims-rdiscount-not-found

conditional haml - if else nesting

放肆的年华 提交于 2019-12-03 08:48:23
问题 What I want is both whats in "if" and whats in "else" to include #main-block. - if @transparency #content-inner{:style => "background: url(../../../images/illustrations/" + @transparency + ") no-repeat 88% 50%"} - else #content-inner #main-block What happens currently is, if @transparency is defined, #main-block is not nested inside #content-inner . 回答1: You can use a ternary operator to conditionally apply the style attribute: #content-inner{ :style => @transparency ? "background: url(../../