Module: BootstrapHelper
- Defined in:
- app/helpers/bootstrap_helper.rb
Instance Method Summary collapse
-
#back_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link back button.
-
#bs_icon(icon, html_options = {}) ⇒ Object
Generates an icon.
-
#button(label = nil, html_options = nil, &block) ⇒ Object
Generates a button.
-
#cancel_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link cancel button.
-
#content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object
———— # - OVERRIDE - # ———— #.
-
#destroy_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link destroy button.
-
#edit_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link edit button.
-
#image_circle(source, html_options = {}) ⇒ Object
Generates an image tag with circle.
-
#image_responsive(source, html_options = {}) ⇒ Object
Generates a responsive-friendly image tag.
-
#image_rounded(source, html_options = {}) ⇒ Object
Generates an image tag with rounded corners.
-
#image_thumbnail(source, html_options = {}) ⇒ Object
Generates an image tag within thumbnail.
-
#link_button(label = nil, options = nil, html_options = nil, &block) ⇒ Object
Generates a link button.
- #new_button(label = nil, options = nil, html_options = {}) ⇒ Object
-
#radio_buttons_group(html_options = nil) {|radios| ... } ⇒ Object
Generates a radio buttons group.
-
#reset_button(label = nil, html_options = {}) ⇒ Object
Generates a reset button.
-
#show_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link show button.
-
#submit_button(label = nil, html_options = {}) ⇒ Object
Generates a submit button.
Instance Method Details
#back_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link back button.
83 84 85 86 87 88 |
# File 'app/helpers/bootstrap_helper.rb', line 83 def (label = nil, = nil, = {}) = { icon: 'reply' } = .update (label, , ) end |
#bs_icon(icon, html_options = {}) ⇒ Object
Generates an icon.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/bootstrap_helper.rb', line 8 def bs_icon(icon, = {}) = .symbolize_keys classes = ['glyphicon'] classes << "glyphicon-#{icon}" if [:class] classes << [:class] end [:class] = classes * ' ' if classes.present? content_tag(:span, nil, ) end |
#button(label = nil, html_options = nil, &block) ⇒ Object
Generates a button.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/helpers/bootstrap_helper.rb', line 103 def (label = nil, = nil, &block) , label = label, capture(&block) if block_given? ||= {} = .symbolize_keys = (, :button) [:type] ||= 'button' if (label_hidden = .delete(:label_hidden)) && !block_given? label = content_tag :span, label, class: "hidden-#{label_hidden}" end if (icon = .delete(:icon)) && !block_given? label = fa_icon(icon, text: label) end if [:confirm] [:'data-confirm'] = .delete(:confirm) end if [:disable_with] [:'data-disable-with'] = .delete(:disable_with) end (label, ) end |
#cancel_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link cancel button.
91 92 93 94 95 96 |
# File 'app/helpers/bootstrap_helper.rb', line 91 def (label = nil, = nil, = {}) = { icon: 'ban' } = .update (label, , ) end |
#content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object
———— #
-
OVERRIDE - #
———— #
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'app/helpers/bootstrap_helper.rb', line 266 def content_tag(name, = nil, = nil, escape = true, &block) if block_given? if .is_a?(Hash) || .nil? = ||= {} = .symbolize_keys = () end content_tag_string(name, capture(&block), , escape) else ||= {} = .symbolize_keys = () content_tag_string(name, , , escape) end end |
#destroy_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link destroy button.
75 76 77 78 79 80 |
# File 'app/helpers/bootstrap_helper.rb', line 75 def (label = nil, = nil, = {}) = { icon: 'trash', color: 'danger', method: :delete, confirm: 'Are you sure?' } = .update (label, , ) end |
#edit_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link edit button.
67 68 69 70 71 72 |
# File 'app/helpers/bootstrap_helper.rb', line 67 def (label = nil, = nil, = {}) = { icon: 'edit', color: 'warning' } = .update (label, , ) end |
#image_circle(source, html_options = {}) ⇒ Object
Generates an image tag with circle.
235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/helpers/bootstrap_helper.rb', line 235 def image_circle(source, = {}) = .symbolize_keys classes = ['img-circle'] if [:class] classes << [:class] end [:class] = classes * ' ' if classes.present? image_tag(source, ) end |
#image_responsive(source, html_options = {}) ⇒ Object
Generates a responsive-friendly image tag
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'app/helpers/bootstrap_helper.rb', line 207 def image_responsive(source, = {}) = .symbolize_keys classes = ['img-responsive'] if [:class] classes << [:class] end [:class] = classes * ' ' if classes.present? image_tag(source, ) end |
#image_rounded(source, html_options = {}) ⇒ Object
Generates an image tag with rounded corners.
221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'app/helpers/bootstrap_helper.rb', line 221 def image_rounded(source, = {}) = .symbolize_keys classes = ['img-rounded'] if [:class] classes << [:class] end [:class] = classes * ' ' if classes.present? image_tag(source, ) end |
#image_thumbnail(source, html_options = {}) ⇒ Object
Generates an image tag within thumbnail.
249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'app/helpers/bootstrap_helper.rb', line 249 def image_thumbnail(source, = {}) = .symbolize_keys classes = ['img-thumbnail'] if [:class] classes << [:class] end [:class] = classes * ' ' if classes.present? image_tag(source, ) end |
#link_button(label = nil, options = nil, html_options = nil, &block) ⇒ Object
Generates a link button.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/bootstrap_helper.rb', line 25 def (label = nil, = nil, = nil, &block) , , label = , label, capture(&block) if block_given? ||= {} = .symbolize_keys = () if (label_hidden = .delete(:label_hidden)) && !block_given? label = content_tag :span, label, class: "hidden-#{label_hidden}" end if (icon = .delete(:icon)) && !block_given? label = fa_icon(icon, text: label) end if [:confirm] [:'data-confirm'] = .delete(:confirm) end if [:disable_with] [:'data-disable-with'] = .delete(:disable_with) end link_to(label, , ) end |
#new_button(label = nil, options = nil, html_options = {}) ⇒ Object
51 52 53 54 55 56 |
# File 'app/helpers/bootstrap_helper.rb', line 51 def (label = nil, = nil, = {}) = { icon: 'plus', color: 'primary' } = .update (label, , ) end |
#radio_buttons_group(html_options = nil) {|radios| ... } ⇒ Object
Generates a radio buttons group
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/helpers/bootstrap_helper.rb', line 148 def ( = nil, &block) # Set html_options ||= {} ['data-toggle'] = 'buttons' = .symbolize_keys # Set html_options class classes = ['btn-group'] classes << [:class] if [:class] [:class] = classes * ' ' if classes.present? # Set radios options radios = [] yield radios # Set radio input name name = .delete(:name) # Set radio_items radio_items = [] radios.each do |radio| = radio.symbolize_keys label = .delete(:label) if label_hidden = .delete(:label_hidden) label = content_tag :span, label, class: "hidden-#{label_hidden}" end if icon = .delete(:icon) label = fa_icon(icon, text: label) end value = .delete(:value) radio_input = (name, value, [:active]) classes = ['btn', 'btn-default'] classes << [:class] if [:class] classes << 'active' if .delete(:active) [:class] = classes * ' ' if classes.present? radio_item = label_tag value, do radio_input + ' ' + label end radio_items << radio_item end # Set output content_tag :div, do (radio_items * '').html_safe end end |
#reset_button(label = nil, html_options = {}) ⇒ Object
Generates a reset button.
140 141 142 143 144 145 |
# File 'app/helpers/bootstrap_helper.rb', line 140 def (label = nil, = {}) = { icon: 'eraser', name: 'reset', type: 'reset' } = .update (label, ) end |
#show_button(label = nil, options = nil, html_options = {}) ⇒ Object
Generates a link show button.
59 60 61 62 63 64 |
# File 'app/helpers/bootstrap_helper.rb', line 59 def (label = nil, = nil, = {}) = { icon: 'search', color: 'info' } = .update (label, , ) end |
#submit_button(label = nil, html_options = {}) ⇒ Object
Generates a submit button.
132 133 134 135 136 137 |
# File 'app/helpers/bootstrap_helper.rb', line 132 def (label = nil, = {}) = { icon: 'check', color: 'primary', name: 'submit', type: 'submit' } = .update (label, ) end |