Content helpers - mateusmedeiros/sinatra-bootstrap GitHub Wiki

(Yes, I'll make this a little more readable and organized in the future, for now, at least it should have the information)

Table of Contents

Piece of history

Well, bootstrap 2 used span, but bootstrap 3 didn't, so I had to scrap at least the spanX helpers from the original code. I ended up scrapping all of them though as I wanted more than just haml support.

Helpers

Note that unlike the include helpers, these are NOT to be used based on their return value. That's because they work in blocks. Right now haml and erb are supported, but I plan to support as much template engines as possible. As these helpers are NOT to be used based on their return value, you should use <% %> and not <%= %> (or - instead of = on haml).

cols

def cols(tag, attrb = {}, &block)

Parameters

tag

tag is the tag with the cols classes (you can pass a symbol or a String, it won't make any difference).

TO-DO: make :div be the default

attrb

The options to attrb are

:cols The number of cols for the different sizes (xs, sm, md, lg)
:c A short alias for :cols
:offset The number of cols offset for the different sizes (xs, sm, md, lg)
:o A short alias for :offset
:class Any additional class you might add
:cols / :c

Pass to it a String in the format "aXXbXXcXXdXX".

The meaning of the letters are the following:

a xs
b sm
c md
d lg

XX are numbers, which should be from 1 to 12, but sinatra-bootstrap will only check if they are numbers, it won't care which number you put in there. You can (and should) ommit any letter+number you don't want to use.

:offset / :o

See :cols above. It should work the same way, except it will generate classes with "-offset"

:class

Pass to it a string with any additional classes you want to add. They should be separated by spaces, as they will just be interpolated in the tag on the end.

Other attributes

You can also add any other option to attrb hash and it will be considered an extra attribute on the tag.

Example

<% cols :div, cols: "a2b2", o: "b23d4", extr: "foobar", class: "navbar navbar-collapse" do %>
  <your code inside the div tag>
<% end %>

This will result on:

<div class="col-xs-2 col-sm-2 col-sm-offset-23 col-lg-offset-4 navbar navbar-collapse" extr="foobar">
  <your code inside the div tag>
</div>

container

def container(tag, attrb = {}, &block)

Parameters

tag

tag is the tag with the container class (you can pass a symbol or a String, it won't make any difference).

TO-DO: make :div be the default

attrb

:class

Pass to it a string with any additional classes you want to add. They should be separated by spaces, as they will just be interpolated in the tag on the end.

Other attributes

You can also add any other option to attrb hash and it will be considered an extra attribute on the tag.

Example

<% container :div, class: "extra class" extr: "attribute" do %>
  <your code inside div>
<% end %>

will result in:

<div class="container extra class" extr="attribute">
  <your code inside div>
</div>

row

def row(tag, attrb = {}, &block)

Parameters

tag

tag is the tag with the row class (you can pass a symbol or a String, it won't make any difference).

TO-DO: make :div be the default

attrb

:class

Pass to it a string with any additional classes you want to add. They should be separated by spaces, as they will just be interpolated in the tag on the end.

Other attributes

You can also add any other option to attrb hash and it will be considered an extra attribute on the tag.

Example

<% row :div, class: "extra class" extr: "attribute" do %>
  <your code inside div>
<% end %>

will result in:

<div class="row extra class" extr="attribute">
  <your code inside div>
</div>
⚠️ **GitHub.com Fallback** ⚠️