rails-bootstrap-helpers 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/README.md +336 -14
  2. data/lib/rails-bootstrap-helpers.rb +14 -3
  3. data/lib/rails-bootstrap-helpers/helpers/accordion_helper.rb +8 -0
  4. data/lib/rails-bootstrap-helpers/helpers/alert_helper.rb +24 -14
  5. data/lib/rails-bootstrap-helpers/helpers/base_helper.rb +25 -13
  6. data/lib/rails-bootstrap-helpers/helpers/button_helper.rb +85 -13
  7. data/lib/rails-bootstrap-helpers/helpers/form_tag_helper.rb +42 -10
  8. data/lib/rails-bootstrap-helpers/helpers/navigation_helper.rb +17 -0
  9. data/lib/rails-bootstrap-helpers/helpers/options_helper.rb +24 -3
  10. data/lib/rails-bootstrap-helpers/helpers/tag_helper.rb +26 -0
  11. data/lib/rails-bootstrap-helpers/helpers/url_helper.rb +17 -0
  12. data/lib/rails-bootstrap-helpers/rails/engine.rb +4 -2
  13. data/lib/rails-bootstrap-helpers/renderers/{abstract_button_renderer.rb → abstract_link_renderer.rb} +23 -7
  14. data/lib/rails-bootstrap-helpers/renderers/accordion_renderer.rb +94 -0
  15. data/lib/rails-bootstrap-helpers/renderers/action_link_renderer.rb +19 -0
  16. data/lib/rails-bootstrap-helpers/renderers/button_renderer.rb +6 -4
  17. data/lib/rails-bootstrap-helpers/renderers/content_tag_renderer.rb +67 -0
  18. data/lib/rails-bootstrap-helpers/renderers/dropdown_button_renderer.rb +87 -0
  19. data/lib/rails-bootstrap-helpers/renderers/iconic_icon_renderer.rb +75 -0
  20. data/lib/rails-bootstrap-helpers/renderers/row_link_renderer.rb +12 -0
  21. data/lib/rails-bootstrap-helpers/renderers/tabbable_renderer.rb +186 -0
  22. data/lib/rails-bootstrap-helpers/version.rb +1 -1
  23. data/spec/dummy/log/test.log +296 -0
  24. data/spec/helpers/accordion_helper_spec.rb +35 -0
  25. data/spec/helpers/alert_helper_spec.rb +11 -7
  26. data/spec/helpers/base_helper_spec.rb +44 -0
  27. data/spec/helpers/button_helper_spec.rb +214 -9
  28. data/spec/helpers/form_tag_helper_spec.rb +27 -0
  29. data/spec/helpers/navigation_helper_spec.rb +228 -0
  30. data/spec/helpers/options_helper_spec.rb +50 -0
  31. data/spec/helpers/tag_helper_spec.rb +26 -0
  32. data/spec/helpers/url_helper_spec.rb +33 -0
  33. data/spec/spec_helper.rb +2 -0
  34. data/spec/support/html.rb +9 -0
  35. data/spec/support/matchers/helpers/alert_helper/render_bs_alert.rb +19 -10
  36. data/spec/support/matchers/helpers/base_helper/render_icon.rb +18 -1
  37. data/spec/support/matchers/helpers/base_helper/render_iconic_icon.rb +191 -0
  38. data/spec/support/matchers/helpers/button_helper/render_bs_button_to.rb +44 -3
  39. data/spec/support/matchers/helpers/button_helper/render_inline_button_to.rb +1 -1
  40. data/spec/support/matchers/helpers/form_tag_helper/render_bs_button_tag.rb +39 -1
  41. data/spec/support/matchers/helpers/form_tag_helper/render_bs_submit_tag.rb +96 -0
  42. data/spec/support/matchers/helpers/url_helper/render_action_link_to.rb +123 -0
  43. data/spec/support/matchers/helpers/url_helper/render_row_link_to.rb +97 -0
  44. metadata +59 -8
  45. checksums.yaml +0 -15
