Skip to content

Instantly share code, notes, and snippets.

@jagdeepsingh
Last active May 23, 2017 08:02
Show Gist options
  • Save jagdeepsingh/7aa5b4d97db06ba2dbf3311992639ab9 to your computer and use it in GitHub Desktop.
Save jagdeepsingh/7aa5b4d97db06ba2dbf3311992639ab9 to your computer and use it in GitHub Desktop.
Slim- Slim Framework source code

Slim

HTML elements

p Hello world
p = user.name

HTML divs can be created by simply writing:

.foo Hello world
.foo = user.name

This creates a div with class foo.

Dynamic classes

.foo class=('special' if user.special?) Hello world
.foo class=(user.special? ? 'special' : 'not-special') Hello world

HTML attributes

th colspan=4 = user.name

Data attributes

p data-bar=200
p data-bar="Hello #{user.name}"

Rails code

- if foo
  p Hello world
- else
  p Bye Bye
= render 'path/to/partial'

Javascript

javascript:
  Foo.array_field = #{raw array};
  Foo.json_field = #{hash.to_json.html_safe};
  Foo.bar();
= mobiscroll("#user_date_of_birth", :date) do
  | onChange: function(newDate, inst) {
  | $('#payment_account_date_of_birth').val(newDate);
  | }

Add comments

/!
  This is a
  multiline comment
  
  This is also a comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment