haml

Rendering HAML partials from within HAML outside of Rails

寵の児 提交于 2019-12-18 13:21:35
问题 I'm using HAML to generate some static html pages for a site, and I was wanting to split out common components into partials that I can include in multiple pages, just like in Rails. However I don't want to use the whole Rails stack to do this as it seems like overkill. I've looked around on the Internet but haven't found anything, better than just doing something like: Haml::Engine.new(IO.read("header.haml")).render Is there a nicer way of including so-called partials from within HAML? An

Partial HAML templating in Ruby without Rails

倾然丶 夕夏残阳落幕 提交于 2019-12-18 10:49:27
问题 I really don’t need the overhead of Rails for my very small project, so I’m trying to achieve this just using just plain Ruby and HAML. I want to include another HAML file inside my HAML template. But I haven’t found a good—or really usable—way of doing this. For example, I have these two HAML files: documents.haml %html %body = include(menu.haml) body %article … menu.haml %ul %li %a whatever … Include is obviously not the way to go here. But it does a nice job describing what I’m trying to

Convert existing html.erb to Haml [closed]

空扰寡人 提交于 2019-12-18 10:15:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have a rails project, the views only consist with HTML.ERB files, my client wants to convert ERB to HAML. I have too many views file. It's taking a huge amount of time to convert file by file. So that any simply way I can convert HTML to haml? I installed haml plugin under my project. 回答1: There you go: http:/

Cocoon add association, how to limit number of associations

梦想与她 提交于 2019-12-18 04:16:31
问题 I am creating a system that stores cards using Ruby/Rails/HAML - In this case there is a Card class that has many Colours (this is also a class). When creating and editing a card I am using the Cocoon gem to allow me to dynamically add colour associations. The problem I am having is that in the Card model, a card is limited to having a maximum of 5 colours. Yet the interface allows adding of unlimited colours resulting in an error. Is there a way in Cocoon to limit the number of associations

How do I make dynamic ids in Haml?

不羁岁月 提交于 2019-12-17 21:57:46
问题 #item creates a div with id="item" .box#item creates a div with class="box" and id="item" .box#="item "+x creates a div with class="box" and a comment '#="item"+x' .box# ="item"+x throws "Illegal element: classes and ids must have values." How do I get set the id to a variable? 回答1: There are two ways: The long form way (define the id as if it were a regular attribute): .box{:id => "item_#{x}"} produces this ( x is what ever x.to_s evaluates to): <div class="box" id="item_x"> The short form

Is there a way to use a Ruby loop inside of HAML's :javascript region?

扶醉桌前 提交于 2019-12-17 19:58:32
问题 Inside of HAML, can we have a loop inside the :javascript region? This will work: - 10.upto(20) do |i| :javascript document.getElementById('aDiv').innerHTML += '#{i}'; and this will not: :javascript - 10.upto(20) do |i| document.getElementById('aDiv').innerHTML += '#{i}'; can the code above also be made to work as well? 回答1: this one works %script - 10.upto(20) do |i| document.getElementById('aDiv').innerHTML += '#{i}'; 回答2: %html %head :javascript var foo = []; #{ limit = rand(4)+3 array =

Haml::SyntaxError - Illegal nesting: content can't be both given on the same line as %a and nested within it

拟墨画扇 提交于 2019-12-17 16:28:02
问题 I'm using "Button dropdowns" from Twitter Bootstrap with HAML. In the Bootstrap docs I have found the example: <div class="btn-group"> <a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> Action <span class="caret"></span> </a> <ul class="dropdown-menu"> <!-- dropdown menu links --> </ul> </div> I have tried rewrite it using HAML: %div{:class => 'btn-group task_controller'} %a{:class => 'btn-mini dropdown-toggle', "data-toggle" => 'dropdown', :href => '#'} Action %span{:class =>

Is there a good HAML -> ERB/HTML converter?

主宰稳场 提交于 2019-12-17 16:24:02
问题 I'm looking for a reliable way to convert a HAML template to an equivalent ERB/HTML template? Has anyone come across one? 回答1: I recommend you to use HAML2ERB service. It's really cool and generates valid ERB/HTML code! The benefits are: HTTPS - if you need some security for your markup; API - you could write the plugin or something else for your IDE; Simple - just put your HAML code to the textbox and click "Convert"; Project is active - the author is currently working on it. Project was

Injecting variable values into javascript and HAML in RoR

半腔热情 提交于 2019-12-17 15:38:20
问题 I have the following function for using ZenDesk. I'd like to inject my current_user details into the form as follows. (this is my from html.haml template). However I cannot figure out how to make this work. :javascript if (typeof(Zenbox) !== "undefined") { Zenbox.init({ dropboxID: "xxxxx", url: "xxxxx.zendesk.com", tabID: "support", tabColor: "black", tabPosition: "Left", requester_name: =current_user ? "#{current_user.first_name} #{current_user.last_name}" : "" , requester_email: =current

Using layouts in HAML files independently of Rails

浪尽此生 提交于 2019-12-17 08:25:13
问题 My end goal is to create several static HTML files for hand-off to other folks. But for my workflow, I'd like to have HAML as the basic source files. In doing so, I'd hope to DRY up the process at least on my side. Now I have a lot of pages that will ultimately be sharing a common layout, and I'm wondering how to incorporate the layouts. Here's my current code: ./compile.rb #!/usr/bin/env ruby require 'rubygems' require 'rake' require 'haml' FileList.new('./src/*.html.haml').each do |filename