Module: TbHelpers::Base
- Defined in:
- lib/tb-helpers/base.rb
Constant Summary collapse
- ALIGNMENT_CLASSES =
{:left => 'text-left', :center => 'text-center', :right => 'text-right'}
- EMPHASIS_CLASSES =
{:success => 'text-success', :error => 'text-error', :warning => 'text-warning', :info => 'text-info', :muted => 'muted'}
- TABLE_CLASSES =
{:striped => 'table-striped', :bordered => 'table-bordered', :hover => 'table-hover', :condensed => 'table-condensed'}
- TABLE_ROW_CLASSES =
{:success => 'success', :error => 'error', :warning => 'warning', :info => 'info'}
- FORM_CLASSES =
{:search => 'form-search', :inline => 'form-inline', :horizontal => 'form-horizontal'}
- INPUT_SIZES =
{:mini => 'input-mini', :small => 'input-small', :medium => 'input-medium', :large => 'input-large', :xlarge => 'input-xlarge', :xxlarge => 'input-xxlarge'}
- SPAN_SIZES =
span1 - span12
{}
- BUTTON_SIZES =
{:mini => 'btn-mini', :small => 'btn-small', :large => 'btn-large'}
Instance Method Summary collapse
- #tb_abbreviation(content = nil, options = nil, &block) ⇒ Object (also: #tb_abbr)
- #tb_address(content = nil, options = nil, &block) ⇒ Object
- #tb_blockquote(content = nil, options = nil, &block) ⇒ Object
- #tb_bold(content = nil, options = nil, &block) ⇒ Object
- #tb_button(content = nil, options = nil, &block) ⇒ Object (also: #tb_btn)
-
#tb_button_group(options = nil, &block) ⇒ Object
buttons.
- #tb_checkbox_label(options = nil, &block) ⇒ Object (also: #tb_check_box_label)
- #tb_code_block(content = nil, options = nil, &block) ⇒ Object
-
#tb_code_inline(content = nil, options = nil, &block) ⇒ Object
code.
- #tb_control_group(options = nil, &block) ⇒ Object
- #tb_control_label(content = nil, options = nil, &block) ⇒ Object
- #tb_controls(options = nil, &block) ⇒ Object
- #tb_emphasis(style, content = nil, options = nil, &block) ⇒ Object
- #tb_fieldset(options = nil, &block) ⇒ Object
- #tb_form_actions(options = nil, &block) ⇒ Object
-
#tb_form_for(*args) ⇒ Object
forms.
-
#tb_icon_black(name, options = nil) ⇒ Object
(also: #tb_icon)
icons by glyphicons.
- #tb_icon_white(name, options = nil) ⇒ Object
- #tb_input_addon(style, options = nil, &block) ⇒ Object
- #tb_input_addon_append(options = nil, &block) ⇒ Object
- #tb_input_addon_pre_and_append(options = nil, &block) ⇒ Object (also: #tb_input_addon_combined)
- #tb_input_addon_prepend(options = nil, &block) ⇒ Object
- #tb_input_help(style, content = nil, options = nil, &block) ⇒ Object
- #tb_input_help_block(content = nil, options = nil, &block) ⇒ Object
- #tb_input_help_inline(content = nil, options = nil, &block) ⇒ Object
- #tb_input_uneditable(content = nil, options = nil, &block) ⇒ Object
- #tb_italics(content = nil, options = nil, &block) ⇒ Object (also: #tb_italic)
-
#tb_javascript_include_tag(version = nil) ⇒ Object
essentials.
-
#tb_lead(content = nil, options = nil, &block) ⇒ Object
typography.
- #tb_link_button_to(*args, &block) ⇒ Object (also: #tb_button_link_to)
- #tb_radio_label(options = nil, &block) ⇒ Object
- #tb_small(content = nil, options = nil, &block) ⇒ Object
- #tb_stylesheet_link_tag(version = nil) ⇒ Object
-
#tb_table(options = nil, &block) ⇒ Object
tables.
- #tb_table_row(options = nil, &block) ⇒ Object
Instance Method Details
#tb_abbreviation(content = nil, options = nil, &block) ⇒ Object Also known as: tb_abbr
74 75 76 77 78 79 80 |
# File 'lib/tb-helpers/base.rb', line 74 def tb_abbreviation(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :abbr) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, content, , escape) end |
#tb_address(content = nil, options = nil, &block) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/tb-helpers/base.rb', line 83 def tb_address(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :address) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, content, , escape) end |
#tb_blockquote(content = nil, options = nil, &block) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/tb-helpers/base.rb', line 91 def tb_blockquote(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :blockquote) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, content, , escape) end |
#tb_bold(content = nil, options = nil, &block) ⇒ Object
65 66 67 |
# File 'lib/tb-helpers/base.rb', line 65 def tb_bold(content = nil, = nil, &block) tb_emphasis(:bold, content, , &block) end |
#tb_button(content = nil, options = nil, &block) ⇒ Object Also known as: tb_btn
340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/tb-helpers/base.rb', line 340 def (content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) classes = ['btn'] context = delete_option_if_exists!(, :context, nil) classes << "btn-#{context}" if context size = delete_option_if_exists!(, :size, nil) classes << "btn-#{size}" if size set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, content, , escape) end |
#tb_button_group(options = nil, &block) ⇒ Object
buttons
332 333 334 335 336 337 338 |
# File 'lib/tb-helpers/base.rb', line 332 def ( = nil, &block) = set_or_prepend_option!(, :class, 'btn-group') tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, , nil, escape, &block) end |
#tb_checkbox_label(options = nil, &block) ⇒ Object Also known as: tb_check_box_label
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/tb-helpers/base.rb', line 218 def tb_checkbox_label( = nil, &block) ||= {} # set_or_prepend_option!(options, :class, 'checkbox') tag = delete_option_if_exists!(, :tag, :label) escape = delete_option_if_exists!(, :escape, true) classes = ['checkbox'] inline = delete_option_if_exists!(, :inline, false) classes << 'inline' if inline set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape, &block) end |
#tb_code_block(content = nil, options = nil, &block) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tb-helpers/base.rb', line 111 def tb_code_block(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :pre) escape = delete_option_if_exists!(, :escape, true) classes = [] scrollable = delete_option_if_exists!(, :scrollable, true) classes << 'pre-scrollable' if scrollable set_or_prepend_option!(, :class, classes.join(' ')) unless classes.empty? content_tag(tag, content, , escape) end |
#tb_code_inline(content = nil, options = nil, &block) ⇒ Object
code
103 104 105 106 107 108 109 |
# File 'lib/tb-helpers/base.rb', line 103 def tb_code_inline(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :code) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, content, , escape) end |
#tb_control_group(options = nil, &block) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/tb-helpers/base.rb', line 183 def tb_control_group( = nil, &block) ||= {} tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) classes = ['control-group'] context = delete_option_if_exists!(, :context, nil) classes << context.to_s if context set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape, &block) end |
#tb_control_label(content = nil, options = nil, &block) ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'lib/tb-helpers/base.rb', line 209 def tb_control_label(content = nil, = nil, &block) content, = (content, , &block) = set_or_prepend_option!(, :class, 'control-label') tag = delete_option_if_exists!(, :tag, :label) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, content, , escape) end |
#tb_controls(options = nil, &block) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/tb-helpers/base.rb', line 196 def tb_controls( = nil, &block) ||= {} # set_or_prepend_option!(options, :class, 'controls') tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) classes = ['controls'] row = delete_option_if_exists!(, :row, false) classes << 'controls-row' if row set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape, &block) end |
#tb_emphasis(style, content = nil, options = nil, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tb-helpers/base.rb', line 40 def tb_emphasis(style, content = nil, = nil, &block) content, = (content, , &block) tag = case style when :small then :small when :bold then :strong when :italics then :em when nil then delete_option_if_exists!(, :tag, :span) else raise ArgumentError.new('invalid style value') end escape = delete_option_if_exists!(, :escape, true) classes = [] EMPHASIS_CLASSES.each do |class_sym, class_name| class_val = delete_option_if_exists!(, class_sym, false) classes << class_name if class_val end set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, content, , escape) end |
#tb_fieldset(options = nil, &block) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/tb-helpers/base.rb', line 171 def tb_fieldset( = nil, &block) ||= {} tag = delete_option_if_exists!(, :tag, :fieldset) escape = delete_option_if_exists!(, :escape, true) legend = delete_option_if_exists!(, :legend, nil) content_tag(tag, , nil, escape) do concat content_tag(:legend, legend, {}, true) if legend concat capture(&block) end end |
#tb_form_actions(options = nil, &block) ⇒ Object
296 297 298 299 300 301 302 |
# File 'lib/tb-helpers/base.rb', line 296 def tb_form_actions( = nil, &block) = set_or_prepend_option!(, :class, 'form-actions') tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, , nil, escape, &block) end |
#tb_form_for(*args) ⇒ Object
forms
167 168 169 |
# File 'lib/tb-helpers/base.rb', line 167 def tb_form_for(*args) raise NotImplementedError.new end |
#tb_icon_black(name, options = nil) ⇒ Object Also known as: tb_icon
icons by glyphicons
384 385 386 387 388 389 390 391 |
# File 'lib/tb-helpers/base.rb', line 384 def tb_icon_black(name, = nil) icon_name = name.to_s.starts_with?('icon-') ? name.to_s : "icon-#{name}" = set_or_prepend_option!(, :class, icon_name) tag = delete_option_if_exists!(, :tag, :i) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, nil, , escape) end |
#tb_icon_white(name, options = nil) ⇒ Object
394 395 396 397 398 399 400 401 |
# File 'lib/tb-helpers/base.rb', line 394 def tb_icon_white(name, = nil) icon_name = name.to_s.starts_with?('icon-') ? "#{name} icon-white" : "icon-#{name} icon-white" = set_or_prepend_option!(, :class, icon_name) tag = delete_option_if_exists!(, :tag, :i) escape = delete_option_if_exists!(, :escape, true) content_tag(tag, nil, , escape) end |
#tb_input_addon(style, options = nil, &block) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/tb-helpers/base.rb', line 245 def tb_input_addon(style, = nil, &block) = case style when :prepend then set_or_prepend_option!(, :class, 'input-prepend') when :append then set_or_prepend_option!(, :class, 'input-append') when :combined then set_or_prepend_option!(, :class, 'input-prepend input-append') else raise ArgumentError.new('invalid style value') end tag = delete_option_if_exists!(, :tag, :div) escape = delete_option_if_exists!(, :escape, true) addon = delete_option_if_exists!(, :addon, nil) content_tag(tag, , nil, escape) do if style == :prepend || style == :combined prepend = addon.is_a?(Array) ? addon[0] : addon concat content_tag(:span, prepend, {:class => 'add-on'}, true) if prepend end concat capture(&block) if style == :append || style == :combined append = addon.is_a?(Array) ? addon[1] : addon concat content_tag(:span, append, {:class => 'add-on'}, true) if append end end end |
#tb_input_addon_append(options = nil, &block) ⇒ Object
273 274 275 |
# File 'lib/tb-helpers/base.rb', line 273 def tb_input_addon_append( = nil, &block) tb_input_addon(:append, , &block) end |
#tb_input_addon_pre_and_append(options = nil, &block) ⇒ Object Also known as: tb_input_addon_combined
277 278 279 |
# File 'lib/tb-helpers/base.rb', line 277 def tb_input_addon_pre_and_append( = nil, &block) tb_input_addon(:combined, , &block) end |
#tb_input_addon_prepend(options = nil, &block) ⇒ Object
269 270 271 |
# File 'lib/tb-helpers/base.rb', line 269 def tb_input_addon_prepend( = nil, &block) tb_input_addon(:prepend, , &block) end |
#tb_input_help(style, content = nil, options = nil, &block) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/tb-helpers/base.rb', line 304 def tb_input_help(style, content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :span) escape = delete_option_if_exists!(, :escape, true) classes = [] classes << case style when :inline then 'help-inline' when :block then 'help-block' else raise ArgumentError.new('invalid style value') end set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, content, , escape) end |
#tb_input_help_block(content = nil, options = nil, &block) ⇒ Object
324 325 326 |
# File 'lib/tb-helpers/base.rb', line 324 def tb_input_help_block(content = nil, = nil, &block) tb_input_help(:block, content, , &block) end |
#tb_input_help_inline(content = nil, options = nil, &block) ⇒ Object
320 321 322 |
# File 'lib/tb-helpers/base.rb', line 320 def tb_input_help_inline(content = nil, = nil, &block) tb_input_help(:inline, content, , &block) end |
#tb_input_uneditable(content = nil, options = nil, &block) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/tb-helpers/base.rb', line 282 def tb_input_uneditable(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :span) escape = delete_option_if_exists!(, :escape, true) classes = [] size = delete_option_if_exists!(, :size, nil) classes << "input-#{size}" if size classes << 'uneditable-input' set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, content, , escape) end |
#tb_italics(content = nil, options = nil, &block) ⇒ Object Also known as: tb_italic
69 70 71 |
# File 'lib/tb-helpers/base.rb', line 69 def tb_italics(content = nil, = nil, &block) tb_emphasis(:italics, content, , &block) end |
#tb_javascript_include_tag(version = nil) ⇒ Object
essentials
15 16 17 18 |
# File 'lib/tb-helpers/base.rb', line 15 def tb_javascript_include_tag(version=nil) version ||= '2.3.1' javascript_include_tag "//netdna.bootstrapcdn.com/twitter-bootstrap/#{version}/js/bootstrap.min.js" end |
#tb_lead(content = nil, options = nil, &block) ⇒ Object
typography
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tb-helpers/base.rb', line 29 def tb_lead(content = nil, = nil, &block) content, = (content, , &block) tag = delete_option_if_exists!(, :tag, :p) escape = delete_option_if_exists!(, :escape, true) classes = ['lead'] set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, content, , escape) end |
#tb_link_button_to(*args, &block) ⇒ Object Also known as:
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/tb-helpers/base.rb', line 356 def (*args, &block) if block_given? = args[1] ||= {} else = args[2] ||= {} end classes = ['btn'] context = delete_option_if_exists!(, :context, nil) classes << "btn-#{context}" if context size = delete_option_if_exists!(, :size, nil) classes << "btn-#{size}" if size disabled = delete_option_if_exists!(, :disabled, false) classes << "disabled" if disabled set_or_prepend_option!(, :class, classes.join(' ')) link_to(*args, &block) end |
#tb_radio_label(options = nil, &block) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/tb-helpers/base.rb', line 232 def tb_radio_label( = nil, &block) ||= {} # set_or_prepend_option!(options, :class, 'radio') tag = delete_option_if_exists!(, :tag, :label) escape = delete_option_if_exists!(, :escape, true) classes = ['radio'] inline = delete_option_if_exists!(, :inline, false) classes << 'inline' if inline set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape, &block) end |
#tb_small(content = nil, options = nil, &block) ⇒ Object
61 62 63 |
# File 'lib/tb-helpers/base.rb', line 61 def tb_small(content = nil, = nil, &block) tb_emphasis(:small, content, , &block) end |
#tb_stylesheet_link_tag(version = nil) ⇒ Object
20 21 22 23 |
# File 'lib/tb-helpers/base.rb', line 20 def tb_stylesheet_link_tag(version=nil) version ||= '2.3.1' stylesheet_link_tag "//netdna.bootstrapcdn.com/twitter-bootstrap/#{version}/css/bootstrap-combined.min.css" end |
#tb_table(options = nil, &block) ⇒ Object
tables
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/tb-helpers/base.rb', line 128 def tb_table( = nil, &block) ||= {} tag = delete_option_if_exists!(, :tag, :table) escape = delete_option_if_exists!(, :escape, true) = delete_option_if_exists!(, :caption, nil) classes = ['table'] TABLE_CLASSES.each do |class_sym, class_name| class_val = delete_option_if_exists!(, class_sym, false) classes << class_name if class_val end set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape) do concat content_tag(:caption, , {}, true) if concat capture(&block) end end |
#tb_table_row(options = nil, &block) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/tb-helpers/base.rb', line 147 def tb_table_row( = nil, &block) ||= {} tag = delete_option_if_exists!(, :tag, :tr) escape = delete_option_if_exists!(, :escape, true) # FIXME this should be done with context option classes = [] TABLE_ROW_CLASSES.each do |class_sym, class_name| class_val = delete_option_if_exists!(, class_sym, false) classes << class_name if class_val end set_or_prepend_option!(, :class, classes.join(' ')) content_tag(tag, , nil, escape, &block) end |