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
data/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # Rails Bootstrap Helpers
2
2
 
3
3
  Rails Bootstrap Helpers is a plugin for Ruby on Rails that adds view helpers for
4
- [Bootstrap](http://twitter.github.io/bootstrap/).
4
+ [Bootstrap](http://getbootstrap.com/2.3.2/). It also contains some helpers
5
+ for [Jasny's Bootstrap extensions](http://jasny.github.io/bootstrap/index.html).
6
+
7
+ This documentation is for the upcoming release, that is git HEAD.
8
+ For documentation for the latest release see: https://github.com/Tretti/rails-bootstrap-helpers/blob/v0.1.0/README.md
5
9
 
6
10
  ## Installation
7
11
 
@@ -15,8 +19,8 @@ Manually include the necessary stylesheets and JavaScript files from Bootstrap.
15
19
 
16
20
  Although it has no direct dependencies on other gems than Rails, it is necessary
17
21
  to include Bootstrap in some way or another to make this gem useful.
18
- [bootstrap-sass](https://github.com/thomas-mcdonald/bootstrap-sass) is
19
- recommended.
22
+ For standard Bootstrap, [bootstrap-sass](https://github.com/thomas-mcdonald/bootstrap-sass) is
23
+ recommended. For Jasny Bootstrap, [jasny-bootstrap-extension-rails](https://github.com/mdedetrich/jasny-bootstrap-extension-rails) is recommended.
20
24
 
21
25
  ### JavaScript
22
26
 
@@ -28,7 +32,7 @@ uses JavaScript that needs manually initialization:
28
32
  * [bs\_popover\_button](#bs_popover_button)
29
33
 
30
34
  For which JavaScript file to include, follow the
31
- [Bootstrap documentation](http://twitter.github.io/bootstrap/javascript.html).
35
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/javascript.html).
32
36
 
33
37
  ## Usage
34
38
 
@@ -41,7 +45,30 @@ For which JavaScript file to include, follow the
41
45
  <%= icon :edit, invert: true %> # inverts the color of the icon, making it white
42
46
  ```
43
47
 
44
- [Bootstrap documentation](http://twitter.github.io/bootstrap/base-css.html#icons)
48
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/base-css.html#icons)
49
+
50
+ #### <a id="iconic_icon"></a>iconic\_icon
51
+
52
+ ```erb
53
+ <%= iconic_icon :check %> # renders an icon with the iconic-check icon
54
+
55
+ <%= iconic_icon :edit, color: :blue %> # render an icon with an CSS color
56
+ <%= iconic_icon :edit, color: "#fff" %> # render an icon with an CSS color
57
+
58
+ <%= iconic_icon :edit, size: 10 %> # render an icon with an CSS font size
59
+ <%= iconic_icon :edit, size: "10" %> # render an icon with an CSS font size
60
+ <%= iconic_icon :edit, size: "10em" %> # render an icon with an CSS font size
61
+
62
+ <%= iconic_icon :edit, bs_style: "muted" %> # render an Bootstrap style
63
+ <%= iconic_icon :edit, bs_style: "success" %> # render an Bootstrap style
64
+
65
+ <%= iconic_icon :edit, action_style: "default" %> # render an Jasny Bootstrap action link style
66
+ <%= iconic_icon :edit, action_style: "success" %> # render an Jasny Bootstrap action link style
67
+ ```
68
+
69
+ Renders an icon using the Jasny Bootstrap Iconic icon set.
70
+
71
+ [Jasny Bootstrap documentation](http://jasny.github.io/bootstrap/base-css.html#iconic)
45
72
 
46
73
  ### <a id="alerts"></a>Alerts
47
74
 
@@ -52,7 +79,7 @@ For which JavaScript file to include, follow the
52
79
  <%= bs_alert "foo", dismiss_button: true %> # alert box with a dismiss button
53
80
  ```
54
81
 
55
- [Bootstrap documentation](http://twitter.github.io/bootstrap/components.html#alerts)
82
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#alerts)
56
83
 
57
84
  ### <a id="buttons"></a>Buttons
58
85
 
@@ -84,8 +111,8 @@ Bootstrap button. That is, a button with the an icon (no text) and the size
84
111
  #### <a id="bs_popover_button"></a>bs\_popover\_button
85
112
 
86
113
  ```erb
87
- <%= bs_popover_button "foo", "bar"
88
- <%= bs_popover_button "foo", "bar", placement: "right" %>
114
+ <%= bs_popover_button "foo", "bar" %>
115
+ <%= bs_popover_button "foo", "bar", position: "right" %>
89
116
  <%= bs_popover_button "foo" do %>
90
117
  <%= link_to "Google", "http://www.google.se" %>
91
118
  <% end %>
@@ -97,13 +124,94 @@ popover can either be supplied as the second argument or as a block.
97
124
  **Note:** this helper requires JavaScript to be manually initialized. Add the
98
125
  following code to your JavaScript file:
99
126
 
100
- ````javascript
127
+ ```javascript
101
128
  $("[data-toggle=popover]").popover(html: true)
102
129
  // The "html" option tells the plugin to not escape HTML. Useful when rendering
103
130
  // the popover content using a block.
104
131
  ```
105
132
 
106
- [Bootstrap documentation](http://twitter.github.io/bootstrap/base-css.html#buttons)
133
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/base-css.html#buttons)
134
+
135
+ #### <a id="bs_collapsible_button"></a>bs\_collapsible\_button
136
+
137
+ ```erb
138
+ <%= bs_collapsible_button "foo", "#bar" %>
139
+ <%= bs_collapsible_button "foo", "#bar", style: "primary" %>
140
+
141
+ <div id="bar">foobar</div>
142
+ ```
143
+
144
+ Renders a Bootstrap button that when clicked will open a collapsible section.
145
+ The second argument is a selector matching the section to open.
146
+
147
+ #### <a id="button_group"></a>button\_group
148
+
149
+ ```erb
150
+ <%= button_group do %>
151
+ <%= bs_button_to "google", "http://www.google.se" %>
152
+ <%= bs_button_to "google", "http://www.google.se", style: "success" %>
153
+ <% end %>
154
+
155
+ <%= button_group vertical: true do %>
156
+ <%= bs_button_to "google", "http://www.google.se" %>
157
+ <%= bs_button_to "google", "http://www.google.se", style: "success" %>
158
+ <% end %>
159
+
160
+ <%= button_group toolbar: true do %>
161
+ <%= button_group do %>
162
+ <%= bs_button_to "google", "http://www.google.se" %>
163
+ <%= bs_button_to "google", "http://www.google.se", style: "success" %>
164
+ <% end %>
165
+
166
+ <%= button_group do %>
167
+ <%= bs_button_to "google", "http://www.google.se", disabled: true %>
168
+ <%= bs_button_to "google", "http://www.google.se", icon: "edit" %>
169
+ <% end %>
170
+ <%= end %>
171
+ ```
172
+
173
+ Renders a Bootstrap button group. That is, a div tag with the `btn-group` class.
174
+
175
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#buttonGroups)
176
+
177
+ #### <a id="bs_dropdown_button_to"></a>bs\_dropdown\_button\_to
178
+
179
+ Renders a Bootstrap button with a dropdown menu. The menu items are rendered in
180
+ the block by rendering list items (`<li>`) with a link (`<a>`) for the menu items.
181
+
182
+ If the second argument is a string it will render a split button with a dropdown
183
+ menu. The second argument will be interpreted as the URL to the left side of the
184
+ button. Then the third argument can be used for options.
185
+
186
+ It accepts all the same options as [bs\_button\_to](#bs_button_to).
187
+
188
+ Standard button with dropdown menu.
189
+
190
+ ```erb
191
+ <%= bs_dropdown_button_to "foo" do %>
192
+ <li><%= link_to "Google", "http://www.google.com" %></li>
193
+ <li><%= link_to "Github", "http://www.github.com" %></li>
194
+ <% end %>
195
+ ```
196
+ Split button with a dropdown menu.
197
+
198
+ ```erb
199
+ <%= bs_dropdown_button_to "foo", "http://www.google.com" do %>
200
+ <li><%= link_to "Google", "http://www.google.com" %></li>
201
+ <li><%= link_to "Github", "http://www.github.com" %></li>
202
+ <% end %>
203
+ ```
204
+
205
+ Standard button with dropdown menu and an edit icon.
206
+
207
+ ```erb
208
+ <%= bs_dropdown_button_to "foo", icon: "edit" do %>
209
+ <li><%= link_to "Google", "http://www.google.com" %></li>
210
+ <li><%= link_to "Github", "http://www.github.com" %></li>
211
+ <% end %>
212
+ ```
213
+
214
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#buttonDropdowns)
107
215
 
108
216
  ### <a id="forms"></a>Forms
109
217
 
@@ -117,7 +225,15 @@ Renders an `button` tag styled as a Bootstrap button. First argument is the text
117
225
  to be rendered on the button, the other is what type of button (that is, the HTML
118
226
  attribute `type`). Accepts all the options as [bs\_button\_to](#bs_button_to) does.
119
227
 
120
- [Bootstrap documentation](http://twitter.github.io/bootstrap/base-css.html#buttons)
228
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/base-css.html#buttons)
229
+
230
+ #### <a id="bs_submit_tag"></a> bs\_submit\_tag
231
+
232
+ ```erb
233
+ <%= bs_submit_tag "save" %>
234
+ <%= bs_submit_tag "save", style: "primary" %>
235
+ <%= bs_submit_tag "save", size: "small" %>
236
+ ```
121
237
 
122
238
  ### <a id="labels"></a>Labels
123
239
 
@@ -125,7 +241,7 @@ attribute `type`). Accepts all the options as [bs\_button\_to](#bs_button_to) do
125
241
 
126
242
  ```erb
127
243
  <%= bs_label "foo" # standard label%>
128
- <%= bs_label "foo", style: "success" # styled label %>
244
+ <%= bs_label "foo", :success # styled label %>
129
245
  ```
130
246
 
131
247
  ### <a id="tooltips"></a>Tooltips
@@ -140,11 +256,217 @@ tooltip to the rendered component.
140
256
  **Note:** this option requires JavaScript to be manually initialized. Add the
141
257
  following code to your JavaScript file:
142
258
 
143
- ````javascript
259
+ ```javascript
144
260
  $("[data-toggle=tooltip]").tooltip()
145
261
  ```
146
262
 
147
- [Bootstrap documentation](http://twitter.github.io/bootstrap/components.html#labels-badges)
263
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#labels-badges)
264
+
265
+ ### <a id="tags"></a>Tags
266
+
267
+ #### <a id="bs_content_tag"></a>bs\_content\_tag
268
+
269
+ ```ruby
270
+ bs_content_tag :div do
271
+ append "foo"
272
+ end
273
+
274
+ bs_content_tag :div, id: "foo" do
275
+ bs_content_tag :div, class: "asd" do
276
+ append "bar"
277
+ end
278
+
279
+ append "foobar"
280
+ end
281
+ ```
282
+
283
+ The above code will return the following HTML code:
284
+
285
+ ```html
286
+ <div>
287
+ foo
288
+ </div>
289
+
290
+ <div id="foo">
291
+ <div class="asd">
292
+ bar
293
+ </div>
294
+ foobar
295
+ </div>
296
+ ```
297
+
298
+ Returns an HTML block. This method behaves basically just like `content_tag` but
299
+ properly indents and add newlines to the HTML. This is useful in helpers.
300
+
301
+ ### <a id="accordion"></a>Accordion
302
+
303
+ #### <a id="accordion_helper"></a>accordion
304
+
305
+ ```erb
306
+ <%= accordion "unique_id" do |a| %>
307
+ <% a.group "heading" do %>
308
+ content
309
+ <% end %>
310
+ <% end %>
311
+ ```
312
+
313
+ The above code will render the following HTML code:
314
+
315
+ ```html
316
+ <div class="accordion" id="unique_id">
317
+ <div class="accordion-group">
318
+ <div class="accordion-heading">
319
+ <a class="accordion-toggle" data-parent="#unique_id.accordion" data-toggle="collapse" href="#unique_id.accordion .accordion-group:nth-child(0) .accordion-body.collapse">
320
+ heading
321
+ </a>
322
+ </div>
323
+
324
+ <div class="accordion-body collapse">
325
+ <div class="accordion-inner">
326
+ content
327
+ </div>
328
+ </div>
329
+ </div>
330
+ </div>
331
+ ```
332
+
333
+ Renders a Bootstrap accordion/collapsible section.
334
+
335
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/javascript.html#collapse)
336
+
337
+ ### <a id="accordion"></a>Url Helpers
338
+
339
+ #### <a id="action_link_to"></a>action\_link\_to
340
+
341
+ ```erb
342
+ <%= action_link_to "google", "http://www.google.se" %>
343
+ <%= action_link_to "google", "http://www.google.se", style: "default" %>
344
+ <%= action_link_to "google", "http://www.google.se", style: "primary" %>
345
+ ```
346
+
347
+ Renders an action link from Jasny's Bootstrap extensions. It's basically a
348
+ wrapper around the `link_to` helper. In addition all the standard arguments and
349
+ options that `link_to` accepts it also accepts the above options.
350
+
351
+ [Jasny Bootstrap documentation](http://jasny.github.io/bootstrap/base-css.html#action-links)
352
+
353
+ #### <a id="action_link_to"></a>row\_link\_to
354
+
355
+ ```erb
356
+ <%= row_link_to "google", "http://www.google.se" %>
357
+ ```
358
+
359
+ Renders a row link from Jasny's Bootstrap extensions. It's basically a
360
+ wrapper around the `link_to` helper.
361
+
362
+ [Jasny Bootstrap documentation](http://jasny.github.io/bootstrap/javascript.html#rowlink)
363
+
364
+ ### <a id="navigation"></a>Navigation
365
+
366
+ #### <a id="tabbable"></a>tabbable
367
+
368
+ Renders a tabbable navigation. By default the first tab will be active. This is
369
+ possible to override by passing `active: true` or `active: false` to any tab
370
+ or tab pane. If `active: false` is specified to any tab or tab pane the first
371
+ tab or tab pane will _not_ get the class "active".
372
+
373
+ ```erb
374
+ <%= tabbable do |bar| %>
375
+ <% bar.tab "foo" %>
376
+ <% bar.tab "bar" %>
377
+
378
+ <% bar.tab_pane do %>
379
+ Foo pane
380
+ <% end %>
381
+
382
+ <% bar.tab_pane do %>
383
+ Bar pane
384
+ <% end %>
385
+ <% end >
386
+ ```
387
+
388
+ The above code will render the following HTML:
389
+
390
+ ```html
391
+ <div class="tabbable">
392
+ <ul class="nav nav-tabs">
393
+ <li class="active"><a href="#tab_pane_0_2156227680" data-toggle="tab">foo</a></li>
394
+ <li><a href="#tab_pane_1_2156227620" data-toggle="tab">bar</a></li>
395
+ </ul>
396
+
397
+ <div class="tab-content">
398
+ <div class="active" id="tab_pane_0_2156227680">
399
+ foo content
400
+ </div>
401
+
402
+ <div id="tab_pane_1_2156227620">
403
+ bar content
404
+ </div>
405
+ </div>
406
+ </div>
407
+ ```
408
+
409
+ Alternatively the tabs can be passed directly to the `tabbable` method:
410
+
411
+ ```erb
412
+ <%= tabbable "foo", "bar" do |bar| %>
413
+ <% bar.tab_pane do %>
414
+ Foo pane
415
+ <% end %>
416
+
417
+ <% bar.tab_pane do %>
418
+ Bar pane
419
+ <% end %>
420
+ <% end >
421
+ ```
422
+
423
+ If the number of tabs and tab panes don't match an error will be raised.
424
+
425
+ ```erb
426
+ <%= tabbable "foo", fade: true do |bar| %>
427
+ <% bar.tab_pane do %>
428
+ Foo pane
429
+ <% end %>
430
+ <% end >
431
+ ```
432
+
433
+ The above option will add the "fade in" class to each tab pane. Requires the
434
+ bootstrap-transition.js file to work.
435
+
436
+ ```erb
437
+ <%= tabbable do |bar| %>
438
+ <% bar.tab "foo" %>
439
+ <% bar.tab "bar", active: true %>
440
+
441
+ <% bar.tab_pane do %>
442
+ Foo pane
443
+ <% end %>
444
+
445
+ <% bar.tab_pane active: true do %>
446
+ Bar pane
447
+ <% end %>
448
+ <% end >
449
+ ```
450
+
451
+ The above will add the class "active" only to the tabs and tab panes with the
452
+ option `active: true`.
453
+
454
+ ```erb
455
+ <%= tabbable "foo", bordered: true do |bar| %>
456
+ <% bar.tab_pane do %>
457
+ Foo pane
458
+ <% end %>
459
+ <% end >
460
+ ```
461
+
462
+ The above option will render the tabbable container with a border. Requires
463
+ the Jasny Bootstrap extensions.
464
+
465
+ Add the option `direction`, with the value `"top"`, `"left"`, `"right"` or
466
+ `"below"`, to render the tabs in the direction specified.
467
+
468
+ [Bootstrap documentation](http://getbootstrap.com/2.3.2/components.html#navs)
469
+ [Jasny Bootstrap documentation](http://jasny.github.io/bootstrap/components.html#navs)
148
470
 
149
471
  ## Tests
150
472
 
@@ -2,18 +2,29 @@ require "rails-bootstrap-helpers/core_ext/abstract"
2
2
 
3
3
  module RailsBootstrapHelpers
4
4
  module Renderers
5
- autoload :AbstractButtonRenderer, "rails-bootstrap-helpers/renderers/abstract_button_renderer"
5
+ autoload :AbstractLinkRenderer, "rails-bootstrap-helpers/renderers/abstract_link_renderer"
6
+ autoload :AccordionRenderer, "rails-bootstrap-helpers/renderers/accordion_renderer"
7
+ autoload :ActionLinkRenderer, "rails-bootstrap-helpers/renderers/action_link_renderer"
6
8
  autoload :ButtonRenderer, "rails-bootstrap-helpers/renderers/button_renderer"
9
+ autoload :ContentTagRenderer, "rails-bootstrap-helpers/renderers/content_tag_renderer"
10
+ autoload :DropdownButtonRenderer, "rails-bootstrap-helpers/renderers/dropdown_button_renderer"
11
+ autoload :IconicIconRenderer, "rails-bootstrap-helpers/renderers/iconic_icon_renderer"
7
12
  autoload :Renderer, "rails-bootstrap-helpers/renderers/renderer"
13
+ autoload :RowLinkRenderer, "rails-bootstrap-helpers/renderers/row_link_renderer"
14
+ autoload :TabbableRenderer, "rails-bootstrap-helpers/renderers/tabbable_renderer"
8
15
  end
9
16
 
10
17
  module Helpers
11
- autoload :AlertHelper, "rails-bootstrap-helpers/helpers/alert_helper"
18
+ autoload :OptionsHelper, "rails-bootstrap-helpers/helpers/options_helper"
12
19
  autoload :BaseHelper, "rails-bootstrap-helpers/helpers/base_helper"
20
+ autoload :AccordionHelper, "rails-bootstrap-helpers/helpers/accordion_helper"
21
+ autoload :UrlHelper, "rails-bootstrap-helpers/helpers/url_helper"
22
+ autoload :AlertHelper, "rails-bootstrap-helpers/helpers/alert_helper"
13
23
  autoload :ButtonHelper, "rails-bootstrap-helpers/helpers/button_helper"
14
24
  autoload :FormTagHelper, "rails-bootstrap-helpers/helpers/form_tag_helper"
15
25
  autoload :LabelHelper, "rails-bootstrap-helpers/helpers/label_helper"
16
- autoload :OptionsHelper, "rails-bootstrap-helpers/helpers/options_helper"
26
+ autoload :TagHelper, "rails-bootstrap-helpers/helpers/tag_helper"
27
+ autoload :NavigationHelper, "rails-bootstrap-helpers/helpers/navigation_helper"
17
28
  end
18
29
  end
19
30