haml

HAML prevents template engines to render anything else than HTML

▼魔方 西西 提交于 2019-12-01 02:51:09
问题 I am using Jbuilder (and I also tried to use Rabl) to render json. When I try to render the jbuilder template in my application it renders the template within the layouts/application file and returns HTML as JSON (see line 'within layouts/application'): Rides controller on Github Started GET "/random_photo.json" Processing by RidesController#random_photo as JSON >> Rendered rides/random_photo.json.jbuilder within layouts/application (0.3ms) Rendered shared/_banners_in_corners.haml (3.0ms)

Haml syntax: split a line to a couple of rows

泄露秘密 提交于 2019-12-01 02:42:36
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 like above I get an error: "Unbalanced brackets." any help? New lines can be placed after commas,

Rails App to Angular: HAML + Rails Helpers

被刻印的时光 ゝ 提交于 2019-12-01 02:17:24
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 other page (including the ones it's linked to) were still being served server-side. Instead, I'm

Multiple multi-line HAML blocks

[亡魂溺海] 提交于 2019-11-30 17:18:51
Using the (intentionally) strange multi-line format for HAML, I'd like to have the following lines in my template: = call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', | :foo4 => 'bar4', :foo5 => 'bar5' | -# and = call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', | :foo4 => 'bar4', :foo5 => 'bar5' | However, they can not run up against one another, or they are read as one single multi-line block. -# This fails: = call_to_helper :foo1 => 'bar1', :foo2 => 'bar2', :foo3 => 'bar3', | :foo4 => 'bar4', :foo5 => 'bar5' | = call_to_helper :foo1 => 'bar1', :foo2 => 'bar2'

Mustache and Haml

扶醉桌前 提交于 2019-11-30 14:14:43
问题 I have got this haml/mustache template: {{#data}} ok {{#items}} {{#item}} %b ID: {{id}} {{/item}} {{/items}} {{/data}} And I have got Illegal nesting: nesting within plain text is illegal Error. I render it in Sinatra Mustache.render(haml(:index), hash) 回答1: I'm not sure about rendering with Sinatra, but with this command: cat example.yml foo.haml.mustache | mustache | haml -e this data file example.yml --- data: - items: - item: - id: 1 - id: 2 - id: 3 --- and template (foo.haml.mustache ):

HAML: Create container/wrapper element only if condition is true

随声附和 提交于 2019-11-30 12:41:34
Longshot, but I'm wondering if there's any way to do something like this: %p # ONLY SHOW THIS IF LOCAL VARIABLE show_paras IS TRUE = name In other words, it always shows the content inside, but it only wraps a container around it if (some-condition) is true. You could use raw html, but then you'd have to have the if statement both at the beginning and end: - if show_paras <p> = name - if show_paras </p> Assuming you're doing more than just = name , you could use a partial: - if show_paras %p= render "my_partial" - else = render "my_partial" You could also use HAML's surround (though this is a

Why does a rails app on heroku serve assets via all.css and locally via individual files

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 11:58:30
I'm a rails newbie, I've been trying to figure out what is going on with the stylesheets_link_tag on heroku. If I use = stylesheet_link_tag "style", :cache => true heroku uses "all.css" and does not pick up the stylesheet, but if I use = stylesheet_link_tag "style", :cache => false it serves the stylesheet using its name "style.css". Why? This is the result of calling :cache => true on your stylesheet link tag. :cache => true takes all of the stylesheets provided and concatenates them into one file called all.css. The reason you're only seeing this on your Heroku deployment is because it calls

Mustache and Haml

会有一股神秘感。 提交于 2019-11-30 09:54:46
I have got this haml/mustache template: {{#data}} ok {{#items}} {{#item}} %b ID: {{id}} {{/item}} {{/items}} {{/data}} And I have got Illegal nesting: nesting within plain text is illegal Error. I render it in Sinatra Mustache.render(haml(:index), hash) I'm not sure about rendering with Sinatra, but with this command: cat example.yml foo.haml.mustache | mustache | haml -e this data file example.yml --- data: - items: - item: - id: 1 - id: 2 - id: 3 --- and template (foo.haml.mustache ): {{#data}} #ok {{#items}} {{#item}} %b ID: {{id}} {{/item}} {{/items}} {{/data}} I get following result: <div

content_for vs yield in partials

夙愿已清 提交于 2019-11-30 09:07:48
In rails 3.0 with HAML (3.1.4) I have some template-like partial , like _template.html.haml: .panel.top = yield :panel_top .content = yield some another partial which will be displayed using prev template (all this stuff is rendered using AJAX, but this doesn't matter) - content_for :panel_top do .title.left = title content text and this worked like a charm in Rails 3.0 But, after upgrade to 3.2 this fails! Yiels just yields "content text", so I have "content text" twice and no title at all only changing = yield :panel_top to = content_for :panel_top works for 3.2 I am not sure that this

Haml - how do I force tag attributes to use double quotes only AND how do I order tag attributes the way I want?

一世执手 提交于 2019-11-30 06:47:09
I use staticmatic for templates I use later with PHP. There is an odd situation where some tag attributes have single quotes, while some have double quotation marks. I would like all of them to have double quotes exclusively (not that it matters I guess, but I want them like that!) For example, haml code: !!! XML %html{html_attrs('hr-HR')} %head %title Some title %meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}/ %meta{'name' => "description", :content => 'Some title - YO!'}/ = stylesheets = javascripts('test', :other) %body = yield produces following: <?xml version