tb-helpers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +3 -0
  3. data/Rakefile +36 -0
  4. data/lib/tasks/tb-helpers_tasks.rake +4 -0
  5. data/lib/tb-helpers.rb +8 -0
  6. data/lib/tb-helpers/base.rb +433 -0
  7. data/lib/tb-helpers/components.rb +112 -0
  8. data/lib/tb-helpers/railtie.rb +6 -0
  9. data/lib/tb-helpers/version.rb +3 -0
  10. data/test/dummy/README.rdoc +261 -0
  11. data/test/dummy/Rakefile +7 -0
  12. data/test/dummy/app/assets/javascripts/application.js +15 -0
  13. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  14. data/test/dummy/app/controllers/application_controller.rb +29 -0
  15. data/test/dummy/app/helpers/application_helper.rb +19 -0
  16. data/test/dummy/app/views/application/_tb_button_group.html.erb +3 -0
  17. data/test/dummy/app/views/application/_tb_form_for.html.erb +75 -0
  18. data/test/dummy/app/views/application/_tb_icon.html.erb +5 -0
  19. data/test/dummy/app/views/application/_tb_table.html.erb +11 -0
  20. data/test/dummy/app/views/application/index.html.erb +7 -0
  21. data/test/dummy/app/views/layouts/application.html.erb +22 -0
  22. data/test/dummy/config.ru +4 -0
  23. data/test/dummy/config/application.rb +59 -0
  24. data/test/dummy/config/boot.rb +10 -0
  25. data/test/dummy/config/database.yml +25 -0
  26. data/test/dummy/config/environment.rb +5 -0
  27. data/test/dummy/config/environments/development.rb +37 -0
  28. data/test/dummy/config/environments/production.rb +67 -0
  29. data/test/dummy/config/environments/test.rb +37 -0
  30. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/dummy/config/initializers/inflections.rb +15 -0
  32. data/test/dummy/config/initializers/mime_types.rb +5 -0
  33. data/test/dummy/config/initializers/secret_token.rb +7 -0
  34. data/test/dummy/config/initializers/session_store.rb +8 -0
  35. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  36. data/test/dummy/config/locales/en.yml +5 -0
  37. data/test/dummy/config/routes.rb +58 -0
  38. data/test/dummy/db/development.sqlite3 +0 -0
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/dummy/log/development.log +3568 -0
  41. data/test/dummy/log/test.log +3 -0
  42. data/test/dummy/public/404.html +26 -0
  43. data/test/dummy/public/422.html +26 -0
  44. data/test/dummy/public/500.html +25 -0
  45. data/test/dummy/public/favicon.ico +0 -0
  46. data/test/dummy/script/rails +6 -0
  47. data/test/dummy/tmp/cache/assets/CB1/250/sprockets%2Ff855a83153740f4d283850aee911ba66 +0 -0
  48. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  49. data/test/dummy/tmp/cache/assets/D0B/210/sprockets%2F0aa9423d3d5f9e53b64d393f621b93b1 +0 -0
  50. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  51. data/test/dummy/tmp/cache/assets/D38/1E0/sprockets%2F693567f5af110bb187ac31eda8ca8442 +0 -0
  52. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  53. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  54. data/test/dummy/tmp/cache/assets/DCF/A60/sprockets%2Fec92ed854ea14306cea2ff33733f9dad +0 -0
  55. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  56. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  57. data/test/tb-helpers_test.rb +7 -0
  58. data/test/test_helper.rb +15 -0
  59. metadata +190 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # tb-helpers
