haml

Haml: If statement inside attribute declaration

耗尽温柔 提交于 2020-01-06 19:40:48
问题 I'm trying to put a conditional for a style attribute. According to this answer something like this should be possible: .hello{:style => (true ? 'color: green' : 'color: red;')} But for me the style attribute doesn't get outputted at all. Did things change in Haml? I rather not create a helper for such simple logic. 回答1: I would take the easy route out and add a line: - color = true ? 'color: green' : 'color: red;' .hello{:style => color} The even easier way is to add a further class and

HAML .each function for variables

牧云@^-^@ 提交于 2020-01-06 05:30:29
问题 I have around 30+ variables that contain an array with multiple strings inside of it. 1 variable = 1 array. I want to know if it is possible to create a new variable that will contain all the variables names, so i can loop through them. For example: These are the individual arrays: - @a = ["a","b","c","d","d"]; - @b = ["a","b","c","c","d"]; - @c = ["a","b","c","d"]; Now i want to get all the unique and duplicate strings in separate variables, like this: - @x_uniq = @a.uniq - @x_dup = @a.each

How can add a CSS class if a condition is met Angular JS

我的梦境 提交于 2020-01-04 08:03:22
问题 I'm working on creating a truncate directive and I have the string of text truncating if the characters exceed 10. It will then display the "...". My Goal is to write a condition that removes the "..." if the characters are less than 10. Kind of stuck on this and open to suggestions if anyone has any ideas on how I could accomplish this. Here is my code: var app = angular.module('myApp', []); // Controller app.controller('mainCtrl', function($scope) { $scope.text = "John Doe Blah blah"; }); /

Is it possible to have Haml indent HTML generated by a view helper in Rails?

前提是你 提交于 2020-01-03 11:57:29
问题 Say I have a things resource with a view helper method such as: module ThingsHelper def foo ret = "" 3.times { ret += content_tag(:li, "foo") } content_tag(:ul, ret) end end This, then, is used in a template: %p = foo The HTML source that's generated looks like this: <!DOCTYPE html> <html> <head> <title>Foo</title> </head> </html> <body> <p> <ul><li>foo</li><li>foo</li><li>foo</li></ul> </p> </body> As you can see, the helper output is not indented as the rest of the code. Any way to remedy

Rails 3 not loading HAML handler

懵懂的女人 提交于 2020-01-03 10:22:04
问题 I'm having some problems with Rails 3 and HAML in my application: for some reason Rails appears not to be loading the handler for dealing with haml files. Every action gives an error message similar to this one: Template is missing Missing template contact_search/index with {:formats=>[:html], :handlers=>[:rjs, :rhtml, :rxml, :builder, :erb], :locale=>[:en, :en]} in view paths "/var/www/osphonebook/app/views", "/var/www/osphonebook/vendor/bundle/ruby/1.8/gems/devise-1.3.4/app/views" Look at

HAML: Indenting if/else statements with common content

别说谁变了你拦得住时间么 提交于 2020-01-03 09:58:17
问题 I have the following in my view: - if (condition) %div.truecondition (Ten lines of content) - else %div.falsecondition (Ten lines of the same content) I'd like to factor out the ten lines of content to go below the if/else statement...but if I do that, indentation means the content won't be nested inside the div specified in the if/else. I'm sure this is a common problem, I'm just wondering what the solution is. So...how do I factor out that ten lines while keeping the content nested in the

Specify options for a filter in ruby HAML

﹥>﹥吖頭↗ 提交于 2020-01-02 03:01:10
问题 Is there any way to add options (HTML attributes) to HAML filters? I wanted to do something like this : :javascript{:'data-turbolinks-eval' => 'false', :foo => 'bar'} if(someCondition){ doSomething(); } And the result would be : <script 'data-turbolinks-eval'='false' 'foo'='bar'> if(someCondition){ doSomething(); } </script> The closest I could get is : %script{:'data-turbolinks-eval' => 'false', :foo => 'bar'} if(someCondition){ doSomething(); } The drawback is that you can't indent your JS

Rails 3.2 - haml vs. erb. Is haml faster? (february 2012)

▼魔方 西西 提交于 2020-01-02 00:52:14
问题 I am working on a project and I am still thinking about using HAML (beautiful code, less size of view files) instead of classic ERB template. My worries why I didn't do it yet are the speed of generating views - I read an articles/benchmarks and there was almost always HAML slower than ERB - but the truth is, that the articles are 2-3 years old. So my question is, how looks the comparison these two template systems now, in the start of 2012? 回答1: Here are some benchmarks from someone in Nov

HAML: form_tag dilemma (indentation?)

走远了吗. 提交于 2020-01-01 03:59:27
问题 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=

How to pass an argument when calling a view file?

柔情痞子 提交于 2019-12-31 12:07:26
问题 I wrote a webform using Sinatra and Haml that will be used to call a Ruby script. Everything seems fine except for one thing: I need to pass an argument to a Haml view file from the Sinatra/Ruby script. Here is a part of my code: #!/usr/bin/env ruby require 'rubygems' require 'sinatra' require 'haml' get '/' do haml :index end post '/' do name = params[:name] vlan = params[:vlan] tmp = nil tmp = %x[./wco-hosts.rb -a -n #{name} -v #{vlan}] if tmp.include?("Error") haml :fail else haml :success