haml

How to Generate Views for Devise in HAML

最后都变了- 提交于 2019-12-20 12:29:15
问题 This is mine Gemfile gem 'haml' group :development do gem 'hpricot' gem 'ruby_parser' end I then executed the following statements in a terminal/command window: bundle install rails generate devise:views users -e haml or rails generate devise:views users -t = haml But creating devise views in erb. how to fix this issue? 回答1: Even simpler solution. I have erb2haml installed in the development section of my Gemfile, so I just run: rails generate devise:views rake haml:erb2haml # or rake haml

Inline ruby in :javascript haml tag? [duplicate]

最后都变了- 提交于 2019-12-20 10:59:40
问题 This question already has answers here : Injecting variable values into javascript and HAML in RoR (2 answers) Closed 5 years ago . Hey is there a way I can do this in haml? :javascript var Tab = <%= @tab %> I could just add a helper I guess like: <script> var Tab = '<%= @tab %>' </script> But it'd be nice to use HAML! 回答1: You can use the string interpolation syntax ( #{...} ) : :javascript var tab = #{@tab} Take care of correctly escaping, however. 回答2: This is a terrible way to structure

How to insert a block every several div with haml?

我的未来我决定 提交于 2019-12-20 05:35:09
问题 I want to insert a div.row every three blocks in order to wrap three span together for the following haml snippet. But this code insert a <div class="row"></div> rather than wrap the .span4 . - data.apps.applications.each_with_index do |app, index| - if index%3 == 0 .row # This is the line I want to insert .span4 How could I do that in haml or in this case, erb is more suitable? 回答1: I think what you want is something like this: -data.apps.applications.each_slice(3) do |apps| .row -apps.each

Tilt (kramdown) preventing ERB processing when rendering markdown

只愿长相守 提交于 2019-12-20 04:51:48
问题 I am building a website with Middleman. I am storing a lot of information in data files, as I am going to use the same information on multiple pages. (Partials wouldn't work for me, as same text from data can be used with different HTML tags or be slightly modified for different pages.) I want to write markdown in data files and then use it within HAML templates for specific pages. When I try to create relative links to other pages while using a reference to other data file, resulting HTML is

Preserve attribute ordering in Haml

蹲街弑〆低调 提交于 2019-12-20 02:22:40
问题 If I create an XML element in HAML: %tag{:b => "b", :a => "a"} I get this output: <tag a="a" b="b"/> Is it possible to keep the ordering of the attributes in HAML? I need this for a client-side code to display values in certain order and don't want to pass extra information on the client just to maintain ordering. 回答1: It's not possible with HAML because it's a hash. 来源: https://stackoverflow.com/questions/7766240/preserve-attribute-ordering-in-haml

Adding bootstrap button class to button_to in rails 4

半世苍凉 提交于 2019-12-20 02:17:11
问题 I have a button_to call in my Rails 4 haml file that looks like this = button_to("Click Me", action: "click", class: "btn btn-primary") However, the class: "btn btn-primary" code snippet isn't working properly, and my button isn't changing. I've also tried the old Ruby syntax of :class => "btn btn-primary" , but that doesn't seem to do the trick. Any help would be greatly appreciated. 回答1: You need to make sure the second and third parameters to button_to are separate. Currently the action

Adding bootstrap button class to button_to in rails 4

白昼怎懂夜的黑 提交于 2019-12-20 02:17:00
问题 I have a button_to call in my Rails 4 haml file that looks like this = button_to("Click Me", action: "click", class: "btn btn-primary") However, the class: "btn btn-primary" code snippet isn't working properly, and my button isn't changing. I've also tried the old Ruby syntax of :class => "btn btn-primary" , but that doesn't seem to do the trick. Any help would be greatly appreciated. 回答1: You need to make sure the second and third parameters to button_to are separate. Currently the action

Expressing conditional HAML possibly with ternary operator

余生颓废 提交于 2019-12-19 18:21:30
问题 Trying to come up with a more compact way of expressing this conditional in HAML and Ruby, perhaps with a ternary operator: - if @page.nil? %br (nothing yet) - else %br #{@page.name} (looking for similar approach as per Neat way to conditionally test whether to add a class in HAML template) Your help would be appreciated :) 回答1: The code you have makes the text a child of the <br> element; that is not desirable. What you really meant, I think, was: %br - if @page.nil? (nothing yet) - else #{

Haml syntax: split a line to a couple of rows

爷,独闯天下 提交于 2019-12-19 05:02:35
问题 I use HAML in my rails project for my html templates. I would like to figure out if its possible to divide a very long line and make it a couple of rows: %a.open-service{href: '#', data: { service_name: service.description, balance_type: "coinsurance", total: service.a_total_billed - service.a_rejected - service.a_not_covered, discount: service} } As you can see, I just want to have an anchor with href and some data-attributes, and making it one-line won't be a pretty code. But when I do it

Rails App to Angular: HAML + Rails Helpers

妖精的绣舞 提交于 2019-12-19 04:50:36
问题 I'm trying to move my full-stack rails app over to Angular a page at a time. I'm using ui-router (https://github.com/angular-ui/ui-router) and angular-rails-templates (https://github.com/pitr/angular-rails-templates). I assumed the nghaml extension would allow me to continue to use rails helpers such as link_to, paths, etc. in my haml so just copied and pasted my haml page into the template; in an ideal world I would now be at a point where one page was being served client-side and every