bootstrap-view-helpers 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -28,6 +28,7 @@ Includes support for:
28
28
  * form helpers
29
29
  * submit_tag_button
30
30
  * cancel_tag_button
31
+ * alerts
31
32
 
32
33
  ## Note
33
34
 
@@ -255,3 +256,28 @@ cancel_button_tag(:info, url: '/')
255
256
  cancel_button_tag(:large, url: '/')
256
257
  cancel_button_tag('Return', :small, :warning, url: '/', id: 'my-id')
257
258
  ```
259
+
260
+ ### Alerts
261
+
262
+ [Bootstrap Documentation](http://twitter.github.io/bootstrap/components.html#alerts)
263
+ [API Documentation](http://rubydoc.info/gems/bootstrap-view-helpers/Bootstrap/AlertHelper)
264
+
265
+ ```erb
266
+ <%= alert('Default Alert') %>
267
+ <%= alert('Type :info', :info) %>
268
+ <%= alert('Type :success', :success) %>
269
+ <%= alert('Type :error', :error) %>
270
+
271
+ <%= alert('Default alert with heading', heading: 'Warning!') %>
272
+ <%= alert('No close button', close: false) %>
273
+ <%= alert("Type :block gives some more padding", :block ) %>
274
+ <%= alert("Unknown options are html attributes", id: 'my-id', class: 'my-class') %>
275
+
276
+ <%= alert :success do %>
277
+ <%= alert_heading('A List') %>
278
+ <ul>
279
+ <li>One</li>
280
+ <li>Two</li>
281
+ </ul>
282
+ <% end %>
283
+ ```
@@ -0,0 +1,82 @@
1
+ # Rails helpers for producing Bootstrap alert boxes.
2
+ #
3
+ # See: http://twitter.github.io/bootstrap/components.html#alerts
4
+ #
5
+ # @example
6
+ # <%= alert('Default alert') %>
7
+ #
8
+ # <%= alert('Watch out!', :error) %>
9
+ #
10
+ # <%= alert('This is the body', heading: 'Title') %>
11
+ #
12
+ # <%= alert :success do %>
13
+ # <%= alert_heading('A List') %>
14
+ # <ul>
15
+ # <li>One</li>
16
+ # <li>Two</li>
17
+ # </ul>
18
+ # <% end %>
19
+ module Bootstrap::AlertHelper
20
+
21
+ ALERT_ATTRIBUTES = %w(error success info block)
22
+
23
+ # @overload alert(text, alert_type, options={})
24
+ # @param text [String] text of the label
25
+ # @param alert_type [Symbol, String] if present must be one of {Bootstrap::AlertHelper::ALERT_ATTRIBUTES}
26
+ # @param options [Hash] html attributes for returned alert <div>
27
+ # @option options [String] :heading if present, include a heading in the alert
28
+ # @option options [Boolean] :close if +false+, don't include a close link ('x')
29
+ # @return [String] Returns html for alert
30
+ def alert(*args, &block)
31
+ text = args.shift unless block_given?
32
+ options = canonicalize_options(args.extract_options!)
33
+ options = ensure_class(options, 'alert')
34
+ options = add_alert_classes(options, args)
35
+ heading = options.delete(:heading)
36
+ show_close = options.delete(:close) != false
37
+
38
+ if block_given?
39
+ content_tag(:div, options) do
40
+ alert_close(show_close) +
41
+ alert_heading(heading) +
42
+ capture(&block)
43
+ end
44
+ else
45
+ content_tag(:div, options) do
46
+ alert_close(show_close) +
47
+ alert_heading(heading) +
48
+ text
49
+ end
50
+ end
51
+ end
52
+
53
+ # Return an alert box close button
54
+ #
55
+ # @return [String] html for alert close button
56
+ def alert_close(show=true)
57
+ return '' unless show
58
+ content_tag(:button, '&times;'.html_safe, class: 'close', data: {dismiss: 'alert'})
59
+ end
60
+
61
+ # Return an alert heading
62
+ #
63
+ # @return [String] html for alert heading
64
+ def alert_heading(heading)
65
+ return '' unless heading.present?
66
+ content_tag(:h4, heading)
67
+ end
68
+
69
+ private
70
+
71
+ def add_alert_classes(options, alert_attributes)
72
+ validate_alert_attributes(alert_attributes)
73
+ classes = ['alert'] + alert_attributes.map { |e| "alert-#{e}" }
74
+ ensure_class(options, classes)
75
+ end
76
+
77
+ def validate_alert_attributes(alert_attributes)
78
+ alert_attributes.each { |e| raise(InvalidAlertAttributeError, e.inspect) unless ALERT_ATTRIBUTES.include?(e.to_s) }
79
+ end
80
+
81
+
82
+ end
@@ -7,5 +7,6 @@
7
7
  <%= dropdown_item('Labels and badges', bvh_path('labels_and_badges')) %>
8
8
  <%= dropdown_item('Accordions', bvh_path('accordions')) %>
9
9
  <%= dropdown_item('Form helpers', bvh_path('form_helpers')) %>
10
+ <%= dropdown_item('Alerts', bvh_path('alerts')) %>
10
11
 
11
12
  <% end %>
@@ -0,0 +1,7 @@
1
+ <%= alert :success do %>
2
+ <%= alert_heading('A List') %>
3
+ <ul>
4
+ <li>One</li>
5
+ <li>Two</li>
6
+ </ul>
7
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= alert('Default alert with heading', heading: 'Warning!') %>
2
+
3
+ <%= alert('No close button', close: false) %>
4
+
5
+ <%= alert("Type :block gives some more padding", :block ) %>
6
+
7
+ <%= alert("Unknown options are html attributes", id: 'my-id', class: 'my-class') %>
8
+
@@ -0,0 +1,8 @@
1
+ <%= alert('Default Alert') %>
2
+
3
+ <%= alert('Type :info', :info) %>
4
+
5
+ <%= alert('Type :success', :success) %>
6
+
7
+ <%= alert('Type :error', :error) %>
8
+
@@ -9,5 +9,5 @@
9
9
  <h2>Example</h2>
10
10
  <%= render partial: 'accordions' %>
11
11
 
12
- <h2>Source</2>
12
+ <h2>Source</h2>
13
13
  <%= bvh_show_source('bootstrap_view_helpers/_accordions') %>
@@ -0,0 +1,31 @@
1
+ <h1>Alerts</h1>
2
+
3
+ <p>
4
+ <%=link_to 'Bootstrap Documentation', 'http://twitter.github.io/bootstrap/components.html#alerts' %>
5
+ <br>
6
+ <%= link_to('API Documentation', 'http://rubydoc.info/gems/bootstrap-view-helpers/Bootstrap/AlertHelper') %>
7
+ </p>
8
+
9
+ <h2>Standard Bootstrap Alert Types</h2>
10
+
11
+ <h3>Examples</h3>
12
+ <%= render partial: 'alert_types' %>
13
+
14
+ <h3>Source</h3>
15
+ <%= bvh_show_source('bootstrap_view_helpers/_alert_types') %>
16
+
17
+ <h2>Alert Options</h2>
18
+
19
+ <h3>Examples</h3>
20
+ <%= render partial: 'alert_options' %>
21
+
22
+ <h3>Source</h3>
23
+ <%= bvh_show_source('bootstrap_view_helpers/_alert_options') %>
24
+
25
+ <h2>Block Form</h2>
26
+
27
+ <h3>Examples</h3>
28
+ <%= render partial: 'alert_block' %>
29
+
30
+ <h3>Source</h3>
31
+ <%= bvh_show_source('bootstrap_view_helpers/_alert_block') %>
@@ -1,3 +1,3 @@
1
1
  module BootstrapViewHelpers
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-view-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-01 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -187,6 +187,22 @@ dependencies:
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
+ - !ruby/object:Gem::Dependency
191
+ name: binding_of_caller
192
+ requirement: !ruby/object:Gem::Requirement
193
+ none: false
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ! '>='
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
190
206
  - !ruby/object:Gem::Dependency
191
207
  name: redcarpet
192
208
  requirement: !ruby/object:Gem::Requirement
@@ -261,6 +277,7 @@ files:
261
277
  - app/assets/stylesheets/bootstrap-view-helpers/bs_docs_example.css
262
278
  - app/controllers/bootstrap_view_helpers_controller.rb
263
279
  - app/helpers/bootstrap/accordion_helper.rb
280
+ - app/helpers/bootstrap/alert_helper.rb
264
281
  - app/helpers/bootstrap/badge_helper.rb
265
282
  - app/helpers/bootstrap/button_helper.rb
266
283
  - app/helpers/bootstrap/common_helper.rb
@@ -274,9 +291,13 @@ files:
274
291
  - app/views/application/_bootstrap_view_helper_nav_bar.html.erb
275
292
  - app/views/application/_bootstrap_view_helper_side_bar.html.erb
276
293
  - app/views/bootstrap_view_helpers/_accordions.html.erb
294
+ - app/views/bootstrap_view_helpers/_alert_block.html.erb
295
+ - app/views/bootstrap_view_helpers/_alert_options.html.erb
296
+ - app/views/bootstrap_view_helpers/_alert_types.html.erb
277
297
  - app/views/bootstrap_view_helpers/_form_helper_1.html.erb
278
298
  - app/views/bootstrap_view_helpers/_icons.html.erb
279
299
  - app/views/bootstrap_view_helpers/accordions.html.erb
300
+ - app/views/bootstrap_view_helpers/alerts.html.erb
280
301
  - app/views/bootstrap_view_helpers/buttons.html.erb
281
302
  - app/views/bootstrap_view_helpers/form_helpers.html.erb
282
303
  - app/views/bootstrap_view_helpers/icons.html.erb