@@ -0,0 +1,186 @@
1
+ module RailsBootstrapHelpers::Renderers
2
+ class TabbableRenderer < Renderer
3
+ def initialize (template, *args, &block)
4
+ super template
5
+ @args = args || []
6
+ @block = block
7
+
8
+ @options = {}
9
+ @tabs = []
10
+ @panes = []
11
+
12
+ @last_id = 0
13
+ @ids = []
14
+ end
15
+
16
+ def render
17
+ befor_block
18
+ block.call TabContext.new(self)
19
+ after_block
20
+ end
21
+
22
+ def add_tab (text, options)
23
+ @tabs << Tab.new(text, options)
24
+ end
25
+
26
+ def add_pane (block, options)
27
+ @panes << Pane.new(block, options)
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :args
33
+ attr_reader :tabs
34
+ attr_reader :panes
35
+ attr_reader :block
36
+ attr_reader :options
37
+ attr_accessor :ids
38
+ attr_accessor :fade
39
+
40
+ def active_tabs?
41
+ @active_tabs
42
+ end
43
+
44
+ def active_panes?
45
+ @active_panes
46
+ end
47
+
48
+ def befor_block
49
+ extract_options!
50
+ collect_tabs
51
+ end
52
+
53
+ def after_block
54
+ match_tabs_with_panes!
55
+ identify_active_tabs
56
+ identify_active_panes
57
+
58
+ render_tabbable
59
+ end
60
+
61
+ def extract_options!
62
+ if args.last.is_a?(Hash)
63
+ @options = args.last.dup
64
+ @fade = @options.delete(:fade)
65
+ @tabs = args[0 ... -1]
66
+ else
67
+ @tabs = args
68
+ end
69
+ end
70
+
71
+ def collect_tabs
72
+ @tabs = @tabs.map { |text| Tab.new(text, {}) }
73
+ end
74
+
75
+ def identify_active_tabs
76
+ @active_tabs = tabs.any? { |tab| tab.options.key?(:active) }
77
+ end
78
+
79
+ def identify_active_panes
80
+ @active_panes = panes.any? { |pane| pane.options.key?(:active) }
81
+ end
82
+
83
+ def match_tabs_with_panes!
84
+ tab_text = pluralize(tabs.length, "tab")
85
+ pane_text = pluralize(panes.length, "pane")
86
+
87
+ tab_was = tabs.length == 1 ? "was" : "were"
88
+ pane_was = panes.length == 1 ? "was" : "were"
89
+
90
+ if tabs.length != panes.length
91
+ raise "Unmatching tabs and panes. #{tab_text} #{tab_was} given and #{pane_text} #{pane_was} given"
92
+ end
93
+ end
94
+
95
+ def render_tabbable
96
+ append_class!(options, "tabbable")
97
+ append_class!(options, "tabbable-bordered") if options.delete(:bordered)
98
+
99
+ if direction = options.delete(:direction)
100
+ direction = class_for_direction(direction)
101
+ append_class!(options, direction)
102
+ end
103
+
104
+ content_tag :div, options do
105
+ render_tabs + "\n" +
106
+ render_tab_content
107
+ end
108
+ end
109
+
110
+ def render_tabs
111
+ content_tag :ul, class: "nav nav-tabs" do
112
+ content = process_tab(tabs.first, !active_tabs?) + "\n"
113
+ content << tabs[1 .. -1].map { |tab| process_tab(tab) }.join("\n").html_safe
114
+ end
115
+ end
116
+
117
+ def process_tab (tab, active = false)
118
+ @ids << id_for_tab(tab.name)
119
+ render_tab(ids.last, tab, active)
120
+ end
121
+
122
+ def render_tab_content
123
+ content_tag :div, class: "tab-content" do
124
+ content = render_tab_pane(ids.first, panes.first, !active_panes?) + "\n"
125
+
126
+ panes = @panes[1 .. -1]
127
+ ids = @ids[1 .. -1]
128
+
129
+ content << panes.zip(ids).map { |pane, id| render_tab_pane(id, pane) }.join("\n").html_safe
130
+ end
131
+ end
132
+
133
+ def render_tab (id, tab, active = false)
134
+ if tab.options.key?(:active)
135
+ active = tab.options[:active]
136
+ end
137
+
138
+ content_tag :li, class: ("active" if active) do
139
+ link_to tab.name, "##{id}", data: { toggle: "tab" }
140
+ end
141
+ end
142
+
143
+ def render_tab_pane (id, pane, active = false)
144
+ if pane.options.key?(:active)
145
+ active = pane.options[:active]
146
+ end
147
+
148
+ cls = "tab-pane"
149
+ cls << " active" if active
150
+ cls << " fade in" if fade
151
+ content_tag :div, id: "#{id}", class: cls, &pane.block
152
+ end
153
+
154
+ def id_for_tab (name)
155
+ id = "tab_pane_#{@last_id}_#{name.object_id}"
156
+ @last_id += 1
157
+ id
158
+ end
159
+
160
+ def class_for_direction (direction)
161
+ direction = ERB::Util.html_escape(direction.to_s)
162
+ direction == "top" ? "" : "tabs-#{direction}"
163
+ end
164
+
165
+ class TabContext
166
+ def initialize (renderer)
167
+ @renderer = renderer
168
+ end
169
+
170
+ def tab (text, options = {})
171
+ @renderer.add_tab(text, options)
172
+ end
173
+
174
+ def tab_pane (options = {}, &block)
175
+ @renderer.add_pane(block, options)
176
+ end
177
+
178
+ private
179
+
180
+ attr_reader :renderer
181
+ end
182
+
183
+ Tab = Struct.new(:name, :options)
184
+ Pane = Struct.new(:block, :options)
185
+ end
186
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsBootstrapHelpers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -45,3 +45,299 @@ Connecting to database specified by database.yml
45
45
  Connecting to database specified by database.yml
