Module: BootstrapGridSystem
- Defined in:
- lib/bootstrap_grid_system.rb,
lib/bootstrap_grid_system/version.rb
Overview
Provides a number of methods for creating a simple Bootstrap blocks
Constant Summary collapse
- VERSION =
"0.1.2"
Instance Method Summary collapse
-
#bootstrap_col(options = {}) ⇒ Object
Creates a HTML div block with bootstrap grid column class.
-
#bootstrap_row(options = {}) ⇒ Object
Creates a HTML div block with bootstrap row class.
-
#bootstrap_row_with_col(options = {}) ⇒ Object
Creates a HTML div block with bootstrap row class and HTML div block with bootstrap grid column class inside.
-
#grid_system_class(col = nil, grid_system = nil) ⇒ Object
Creates a HTML class with Bootstrap col.
-
#grid_system_offset_class(col = nil, grid_system = nil) ⇒ Object
Creates a HTML class with Bootstrap offset-col.
Instance Method Details
#bootstrap_col(options = {}) ⇒ Object
Creates a HTML div block with bootstrap grid column class.
Options
You can use only symbols for the attribute names.
:grid_system if the set value from bootstrap grid system you can chenge default value “sm” to “xs”, “sm”, “md” or “lg”. You can use string and symbols for the values
:offset_col if the set value in the range from 1 to 12 it generate bootstrap offset class in HTML div block with bootstrap grid column.
Examples
bootstrap_col(col: 6) { “Test” } # => <div class=“col-sm-6”>Test</div>
bootstrap_col(col: 6, offset_col: 4) { “Test” } # => <div class=“col-sm-6 col-sm-offset-4”>Test</div>
bootstrap_col(col: 6, class: “foo”) { “Test” } # => <div class=“col-sm-6 foo”>Test</div>
bootstrap_col(col: 6, grid_system: :lg) { “Test” } # => <div class=“col-lg-6”>Test</div>
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bootstrap_grid_system.rb', line 54 def bootstrap_col( = {}) grid_system = .delete :grid_system col = grid_system_class .delete(:col) || 12, grid_system offset_col = grid_system_offset_class .delete(:offset_col), grid_system if col || offset_col [:class] = [col, offset_col, [:class]].compact.join(" ") content_tag(:div, ) { yield } else yield end end |
#bootstrap_row(options = {}) ⇒ Object
Creates a HTML div block with bootstrap row class.
Options
You can use only symbols for the attribute names.
:row_disabled if set to true, the content will build without bootstrap row div block, it will return empty content.
Examples
bootstrap_row { “Test” } # => <div class=“row”>Test</div>
bootstrap_row(class: “foo”) { “Test” } # => <div class=“row foo”>Test</div>
bootstrap_row(row_disabled: true) { “Test” } # => Test
21 22 23 24 25 26 27 28 |
# File 'lib/bootstrap_grid_system.rb', line 21 def bootstrap_row( = {}) if .delete :row_disabled yield else [:class] = ["row", [:class]].compact.join(" ") content_tag(:div, ) { yield } end end |
#bootstrap_row_with_col(options = {}) ⇒ Object
Creates a HTML div block with bootstrap row class and HTML div block with bootstrap grid column class inside.
Options
You can use only symbols for the attribute names.
:row_disabled if set to true, it will create only HTML div block with bootstrap grid column class and without HTML div block with bootstrap row class.
Examples
bootstrap_row_with_col(col: 6) { “Test” } # => <div class=“row”>
<div class="col-sm-6">
Test
</div>
</div>
bootstrap_row_with_col(col: 6, offset_col: 4) { “Test” } # => <div class=“row”>
<div class="col-sm-6 col-sm-offset-4">
Test
</div>
</div>
bootstrap_row_with_col(col: 6, class: “foo”) { “Test” } # => <div class=“row foo”>
<div class="col-sm-6">
Test
</div>
</div>
bootstrap_row_with_col(col: 6, grid_system: :lg) { “Test” } # => <div class=“row”>
<div class="col-lg-6">
Test
</div>
</div>
103 104 105 106 |
# File 'lib/bootstrap_grid_system.rb', line 103 def bootstrap_row_with_col( = {}) col_tag = bootstrap_col(.slice(:col, :offset_col, :grid_system)) { yield } bootstrap_row(.except(:col, :offset_col, :grid_system)) { col_tag } end |
#grid_system_class(col = nil, grid_system = nil) ⇒ Object
Creates a HTML class with Bootstrap col.
110 111 112 |
# File 'lib/bootstrap_grid_system.rb', line 110 def grid_system_class(col = nil, grid_system = nil) "col-#{(grid_system || default_grid_system).to_s}-#{col}" if col end |
#grid_system_offset_class(col = nil, grid_system = nil) ⇒ Object
Creates a HTML class with Bootstrap offset-col.
116 117 118 |
# File 'lib/bootstrap_grid_system.rb', line 116 def grid_system_offset_class(col = nil, grid_system = nil) "col-#{(grid_system || default_grid_system).to_s}-offset-#{col}" if col end |