Slim is much simpler than erb !

I learned about the slim templating language from the Rails Style Guide on GitHub. I found slim extremely easy to set up – just added it to my gemfile, and started making new view files using the .html.slim ending rather than the .html.erb ending.

Slim is a lot less cluttered than erb is. Using slim, I simplified and cleaned up some templates that used to look like this in erb:

  <table class="table">
    <thead>
      <tr>
        <th>Mission</th>
        <th>Client</th>
        <th>Service date(s)</th>
        <th>Vendor</th>
        <th>Factory</th>
        <th>Service</th>
        <th>Items</th>
      </tr>
    </thead>

    <tbody>
      <% @send_asi_missions.each do |m| %>
        <tr>
          <td><%= link_to "INT#{m.id}", '#' %></td>
          <td><%= m.client.english_name %></td>
          <td><%= m.active_bookings.map(&:booked_date).sort.join ', ' %></td>
          <td><%= m.vendors.map(&:english_name).sort.join ', ' %></td>
          <td><%= m.factories.map(&:english_name).sort.join ', ' %></td>
          <td><%= m.services.uniq.map(&:abbreviation).sort.join ', ' %></td>
          <td><%= m.items.count %></td>
        </tr>
      <% end %>
    </tbody>
  </table>

so that they now look this this in slim:

  table.table

    thead
      tr
        th Mission
        th Client
        th Service date(s)
        th Vendor
        th Factory
        th Service
        th Items

    tbody
      - @send_asi_missions.each do |m|
        tr
          td = link_to "INT#{m.id}", '#'
          td = m.client.english_name
          td = m.active_bookings.map(&:booked_date).sort.join ', '
          td = m.vendors.map(&:english_name).sort.join ', '
          td = m.factories.map(&:english_name).sort.join ', '
          td = m.services.uniq.map(&:abbreviation).sort.join ', '
          td = m.items.count
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s