2
+
3
+ Twitter-Bootstrap-Helpers -- Rails 3 View-Helpers for Twitter-Bootstrap
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TB::Helpers'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+ Bundler::GemHelper.install_tasks
25
+
26
+ require 'rake/testtask'
27
+
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'lib'
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :tb-helpers do
3
+ # # Task goes here
4
+ # end
data/lib/tb-helpers.rb ADDED
@@ -0,0 +1,8 @@
1
+ module TbHelpers
2
+ end
3
+
4
+ require 'tb-helpers/base'
5
+ require 'tb-helpers/components'
6
+ require 'tb-helpers/version'
7
+
8
+ require 'tb-helpers/railtie' if defined? Rails::Railtie
@@ -0,0 +1,433 @@
1
+ module TbHelpers::Base
2
+ ALIGNMENT_CLASSES = {:left => 'text-left', :center => 'text-center', :right => 'text-right'}
3
+ EMPHASIS_CLASSES = {:success => 'text-success', :error => 'text-error', :warning => 'text-warning', :info => 'text-info', :muted => 'muted'}
4
+ TABLE_CLASSES = {:striped => 'table-striped', :bordered => 'table-bordered', :hover => 'table-hover', :condensed => 'table-condensed'}
5
+ TABLE_ROW_CLASSES = {:success => 'success', :error => 'error', :warning => 'warning', :info => 'info'}
6
+ FORM_CLASSES = {:search => 'form-search', :inline => 'form-inline', :horizontal => 'form-horizontal'}
7
+ INPUT_SIZES = {:mini => 'input-mini', :small => 'input-small', :medium => 'input-medium', :large => 'input-large', :xlarge => 'input-xlarge', :xxlarge => 'input-xxlarge'}
8
+ SPAN_SIZES = {} # span1 - span12
9
+ BUTTON_SIZES = {:mini => 'btn-mini', :small => 'btn-small', :large => 'btn-large'}
10
+
11
+ #
12
+ # essentials
13
+ #
14
+
15
+ def tb_javascript_include_tag(version=nil)
16
+ version ||= '2.3.1'
17
+ javascript_include_tag "//netdna.bootstrapcdn.com/twitter-bootstrap/#{version}/js/bootstrap.min.js"
18
+ end
19
+
20
+ def tb_stylesheet_link_tag(version=nil)
21
+ version ||= '2.3.1'
22
+ stylesheet_link_tag "//netdna.bootstrapcdn.com/twitter-bootstrap/#{version}/css/bootstrap-combined.min.css"
23
+ end
24
+
25
+ #
26
+ # typography
27
+ #
28
+
29
+ def tb_lead(content = nil, options = nil, &block)
30
+ content, options = content_or_options_with_block?(content, options, &block)
31
+ tag = delete_option_if_exists!(options, :tag, :p)
32
+ escape = delete_option_if_exists!(options, :escape, true)
33
+
34
+ classes = ['lead']
35
+ set_or_prepend_option!(options, :class, classes.join(' '))
36
+
37
+ content_tag(tag, content, options, escape)
38
+ end
39
+
40
+ def tb_emphasis(style, content = nil, options = nil, &block)
41
+ content, options = content_or_options_with_block?(content, options, &block)
42
+ tag = case style
43
+ when :small then :small
44
+ when :bold then :strong
45
+ when :italics then :em
46
+ when nil then delete_option_if_exists!(options, :tag, :span)
47
+ else raise ArgumentError.new('invalid style value')
48
+ end
49
+ escape = delete_option_if_exists!(options, :escape, true)
50
+
51
+ classes = []
52
+ EMPHASIS_CLASSES.each do |class_sym, class_name|
53
+ class_val = delete_option_if_exists!(options, class_sym, false)
54
+ classes << class_name if class_val
55
+ end
56
+ set_or_prepend_option!(options, :class, classes.join(' '))
57
+
58
+ content_tag(tag, content, options, escape)
59
+ end
60
+
61
+ def tb_small(content = nil, options = nil, &block)
62
+ tb_emphasis(:small, content, options, &block)
63
+ end
64
+
65
+ def tb_bold(content = nil, options = nil, &block)
66
+ tb_emphasis(:bold, content, options, &block)
67
+ end
68
+
69
+ def tb_italics(content = nil, options = nil, &block)
70
+ tb_emphasis(:italics, content, options, &block)
71
+ end
72
+ alias :tb_italic :tb_italics
73
+
74
+ def tb_abbreviation(content = nil, options = nil, &block)
75
+ content, options = content_or_options_with_block?(content, options, &block)
76
+ tag = delete_option_if_exists!(options, :tag, :abbr)
77
+ escape = delete_option_if_exists!(options, :escape, true)
78
+
79
+ content_tag(tag, content, options, escape)
80
+ end
81
+ alias :tb_abbr :tb_abbreviation
82
+
83
+ def tb_address(content = nil, options = nil, &block)
84
+ content, options = content_or_options_with_block?(content, options, &block)
85
+ tag = delete_option_if_exists!(options, :tag, :address)
86
+ escape = delete_option_if_exists!(options, :escape, true)
87
+
88
+ content_tag(tag, content, options, escape)
89
+ end
90
+
91
+ def tb_blockquote(content = nil, options = nil, &block)
92
+ content, options = content_or_options_with_block?(content, options, &block)
93
+ tag = delete_option_if_exists!(options, :tag, :blockquote)
94
+ escape = delete_option_if_exists!(options, :escape, true)
95
+
96
+ content_tag(tag, content, options, escape)
97
+ end
98
+
99
+ #
100
+ # code
101
+ #
102
+
103
+ def tb_code_inline(content = nil, options = nil, &block)
104
+ content, options = content_or_options_with_block?(content, options, &block)
105
+ tag = delete_option_if_exists!(options, :tag, :code)
106
+ escape = delete_option_if_exists!(options, :escape, true)
107
+
108
+ content_tag(tag, content, options, escape)
109
+ end
110
+
111
+ def tb_code_block(content = nil, options = nil, &block)
112
+ content, options = content_or_options_with_block?(content, options, &block)
113
+ tag = delete_option_if_exists!(options, :tag, :pre)
114
+ escape = delete_option_if_exists!(options, :escape, true)
115
+
116
+ classes = []
117
+ scrollable = delete_option_if_exists!(options, :scrollable, true)
118
+ classes << 'pre-scrollable' if scrollable
119
+ set_or_prepend_option!(options, :class, classes.join(' ')) unless classes.empty?
120
+
121
+ content_tag(tag, content, options, escape)
122
+ end
123
+
124
+ #
125
+ # tables
126
+ #
127
+
128
+ def tb_table(options = nil, &block)
129
+ options ||= {}
130
+ tag = delete_option_if_exists!(options, :tag, :table)
131
+ escape = delete_option_if_exists!(options, :escape, true)
132
+ caption = delete_option_if_exists!(options, :caption, nil)
133
+
134
+ classes = ['table']
135
+ TABLE_CLASSES.each do |class_sym, class_name|
136
+ class_val = delete_option_if_exists!(options, class_sym, false)
137
+ classes << class_name if class_val
138
+ end
139
+ set_or_prepend_option!(options, :class, classes.join(' '))
140
+
141
+ content_tag(tag, options, nil, escape) do
142
+ concat content_tag(:caption, caption, {}, true) if caption
143
+ concat capture(&block)
144
+ end
145
+ end
146
+
147
+ def tb_table_row(options = nil, &block)
148
+ options ||= {}
149
+ tag = delete_option_if_exists!(options, :tag, :tr)
150
+ escape = delete_option_if_exists!(options, :escape, true)
151
+
152
+ # FIXME this should be done with context option
153
+ classes = []
154
+ TABLE_ROW_CLASSES.each do |class_sym, class_name|
155
+ class_val = delete_option_if_exists!(options, class_sym, false)
156
+ classes << class_name if class_val
157
+ end
158
+ set_or_prepend_option!(options, :class, classes.join(' '))
159
+
160
+ content_tag(tag, options, nil, escape, &block)
161
+ end
162
+
163
+ #
164
+ # forms
165
+ #
166
+
167
+ def tb_form_for(*args)
168
+ raise NotImplementedError.new
169
+ end
170
+
171
+ def tb_fieldset(options = nil, &block)
172
+ options ||= {}
173
+ tag = delete_option_if_exists!(options, :tag, :fieldset)
174
+ escape = delete_option_if_exists!(options, :escape, true)
175
+ legend = delete_option_if_exists!(options, :legend, nil)
176
+
177
+ content_tag(tag, options, nil, escape) do
178
+ concat content_tag(:legend, legend, {}, true) if legend
179
+ concat capture(&block)
180
+ end
181
+ end
182
+
183
+ def tb_control_group(options = nil, &block)
184
+ options ||= {}
185
+ tag = delete_option_if_exists!(options, :tag, :div)
186
+ escape = delete_option_if_exists!(options, :escape, true)
187
+
188
+ classes = ['control-group']
189
+ context = delete_option_if_exists!(options, :context, nil)
190
+ classes << context.to_s if context
191
+
192
+ set_or_prepend_option!(options, :class, classes.join(' '))
193
+ content_tag(tag, options, nil, escape, &block)
194
+ end
195
+
196
+ def tb_controls(options = nil, &block)
197
+ options ||= {} # set_or_prepend_option!(options, :class, 'controls')
198
+ tag = delete_option_if_exists!(options, :tag, :div)
199
+ escape = delete_option_if_exists!(options, :escape, true)
200
+
201
+ classes = ['controls']
202
+ row = delete_option_if_exists!(options, :row, false)
203
+ classes << 'controls-row' if row
204
+
205
+ set_or_prepend_option!(options, :class, classes.join(' '))
206
+ content_tag(tag, options, nil, escape, &block)
207
+ end
208
+
209
+ def tb_control_label(content = nil, options = nil, &block)
210
+ content, options = content_or_options_with_block?(content, options, &block)
211
+ options = set_or_prepend_option!(options, :class, 'control-label')
212
+ tag = delete_option_if_exists!(options, :tag, :label)
213
+ escape = delete_option_if_exists!(options, :escape, true)
214
+
215
+ content_tag(tag, content, options, escape)
216
+ end
217
+
218
+ def tb_checkbox_label(options = nil, &block)
219
+ options ||= {} # set_or_prepend_option!(options, :class, 'checkbox')
220
+ tag = delete_option_if_exists!(options, :tag, :label)
221
+ escape = delete_option_if_exists!(options, :escape, true)
222
+
223
+ classes = ['checkbox']
224
+ inline = delete_option_if_exists!(options, :inline, false)
225
+ classes << 'inline' if inline
226
+
227
+ set_or_prepend_option!(options, :class, classes.join(' '))
228
+ content_tag(tag, options, nil, escape, &block)
229
+ end
230
+ alias :tb_check_box_label :tb_checkbox_label
231
+
232
+ def tb_radio_label(options = nil, &block)
233
+ options ||= {} # set_or_prepend_option!(options, :class, 'radio')
234
+ tag = delete_option_if_exists!(options, :tag, :label)
235
+ escape = delete_option_if_exists!(options, :escape, true)
236
+
237
+ classes = ['radio']
238
+ inline = delete_option_if_exists!(options, :inline, false)
239
+ classes << 'inline' if inline
240
+
241
+ set_or_prepend_option!(options, :class, classes.join(' '))
242
+ content_tag(tag, options, nil, escape, &block)
243
+ end
244
+
245
+ def tb_input_addon(style, options = nil, &block)
246
+ options = case style
247
+ when :prepend then set_or_prepend_option!(options, :class, 'input-prepend')
248
+ when :append then set_or_prepend_option!(options, :class, 'input-append')
249
+ when :combined then set_or_prepend_option!(options, :class, 'input-prepend input-append')
250
+ else raise ArgumentError.new('invalid style value')
251
+ end
252
+ tag = delete_option_if_exists!(options, :tag, :div)
253
+ escape = delete_option_if_exists!(options, :escape, true)
254
+ addon = delete_option_if_exists!(options, :addon, nil)
255
+
256
+ content_tag(tag, options, nil, escape) do
257
+ if style == :prepend || style == :combined
258
+ prepend = addon.is_a?(Array) ? addon[0] : addon
259
+ concat content_tag(:span, prepend, {:class => 'add-on'}, true) if prepend
260
+ end
261
+ concat capture(&block)
262
+ if style == :append || style == :combined
263
+ append = addon.is_a?(Array) ? addon[1] : addon
264
+ concat content_tag(:span, append, {:class => 'add-on'}, true) if append
265
+ end
266
+ end
267
+ end
268
+
269
+ def tb_input_addon_prepend(options = nil, &block)
270
+ tb_input_addon(:prepend, options, &block)
271
+ end
272
+
273
+ def tb_input_addon_append(options = nil, &block)
274
+ tb_input_addon(:append, options, &block)
275
+ end
276
+
277
+ def tb_input_addon_pre_and_append(options = nil, &block)
278
+ tb_input_addon(:combined, options, &block)
279
+ end
280
+ alias :tb_input_addon_combined :tb_input_addon_pre_and_append
281
+
282
+ def tb_input_uneditable(content = nil, options = nil, &block)
283
+ content, options = content_or_options_with_block?(content, options, &block)
284
+ tag = delete_option_if_exists!(options, :tag, :span)
285
+ escape = delete_option_if_exists!(options, :escape, true)
286
+
287
+ classes = []
288
+ size = delete_option_if_exists!(options, :size, nil)
289
+ classes << "input-#{size}" if size
290
+ classes << 'uneditable-input'
291
+
292
+ set_or_prepend_option!(options, :class, classes.join(' '))
293
+ content_tag(tag, content, options, escape)
294
+ end
295
+
296
+ def tb_form_actions(options = nil, &block)
297
+ options = set_or_prepend_option!(options, :class, 'form-actions')
298
+ tag = delete_option_if_exists!(options, :tag, :div)
299
+ escape = delete_option_if_exists!(options, :escape, true)
300
+
301
+ content_tag(tag, options, nil, escape, &block)
302
+ end
303
+
304
+ def tb_input_help(style, content = nil, options = nil, &block)
305
+ content, options = content_or_options_with_block?(content, options, &block)
306
+ tag = delete_option_if_exists!(options, :tag, :span)
307
+ escape = delete_option_if_exists!(options, :escape, true)
308
+
309
+ classes = []
310
+ classes << case style
311
+ when :inline then 'help-inline'
312
+ when :block then 'help-block'
313
+ else raise ArgumentError.new('invalid style value')
314
+ end
315
+
316
+ set_or_prepend_option!(options, :class, classes.join(' '))
317
+ content_tag(tag, content, options, escape)
318
+ end
319
+
320
+ def tb_input_help_inline(content = nil, options = nil, &block)
321
+ tb_input_help(:inline, content, options, &block)
322
+ end
323
+
324
+ def tb_input_help_block(content = nil, options = nil, &block)
325
+ tb_input_help(:block, content, options, &block)
326
+ end
327
+
328
+ #
329
+ # buttons
330
+ #
331
+
332
+ def tb_button_group(options = nil, &block)
333
+ options = set_or_prepend_option!(options, :class, 'btn-group')
334
+ tag = delete_option_if_exists!(options, :tag, :div)
335
+ escape = delete_option_if_exists!(options, :escape, true)
336
+
337
+ content_tag(tag, options, nil, escape, &block)
338
+ end
339
+
340
+ def tb_button(content = nil, options = nil, &block)
341
+ content, options = content_or_options_with_block?(content, options, &block)
342
+ tag = delete_option_if_exists!(options, :tag, :div)
343
+ escape = delete_option_if_exists!(options, :escape, true)
344
+
345
+ classes = ['btn']
346
+ context = delete_option_if_exists!(options, :context, nil)
347
+ classes << "btn-#{context}" if context
348
+ size = delete_option_if_exists!(options, :size, nil)
349
+ classes << "btn-#{size}" if size
350
+ set_or_prepend_option!(options, :class, classes.join(' '))
351
+
352
+ content_tag(tag, content, options, escape)
353
+ end
354
+ alias :tb_btn :tb_button
355
+
356
+ def tb_link_button_to(*args, &block)
357
+ if block_given?
358
+ options = args[1] ||= {}
359
+ else
360
+ options = args[2] ||= {}
361
+ end
362
+ classes = ['btn']
363
+ context = delete_option_if_exists!(options, :context, nil)
364
+ classes << "btn-#{context}" if context
365
+ size = delete_option_if_exists!(options, :size, nil)
366
+ classes << "btn-#{size}" if size
367
+ disabled = delete_option_if_exists!(options, :disabled, false)
368
+ classes << "disabled" if disabled
369
+ set_or_prepend_option!(options, :class, classes.join(' '))
370
+ link_to(*args, &block)
371
+ end
372
+ alias :tb_button_link_to :tb_link_button_to
373
+
374
+ #
375
+ # images
376
+ #
377
+
378
+ # nothing here yet
379
+
380
+ #
381
+ # icons by glyphicons
382
+ #
383
+
384
+ def tb_icon_black(name, options = nil)
385
+ icon_name = name.to_s.starts_with?('icon-') ? name.to_s : "icon-#{name}"
386
+ options = set_or_prepend_option!(options, :class, icon_name)
387
+ tag = delete_option_if_exists!(options, :tag, :i)
388
+ escape = delete_option_if_exists!(options, :escape, true)
389
+
390
+ content_tag(tag, nil, options, escape)
391
+ end
392
+ alias :tb_icon :tb_icon_black
393
+
394
+ def tb_icon_white(name, options = nil)
395
+ icon_name = name.to_s.starts_with?('icon-') ? "#{name} icon-white" : "icon-#{name} icon-white"
396
+ options = set_or_prepend_option!(options, :class, icon_name)
397
+ tag = delete_option_if_exists!(options, :tag, :i)
398
+ escape = delete_option_if_exists!(options, :escape, true)
399
+
400
+ content_tag(tag, nil, options, escape)
401
+ end
402
+
403
+ #
404
+ # protected helper methods
405
+ #
406
+
407
+ protected
408
+
409
+ def delete_option_if_exists!(options, key, fallback=nil)
410
+ options.has_key?(key) ? options.delete(key) : fallback
411
+ end
412
+
413
+ def set_or_prepend_option!(options, key, value)
414
+ options ||= {}
415
+ unless options.has_key?(:class)
416
+ options[:class] = value
417
+ else
418
+ options[:class] = "#{value} #{options[:class]}"
419
+ end
420
+ options
421
+ end
422
+
423
+ def content_or_options_with_block?(content_or_options_with_block, options, &block)
424
+ if content_or_options_with_block.is_a?(Hash)
425
+ content = capture(&block)
426
+ options = content_or_options_with_block
427
+ else
428
+ content = content_or_options_with_block
429
+ options ||= {}
430
+ end
431
+ return content, options
432
+ end
433
+ end