Skip to content

Instantly share code, notes, and snippets.

@hmans
Created December 10, 2012 15:45
Show Gist options
  • Save hmans/4251339 to your computer and use it in GitHub Desktop.
Save hmans/4251339 to your computer and use it in GitHub Desktop.
Why I don't like Slim

Confusing syntax

The following are equivalent:

h1 Lorem
   Ipsum

h1 
  | Lorem
  | Ipsum

h1 
  | Lorem
    Ipsum

The following works, since everything after '=' is just Ruby:

h1 = lorem_ipsum_helper

...until it contains a comment:

h1 = lorem_ipsum_helper  # this comment will break Slim

Here's an example of attributes in Slim:

h1 class="foo" Foo

The cool thing is, the bit after the '=' is really just Ruby. So the following would call a 'foo' method:

h1 class=foo Foo

Arrays work as well:

h1 class=["foo", "bar"] Foo

But don't go too crazy with Ruby, because this won't work:

h1 class=["foo"]+["bar"] Foo

Annoying whitespace handling

This will print both words without any whitespace between them:

| Foo
| Bar

This is how you append a single whitespace to some plain text:

' Foo

This is how you do it in a Ruby evaluation line:

=' foo_method

But if you just want to use an element with plain text, it's impossible. The following will not work:

span' Foo

Additional points:

  • Slim "Ugly" and Slim "Pretty" produce semantically different output (since "ugly" strips all whitespace, even between span-level elements.)
@alto
Copy link

alto commented Dec 10, 2012

Please add some notes about performance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment