haml.info

Haml renders HTML with indentation reflecting the nesting level of elements. When it comes to white-space preserving content, this may become a problem: the content will be rendered including...

World Better: Without Extra Indentation Render with tilde ~ instead of equals = to keep Haml from indenting content: .nest %span Reference %pre ~ content Reference Hello World Textareas In some versions...

Haml 6 was a major rewrite with performance in mind. To achieve a performance improvement of 1.7x, some design trade-offs had to be made. The most notable change...

...might be the simplified attribute rendering. In Haml 5, attribute rendering knew two special cases: an attribute with value true would be rendered without a value, an attribute with a...

makandra dev

There are two distinct ways of commenting Haml markup: HTML and Ruby. HTML comments This will create an HTML comment that will be sent to the client (aka browser):

...cache implementation from Rails 7.0 to Rails 7.1. Unfortunately, this is incompatible with how Haml 5 patches Action View buffers. I tried turning a String buffer into an ActionView::OutputBuffer...

...up other issues. Conclusion While we have a Rails 7.2 application successfully running with Haml 5, Rails applications with fragment caching need to upgrade to Haml 6 when upgrading to...

...achieve this easily by using the lang attribute in your views (ERB): ... or in HAML: %html :xmlns => "http://www.w3.org/1999/xhtml", :"xml:lang" => I18n.locale || 'en', :lang => I18n.locale || 'en'

...look weird because of content_tags all over the place? You could also use Haml instead. Example Consider the following helper. def greeting message = ''.html_safe message << 'Welcome to '

Wouldn't it be nicer to say something like this? def greeting render_haml <<-HAML .greeting Welcome to %span.greeting--location = Rails.env HAML end It would be, and you can...

This is not an issue in newer versions of HAML (starting with 5.0.0), as the ugly-option was removed so that in development everything is rendered ugly, too.

...When HTML is rendered from HAML in production or staging environment, whitespace is removed to reduce the download size of the resulting pages. Therefore it might happen that whitespace you...

...through default file extensions, like .rb, .erb, .css, .js. When using different markup like Haml, Sass, or CoffeeScript, you need to make Rails aware of its extensions and how comments...

...Rails.application.config.annotations.tap do |notes| notes.register_extensions('scss', 'sass') { |annotation| %r(//\s*(#{annotation}):?\s*(.*?)$) } notes.register_extensions('haml') { |annotation| %r(#\s*(#{annotation}):?\s*(.*?)$) } notes.register_extensions('coffee') { |annotation| %r(#\s*(#{annotation}):?\s*(.*?)$) } end

stackoverflow.com

%p #{link_to "label", "url"}! Haml is a great engine for writing shorter, readable HTML. However, there is one thing that troubles me regularly. Consider this Haml code...

Visit our homepage at = link_to "www.makandra.com", "http://www.makandra.com" ! Haml will insert a space around the generated link, the result is this (see the space before the exclamation mark...

...might wonder how to express such a conditional comment in your favorite templating language, Haml. You might even have converted a template back to ERB just for this reason! But...

...don't worry any longer, because Haml can do conditional comments: /[if lt IE 8] %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }= 'Firefox' Sometimes you may need to insert semi-conditional HTML...

...to later select it from JavaScript or to update a fragment with an Unpoly. Haml lets you use square brackets ([]) to generate a unique class name and ID from a...

...given Ruby object. Haml will infer a class attribute from the given object's Ruby class. It will also infer an id attribute from the given object's Ruby class...

makandra dev

This is about converting Haml to ERB and not the other way round which you probably want! This process can not be automated 100%, but you can still save time...

script/plugin install http://github.com/cgoddard/haml2erb.git Then in the console type hamls = Dir["app/views/**/*.haml"] - ['app/views/layouts/screen.html.haml']; hamls.each do |haml| puts haml erb = haml.sub(/\.haml$/, '.erb') File.open(erb, 'w') do...

...that you need to use puts to pipe text into the response. From the Haml reference: All output sent to $stdout, like with puts, is output into the Haml document...

A haml angular 1 template with .thing(class="is-{{:: item.type }}") will be compiled (by haml) to which is not what you want! It will also crash in angular (unless thing...

...class instead of class .thing(ng-class='"is-{{ item.type }}"') Solution 2: Don't let haml build the class statement: %div(class="thing is-{{ item.type...

As you may know, HAML expands data attributes that are given as a hash: %div{ data: { count: 3 } } # results in: However, this also works for any other hash attribute. Consider...

...them with the directive/compiler name so it gets clear where the attribute belongs. With HAML, this is easy to build: %div{ lightbox: true, lightbox: { slide_count: 3, url: '...', cycle: true...

Haml lets you prefix a group of attributes by wrapping them in a hash. This is only possible with the {} attribute syntax, not with the () attribute syntax. Example: HTML5 data...

Haml 3.1.2 displays single quotes in FormBuilder#text_ field html escaped. You may see something like that: David&#x27;s Chapter Looking at the page's HTML, your field's...

...values will be doubly escaped: Updating Haml to 3.1.5 or newer will fix it...

nex-3.com

Sass now comes with user-defined functions, keyword arguments, list manipulation. Haml and Sass are now two separate gems...

guides.rubyonrails.org

page: text: 'Please visit our corporate website to learn more about the corporation .' # HAML = t('.text') # Desired output Please visit our corporate website to learn more about the corporation...

= t('.learn_more') = succeed '.' do %em = t('.corporation') This is annoying, especially in HAML where you need the #succeed helper to end the line with a dot.

...config.cache_classes = true config.action_view.cache_template_loading = true config.after_initialize do # only necessary if you use haml-rails ActiveSupport.on_load(:after_initialize) do ActionView::Resolver.caching = true end end # ...

Missing template pages/foo, application/foo with {:locale=>[:de], :formats=>[:json], :handlers=>[:erb, :builder, :haml]} This is because Rails tried to find a template like foo.js.erb but all it found...

Let's say we have posts with an attribute title that is mandatory. Our example feature request is to tag...

tekin.co.uk

Git diffs show the surrounding contexts for diff hunks. It does so by applying regular expressions to find the beginning...

Let's say you have a form that you render a few times but you would like to customize your...