haml

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

北城以北 提交于 2019-12-03 01:05:45
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. 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 environment class Env attr_accessor :name end # Intialize it env = Env.new # Set the variable we reference

Inline ruby in :javascript haml tag? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-03 00:58:18
This question already has an answer here: Injecting variable values into javascript and HAML in RoR 2 answers 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! Arnaud Le Blanc You can use the string interpolation syntax ( #{...} ) : :javascript var tab = #{@tab} Take care of correctly escaping, however. This is a terrible way to structure code. Inline JavaScript is bad enough. Inline JavaScript with ERb inside puts you straight into hell. JavaScript should

Best way to handle data attributes in Slim

谁都会走 提交于 2019-12-03 00:54:17
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> There are multiple ways in Slim As Hash Attributes which will be hyphenated if a Hash is given (e.g. data={a:1,b:2} will render as data-a="1" data-b

conditional haml - if else nesting

笑着哭i 提交于 2019-12-02 22:46:51
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 . You can use a ternary operator to conditionally apply the style attribute: #content-inner{ :style => @transparency ? "background: url(../../../images/illustrations/" + @transparency + ") no-repeat 88% 50%" : '' } #main-block For a more complicated

How to pass an argument when calling a view file?

耗尽温柔 提交于 2019-12-02 20:29:01
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 end end If the script encounters an arror it will return a string including the word "Error". If this

how do I create a table using loops and haml with ruby?

 ̄綄美尐妖づ 提交于 2019-12-02 20:28:06
I'm trying to make an html table that looks like this: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 My data structure is like this: @f_ary = [ 1..250] Here's my haml code: %table{:border => "1"} %tbody %tr - cnt = 0 - @f_ary.each do |f| - cnt += 1 %td= cnt - if cnt == 5 - cnt = 0 %tr My current output looks like this: <table border='1'> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <tr></tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> </tr> </tbody> </table> I want it to look like this: <table border='1'> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <td>5</td> <

Conditionally setting CSS style from ruby controller

时间秒杀一切 提交于 2019-12-02 19:43:21
I'm trying to dynamically change (if it got clicked) a normal table header (which is a link) to another defined CSS class 'th.hilite'. This link simply sorts this column and the header should got highlighted every time a user sorts the list. The view where the class in question should be changed, looks like this: %table#mytable %thead %tr %th= link_to 'Title', mytable_path(:sort => 'title'), :id => 'title_header' My question is simply: How and where could I dynamically set the class to %th.hilite if the header is clicked? Be careful not to put logic (even conditionals) in your views if you can

2 Spaces or 1 Tab, what's the standard for indentation in the Rails Community?

依然范特西╮ 提交于 2019-12-02 18:49:56
I've noticed that most of the HTML/XML/HAML that gets generated from plugins uses 2 spaces instead of 1 tab. I use textmate and have tabs set to 4 spaces for HAML/HTML/XML and 2 spaces for Javascript/Ruby, but I only have to press the tab key once to get nice indentation. Pressing the space bar twice and delete twice seems like too much work :p. Do you manually type two spaces, or is some middle layer converting tabs to two spaces? Or do just a few of you use tabs? 2 spaces is generally agreed-upon. As for all the arguments about different editors showing tabs with different widths... It is a

Using AngularJS within Haml views of a Rails app

放肆的年华 提交于 2019-12-02 18:38:41
I have a Rails app with Haml views. Now I want to add AngularJS to some parts of the application, but the problem is that the Haml views are rendered server-side and the AngularJS code is not working, because it is rendered client-side. Let's say I have just this in my index.html.haml: !!! %html{"ng-app" => "Test"} %head %script{:src => "http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"} :javascript function Clock($scope) { $scope.currentTime = new Date(); } %title Welcome to AngularJS %body %h1 Hello, World. %p{"ng-controller" => "Clock"} The current time is {{currentTime |

Structuring of layout template in Haml

一世执手 提交于 2019-12-02 18:11:55
I have a web page that uses Haml for layouts. There is a separate layout file (layout.haml) which is used when rendering any actual haml page. The layout.haml looks something like -# layout.haml !!! XML !!! %html %head ... %body ... #content= yield The problem: This is of course already in the document's <body> so manipulating things in the header is not directly possible. For instance <title> is changed via @title . What is something more of a problem is the fact that every page specific Javascript needs to be loaded in the body. Moreover the layout.haml already contains Javascript, so jQuery