Haml: How to set inline style for element in HAML
It would have been handy if you’d posted the HAML you’re using, but this is how it’s done: %div.some{ :style => “position: absolute; left: 300px; top: 300px;” }
It would have been handy if you’d posted the HAML you’re using, but this is how it’s done: %div.some{ :style => “position: absolute; left: 300px; top: 300px;” }
You might be interested in SHPAML: http://shpaml.com/ I am actively maintaining it. It is a simple preprocessor, so it is not tied to any other tools like Genshi. I happen to use it with Django, so there is a little bit of Django support, but it should not interfere with most other use cases.
Haml with Rails 3 For Rails 3 all you need to do is add gem “haml”, ‘3.0.25’ to your Gemfile. No need to install plugin or run haml –rails .. Just: $ cd awesome-rails-3-app.git $ echo ‘gem “haml”‘ >> Gemfile And you’re done.
I solved it by following these steps: Make sure config.encoding = “utf-8” is in the application.rb file. Make sure you are using the ‘mysql2’ gem. Put # encoding: utf-8 at the top of file containing UTF-8 characters. Above the <App Name>::Application.initialize! line in the environment.rb file, add following two lines: Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = … Read more
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 way: .box[x] produces the following assuming x is an instance of item: <div class=”box item” id=”item_45″> See the HAML … Read more
HAML is indentation based , and the parser can be tricky.You don’t need to use “- end” in Haml. Use indentation instead.In Haml,a block begins whenever the indentation is increased after a Ruby evaluation command. It ends when the indentation decreases.Sample if else block as follows. – if condition = something – else = something_else … Read more
A better way to do this has been introduced via Haml’s helpers: surround = surround ‘(‘, ‘)’ do %a{:href => “https://stackoverflow.com/questions/1311428/food”} chicken Produces: (<a href=”https://stackoverflow.com/questions/1311428/food”>chicken</a>) succeed: click = succeed ‘.’ do %a{:href=>”https://stackoverflow.com/questions/1311428/thing”} here Produces: click <a href=”https://stackoverflow.com/questions/1311428/thing”>here</a>. precede: = precede ‘*’ do %span.small Not really Produces: *<span class=”small”>Not really</span> To answer the original question: I … Read more
Two big advantages of using slim over haml: Slim is currently about eight times faster than haml. Slim supports HTTP streaming, while HAML doesn’t. Slim has a more natural syntax: a href=”https://stackoverflow.com/questions/11390512/foo.html”
:javascript $(document).ready( function() { $(‘body’).addClass( ‘test’ ); } ); Docs: http://haml.info/docs/yardoc/file.REFERENCE.html#javascript-filter
.post{:class => (“gray” unless post.published?)}