Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ERB vs HAML vs SLIM - Randy Schifflin

7.1k

ERB vs HAML vs SLIM - Randy Schifflin

Las Vegas Ruby Group

July 17, 2013
Tweet

Transcript

  1. ERB vs HAML vs Slim
    by Randy Schifflin

    View Slide

  2. ERB, HAML and Slim are
    all Template Engines.
    They take some source
    template and data and
    produce a formatted
    output.
    Template Engines

    View Slide

  3. ERB (Embedded Ruby)
    ● ERB is the Ruby language's built-in template
    engine.
    ● Uses expression tags <%= ... %> and
    scriptlet tags <% ... %>
    ● Useful for embedding Ruby in any kind of
    source document, most commonly HTML
    and XML.

    View Slide

  4. ERB - The Good
    Why is ERB useful?
    ○ Familiar HTML-style syntax
    ○ Simple learning curve
    ○ Easy to figure out what a given tag is doing

    View Slide

  5. ERB - The Bad
    The problem with using ERB to write HTML is
    that it takes an already verbose syntax format
    like HTML and adds even more clutter!

    View Slide

  6. HAML (Hypertext Abstraction Markup Language)
    HAML is a template engine designed to provide
    a layer of abstraction above HTML. It uses a
    clean, concise syntax which compiles down to
    HTML and offers several usability benefits.

    View Slide

  7. HAML Features
    DRY!
    Short, easy tags
    White-space scoping
    Filters for other template engines
    Rails support
    And much more!

    View Slide

  8. HAML- The Bad
    ● Parsing is slower than ERB
    ● The syntax can be minimized further;
    attributes still require hashes, for example.

    View Slide

  9. Enter... Slim
    Slim is another lightweight templating engine.
    Inspired by HAML, Slim offers extended
    functionality with an arguably more expressive
    syntax and a quicker compilation speed.

    View Slide

  10. So... which should you choose?
    Use ERB if...
    You don't want to learn a new syntax.
    You need lightning-fast templates.
    You don't want to add additional gems
    You don't care for pretty code

    View Slide

  11. So... which should you choose?
    Otherwise, learn HAML or Slim!
    Both are excellent choices for what they do.
    HAML is generally more common.
    Slim provides better speed and extended
    functionality.
    The choice is mostly personal preference.

    View Slide

  12. Fin

    View Slide