46
46
  Connecting to database specified by database.yml
47
47
  Connecting to database specified by database.yml
48
+ Connecting to database specified by database.yml
49
+ Connecting to database specified by database.yml
50
+ Connecting to database specified by database.yml
51
+ Connecting to database specified by database.yml
52
+ Connecting to database specified by database.yml
53
+ Connecting to database specified by database.yml
54
+ Connecting to database specified by database.yml
55
+ Connecting to database specified by database.yml
56
+ Connecting to database specified by database.yml
57
+ Connecting to database specified by database.yml
58
+ Connecting to database specified by database.yml
59
+ Connecting to database specified by database.yml
60
+ Connecting to database specified by database.yml
61
+ Connecting to database specified by database.yml
62
+ Connecting to database specified by database.yml
63
+ Connecting to database specified by database.yml
64
+ Connecting to database specified by database.yml
65
+ Connecting to database specified by database.yml
66
+ Connecting to database specified by database.yml
67
+ Connecting to database specified by database.yml
68
+ Connecting to database specified by database.yml
69
+ Connecting to database specified by database.yml
70
+ Connecting to database specified by database.yml
71
+ Connecting to database specified by database.yml
72
+ Connecting to database specified by database.yml
73
+ Connecting to database specified by database.yml
74
+ Connecting to database specified by database.yml
75
+ Connecting to database specified by database.yml
76
+ Connecting to database specified by database.yml
77
+ Connecting to database specified by database.yml
78
+ Connecting to database specified by database.yml
79
+ Connecting to database specified by database.yml
80
+ Connecting to database specified by database.yml
81
+ Connecting to database specified by database.yml
82
+ Connecting to database specified by database.yml
83
+ Connecting to database specified by database.yml
84
+ Connecting to database specified by database.yml
85
+ Connecting to database specified by database.yml
86
+ Connecting to database specified by database.yml
87
+ Connecting to database specified by database.yml
88
+ Connecting to database specified by database.yml
89
+ Connecting to database specified by database.yml
90
+ Connecting to database specified by database.yml
91
+ Connecting to database specified by database.yml
92
+ Connecting to database specified by database.yml
93
+ Connecting to database specified by database.yml
94
+ Connecting to database specified by database.yml
95
+ Connecting to database specified by database.yml
96
+ Connecting to database specified by database.yml
97
+ Connecting to database specified by database.yml
98
+ Connecting to database specified by database.yml
99
+ Connecting to database specified by database.yml
100
+ Connecting to database specified by database.yml
101
+ Connecting to database specified by database.yml
102
+ Connecting to database specified by database.yml
103
+ Connecting to database specified by database.yml
104
+ Connecting to database specified by database.yml
105
+ Connecting to database specified by database.yml
106
+ Connecting to database specified by database.yml
107
+ Connecting to database specified by database.yml
108
+ Connecting to database specified by database.yml
109
+ Connecting to database specified by database.yml
110
+ Connecting to database specified by database.yml
111
+ Connecting to database specified by database.yml
112
+ Connecting to database specified by database.yml
113
+ Connecting to database specified by database.yml
114
+ Connecting to database specified by database.yml
115
+ Connecting to database specified by database.yml
116
+ Connecting to database specified by database.yml
117
+ Connecting to database specified by database.yml
118
+ Connecting to database specified by database.yml
119
+ Connecting to database specified by database.yml
120
+ Connecting to database specified by database.yml
121
+ Connecting to database specified by database.yml
122
+ Connecting to database specified by database.yml
123
+ Connecting to database specified by database.yml
124
+ Connecting to database specified by database.yml
125
+ Connecting to database specified by database.yml
126
+ Connecting to database specified by database.yml
127
+ Connecting to database specified by database.yml
128
+ Connecting to database specified by database.yml
129
+ Connecting to database specified by database.yml
130
+ Connecting to database specified by database.yml
131
+ Connecting to database specified by database.yml
132
+ Connecting to database specified by database.yml
133
+ Connecting to database specified by database.yml
134
+ Connecting to database specified by database.yml
135
+ Connecting to database specified by database.yml
136
+ Connecting to database specified by database.yml
137
+ Connecting to database specified by database.yml
138
+ Connecting to database specified by database.yml
139
+ Connecting to database specified by database.yml
140
+ Connecting to database specified by database.yml
141
+ Connecting to database specified by database.yml
142
+ Connecting to database specified by database.yml
143
+ Connecting to database specified by database.yml
144
+ Connecting to database specified by database.yml
145
+ Connecting to database specified by database.yml
146
+ Connecting to database specified by database.yml
147
+ Connecting to database specified by database.yml
148
+ Connecting to database specified by database.yml
149
+ Connecting to database specified by database.yml
150
+ Connecting to database specified by database.yml
151
+ Connecting to database specified by database.yml
152
+ Connecting to database specified by database.yml
153
+ Connecting to database specified by database.yml
154
+ Connecting to database specified by database.yml
155
+ Connecting to database specified by database.yml
156
+ Connecting to database specified by database.yml
157
+ Connecting to database specified by database.yml
158
+ Connecting to database specified by database.yml
159
+ Connecting to database specified by database.yml
160
+ Connecting to database specified by database.yml
161
+ Connecting to database specified by database.yml
162
+ Connecting to database specified by database.yml
163
+ Connecting to database specified by database.yml
164
+ Connecting to database specified by database.yml
165
+ Connecting to database specified by database.yml
166
+ Connecting to database specified by database.yml
167
+ Connecting to database specified by database.yml
168
+ Connecting to database specified by database.yml
169
+ Connecting to database specified by database.yml
170
+ Connecting to database specified by database.yml
171
+ Connecting to database specified by database.yml
172
+ Connecting to database specified by database.yml
173
+ Connecting to database specified by database.yml
174
+ Connecting to database specified by database.yml
175
+ Connecting to database specified by database.yml
176
+ Connecting to database specified by database.yml
177
+ Connecting to database specified by database.yml
178
+ Connecting to database specified by database.yml
179
+ Connecting to database specified by database.yml
180
+ Connecting to database specified by database.yml
181
+ Connecting to database specified by database.yml
182
+ Connecting to database specified by database.yml
183
+ Connecting to database specified by database.yml
184
+ Connecting to database specified by database.yml
185
+ Connecting to database specified by database.yml
186
+ Connecting to database specified by database.yml
187
+ Connecting to database specified by database.yml
188
+ Connecting to database specified by database.yml
189
+ Connecting to database specified by database.yml
190
+ Connecting to database specified by database.yml
191
+ Connecting to database specified by database.yml
192
+ Connecting to database specified by database.yml
193
+ Connecting to database specified by database.yml
194
+ Connecting to database specified by database.yml
195
+ Connecting to database specified by database.yml
196
+ Connecting to database specified by database.yml
197
+ Connecting to database specified by database.yml
198
+ Connecting to database specified by database.yml
199
+ Connecting to database specified by database.yml
200
+ Connecting to database specified by database.yml
201
+ Connecting to database specified by database.yml
202
+ Connecting to database specified by database.yml
203
+ Connecting to database specified by database.yml
204
+ Connecting to database specified by database.yml
205
+ Connecting to database specified by database.yml
206
+ Connecting to database specified by database.yml
207
+ Connecting to database specified by database.yml
208
+ Connecting to database specified by database.yml
209
+ Connecting to database specified by database.yml
210
+ Connecting to database specified by database.yml
211
+ Connecting to database specified by database.yml
212
+ Connecting to database specified by database.yml
213
+ Connecting to database specified by database.yml
214
+ Connecting to database specified by database.yml
215
+ Connecting to database specified by database.yml
216
+ Connecting to database specified by database.yml
217
+ Connecting to database specified by database.yml
218
+ Connecting to database specified by database.yml
219
+ Connecting to database specified by database.yml
220
+ Connecting to database specified by database.yml
221
+ Connecting to database specified by database.yml
222
+ Connecting to database specified by database.yml
223
+ Connecting to database specified by database.yml
224
+ Connecting to database specified by database.yml
225
+ Connecting to database specified by database.yml
226
+ Connecting to database specified by database.yml
227
+ Connecting to database specified by database.yml
228
+ Connecting to database specified by database.yml
229
+ Connecting to database specified by database.yml
230
+ Connecting to database specified by database.yml
231
+ Connecting to database specified by database.yml
232
+ Connecting to database specified by database.yml
233
+ Connecting to database specified by database.yml
234
+ Connecting to database specified by database.yml
235
+ Connecting to database specified by database.yml
236
+ Connecting to database specified by database.yml
237
+ Connecting to database specified by database.yml
238
+ Connecting to database specified by database.yml
239
+ Connecting to database specified by database.yml
240
+ Connecting to database specified by database.yml
241
+ Connecting to database specified by database.yml
242
+ Connecting to database specified by database.yml
243
+ Connecting to database specified by database.yml
244
+ Connecting to database specified by database.yml
245
+ Connecting to database specified by database.yml
246
+ Connecting to database specified by database.yml
247
+ Connecting to database specified by database.yml
248
+ Connecting to database specified by database.yml
249
+ Connecting to database specified by database.yml
250
+ Connecting to database specified by database.yml
251
+ Connecting to database specified by database.yml
252
+ Connecting to database specified by database.yml
253
+ Connecting to database specified by database.yml
254
+ Connecting to database specified by database.yml
255
+ Connecting to database specified by database.yml
256
+ Connecting to database specified by database.yml
257
+ Connecting to database specified by database.yml
258
+ Connecting to database specified by database.yml
259
+ Connecting to database specified by database.yml
260
+ Connecting to database specified by database.yml
261
+ Connecting to database specified by database.yml
262
+ Connecting to database specified by database.yml
263
+ Connecting to database specified by database.yml
264
+ Connecting to database specified by database.yml
265
+ Connecting to database specified by database.yml
266
+ Connecting to database specified by database.yml
267
+ Connecting to database specified by database.yml
268
+ Connecting to database specified by database.yml
269
+ Connecting to database specified by database.yml
270
+ Connecting to database specified by database.yml
271
+ Connecting to database specified by database.yml
272
+ Connecting to database specified by database.yml
273
+ Connecting to database specified by database.yml
274
+ Connecting to database specified by database.yml
275
+ Connecting to database specified by database.yml
276
+ Connecting to database specified by database.yml
277
+ Connecting to database specified by database.yml
278
+ Connecting to database specified by database.yml
279
+ Connecting to database specified by database.yml
280
+ Connecting to database specified by database.yml
281
+ Connecting to database specified by database.yml
282
+ Connecting to database specified by database.yml
283
+ Connecting to database specified by database.yml
284
+ Connecting to database specified by database.yml
285
+ Connecting to database specified by database.yml
286
+ Connecting to database specified by database.yml
287
+ Connecting to database specified by database.yml
288
+ Connecting to database specified by database.yml
289
+ Connecting to database specified by database.yml
290
+ Connecting to database specified by database.yml
291
+ Connecting to database specified by database.yml
292
+ Connecting to database specified by database.yml
293
+ Connecting to database specified by database.yml
294
+ Connecting to database specified by database.yml
295
+ Connecting to database specified by database.yml
296
+ Connecting to database specified by database.yml
297
+ Connecting to database specified by database.yml
298
+ Connecting to database specified by database.yml
299
+ Connecting to database specified by database.yml
300
+ Connecting to database specified by database.yml
301
+ Connecting to database specified by database.yml
302
+ Connecting to database specified by database.yml
303
+ Connecting to database specified by database.yml
304
+ Connecting to database specified by database.yml
305
+ Connecting to database specified by database.yml
306
+ Connecting to database specified by database.yml
307
+ Connecting to database specified by database.yml
308
+ Connecting to database specified by database.yml
309
+ Connecting to database specified by database.yml
310
+ Connecting to database specified by database.yml
311
+ Connecting to database specified by database.yml
312
+ Connecting to database specified by database.yml
313
+ Connecting to database specified by database.yml
314
+ Connecting to database specified by database.yml
315
+ Connecting to database specified by database.yml
316
+ Connecting to database specified by database.yml
317
+ Connecting to database specified by database.yml
318
+ Connecting to database specified by database.yml
319
+ Connecting to database specified by database.yml
320
+ Connecting to database specified by database.yml
321
+ Connecting to database specified by database.yml
322
+ Connecting to database specified by database.yml
323
+ Connecting to database specified by database.yml
324
+ Connecting to database specified by database.yml
325
+ Connecting to database specified by database.yml
326
+ Connecting to database specified by database.yml
327
+ Connecting to database specified by database.yml
328
+ Connecting to database specified by database.yml
329
+ Connecting to database specified by database.yml
330
+ Connecting to database specified by database.yml
331
+ Connecting to database specified by database.yml
332
+ Connecting to database specified by database.yml
333
+ Connecting to database specified by database.yml
334
+ Connecting to database specified by database.yml
335
+ Connecting to database specified by database.yml
336
+ Connecting to database specified by database.yml
337
+ Connecting to database specified by database.yml
338
+ Connecting to database specified by database.yml
339
+ Connecting to database specified by database.yml
340
+ Connecting to database specified by database.yml
341
+ Connecting to database specified by database.yml
342
+ Connecting to database specified by database.yml
343
+ Connecting to database specified by database.yml