bh 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/CHANGELOG.md +19 -0
- data/README.md +51 -18
- data/bh.gemspec +13 -9
- data/examples/middleman/.gitignore +18 -0
- data/examples/middleman/Gemfile +6 -0
- data/examples/middleman/config.rb +1 -0
- data/examples/middleman/source/index.html.erb +158 -0
- data/examples/padrino/Gemfile +9 -0
- data/examples/padrino/app/app.rb +16 -0
- data/examples/padrino/app/views/index.html.erb +155 -0
- data/examples/padrino/config.ru +5 -0
- data/examples/padrino/config/apps.rb +5 -0
- data/examples/padrino/config/boot.rb +8 -0
- data/examples/rails/.gitignore +12 -0
- data/examples/rails/Gemfile +5 -0
- data/examples/rails/app/controllers/application_controller.rb +6 -0
- data/examples/rails/app/controllers/users_controller.rb +2 -0
- data/examples/rails/app/models/user.rb +15 -0
- data/examples/rails/app/views/application/index.html.erb +160 -0
- data/examples/rails/bin/rails +4 -0
- data/examples/rails/config.ru +4 -0
- data/examples/rails/config/application.rb +12 -0
- data/examples/rails/config/boot.rb +3 -0
- data/examples/rails/config/environment.rb +5 -0
- data/examples/rails/config/environments/development.rb +7 -0
- data/examples/rails/config/routes.rb +4 -0
- data/examples/rails/config/secrets.yml +22 -0
- data/examples/rails/log/.keep +0 -0
- data/gemfiles/Gemfile.rails-3.x +2 -0
- data/gemfiles/Gemfile.rails-4.x +2 -0
- data/lib/bh.rb +15 -4
- data/lib/bh/classes/alert_box.rb +35 -0
- data/lib/bh/classes/base.rb +125 -0
- data/lib/bh/classes/button.rb +58 -0
- data/lib/bh/classes/button_to.rb +33 -0
- data/lib/bh/classes/cdn.rb +35 -0
- data/lib/bh/classes/dropdown.rb +56 -0
- data/lib/bh/classes/icon.rb +34 -0
- data/lib/bh/classes/link_to.rb +22 -0
- data/lib/bh/classes/modal.rb +68 -0
- data/lib/bh/classes/nav.rb +37 -0
- data/lib/bh/classes/navbar.rb +78 -0
- data/lib/bh/classes/panel.rb +72 -0
- data/lib/bh/classes/panel_row.rb +13 -0
- data/lib/bh/classes/progress_bar.rb +89 -0
- data/lib/bh/classes/stack.rb +19 -0
- data/lib/bh/classes/vertical.rb +27 -0
- data/lib/bh/core_ext/middleman.rb +24 -0
- data/lib/bh/core_ext/padrino.rb +25 -0
- data/lib/bh/core_ext/rails/base_helper.rb +21 -0
- data/lib/bh/{helpers → core_ext/rails}/form/base_helper.rb +3 -1
- data/lib/bh/{helpers → core_ext/rails}/form/check_box_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/field_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/fields_for_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/fieldset_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/file_field_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/legend_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/radio_button_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/select_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/static_control_helper.rb +1 -1
- data/lib/bh/{helpers → core_ext/rails}/form/submit_helper.rb +1 -1
- data/lib/bh/{form_builders → core_ext/rails}/form_builder.rb +11 -10
- data/lib/bh/core_ext/rails/form_for_helper.rb +32 -0
- data/lib/bh/core_ext/railtie.rb +27 -0
- data/lib/bh/helpers/alert_box_helper.rb +40 -0
- data/lib/bh/helpers/button_helper.rb +35 -58
- data/lib/bh/helpers/button_to_helper.rb +48 -10
- data/lib/bh/helpers/cdn_helper.rb +11 -35
- data/lib/bh/helpers/dropdown_helper.rb +29 -62
- data/lib/bh/helpers/glyphicon_helper.rb +7 -13
- data/lib/bh/helpers/horizontal_helper.rb +35 -0
- data/lib/bh/helpers/icon_helper.rb +15 -29
- data/lib/bh/helpers/link_to_helper.rb +52 -41
- data/lib/bh/helpers/modal_helper.rb +49 -79
- data/lib/bh/helpers/nav_helper.rb +25 -40
- data/lib/bh/helpers/navbar_helper.rb +36 -170
- data/lib/bh/helpers/panel_helper.rb +45 -72
- data/lib/bh/helpers/panel_row_helper.rb +20 -38
- data/lib/bh/helpers/progress_bar_helper.rb +48 -59
- data/lib/bh/helpers/vertical_helper.rb +33 -0
- data/lib/bh/version.rb +1 -1
- data/lib/bh/views/bh/_alert_dismiss_button.html +4 -0
- data/lib/bh/views/bh/_dropdown.html.erb +5 -5
- data/lib/bh/views/bh/_dropdown_split.html.erb +5 -5
- data/lib/bh/views/bh/_modal.html.erb +5 -8
- data/lib/bh/views/bh/_navbar.html.erb +5 -0
- data/spec/padrino/button_to_helper.rb +35 -0
- data/spec/padrino_spec.rb +28 -0
- data/spec/rails/button_to_helper.rb +31 -0
- data/spec/{helpers → rails}/form/check_box_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/field_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/fields_for_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/fieldset_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/file_field_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/legend_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/radio_button_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/select_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/static_control_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form/submit_helper_spec.rb +3 -3
- data/spec/{helpers → rails}/form_for_helper_spec.rb +3 -3
- data/spec/rails_helper.rb +25 -0
- data/spec/rails_spec.rb +28 -0
- data/spec/shared/alert_box_helper.rb +62 -0
- data/spec/shared/button_helper.rb +52 -0
- data/spec/shared/button_to_helper.rb +42 -0
- data/spec/shared/cdn_helper.rb +36 -0
- data/spec/shared/dropdown_helper.rb +112 -0
- data/spec/shared/glyphicon_helper.rb +21 -0
- data/spec/shared/horizontal_helper.rb +37 -0
- data/spec/shared/icon_helper.rb +31 -0
- data/spec/shared/link_to_helper.rb +62 -0
- data/spec/shared/modal_helper.rb +104 -0
- data/spec/shared/nav_helper.rb +49 -0
- data/spec/shared/navbar_helper.rb +63 -0
- data/spec/shared/panel_helper.rb +76 -0
- data/spec/shared/panel_row_helper.rb +21 -0
- data/spec/shared/progress_bar_helper.rb +103 -0
- data/spec/shared/vertical_helper.rb +43 -0
- data/spec/spec_helper.rb +6 -29
- data/spec/support/matchers.rb +38 -0
- data/spec/support/padrino.rb +33 -0
- data/spec/support/rails.rb +27 -0
- metadata +183 -94
- data/config.rb +0 -6
- data/lib/bh/helpers/alert_helper.rb +0 -77
- data/lib/bh/helpers/base_helper.rb +0 -39
- data/lib/bh/helpers/form_for_helper.rb +0 -30
- data/lib/bh/middleman.rb +0 -39
- data/lib/bh/railtie.rb +0 -42
- data/spec/dummy/index.html.erb +0 -60
- data/spec/dummy/layouts/default.erb +0 -17
- data/spec/helpers/alert_helper_spec.rb +0 -84
- data/spec/helpers/button_helper_spec.rb +0 -100
- data/spec/helpers/button_to_helper_spec.rb +0 -25
- data/spec/helpers/cdn_helper_spec.rb +0 -100
- data/spec/helpers/dropdown_helper_spec.rb +0 -146
- data/spec/helpers/glyphicon_helper_spec.rb +0 -21
- data/spec/helpers/icon_helper_spec.rb +0 -45
- data/spec/helpers/link_to_helper_spec.rb +0 -124
- data/spec/helpers/modal_helper_spec.rb +0 -133
- data/spec/helpers/nav_helper_spec.rb +0 -53
- data/spec/helpers/navbar_helper_spec.rb +0 -194
- data/spec/helpers/panel_helper_spec.rb +0 -95
- data/spec/helpers/panel_row_helper_spec.rb +0 -27
- data/spec/helpers/progress_bar_helper_spec.rb +0 -114
@@ -1,48 +1,59 @@
|
|
1
|
-
require 'bh/
|
1
|
+
require 'bh/classes/link_to'
|
2
|
+
require 'bh/classes/alert_box'
|
3
|
+
require 'bh/classes/dropdown'
|
4
|
+
require 'bh/classes/nav'
|
5
|
+
require 'bh/classes/stack'
|
6
|
+
require 'bh/classes/vertical'
|
2
7
|
|
3
8
|
module Bh
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# @see http://getbootstrap.com/components/#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
9
|
+
module Helpers
|
10
|
+
# Overrides `link_to` to display a Bootstrap-styled link.
|
11
|
+
# Can only be used in Ruby frameworks that provide the `link_to` method.
|
12
|
+
# @see http://getbootstrap.com/components/#dropdowns
|
13
|
+
# @see http://getbootstrap.com/components/#nav
|
14
|
+
# @see http://getbootstrap.com/components/#navbar-brand-image
|
15
|
+
# @see http://getbootstrap.com/components/#navbar-links
|
16
|
+
# @see http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
|
17
|
+
# @see http://www.rubydoc.info/github/padrino/padrino-framework/Padrino/Helpers/AssetTagHelpers#link_to-instance_method
|
18
|
+
# @return [String] the HTML to display a Bootstrap-styled link.
|
19
|
+
# @overload link_to(caption, url, options = {})
|
20
|
+
# @param [#to_s] caption the caption to display in the link.
|
21
|
+
# @param [#to_s] url the URL to link to.
|
22
|
+
# @param [Hash] options the options for the original `link_to` method.
|
23
|
+
# @example Display a plain-text link inside an alert-box.
|
24
|
+
# alert_box do
|
25
|
+
# link_to 'Check the terms and conditions', '/#terms'
|
26
|
+
# end
|
27
|
+
# @overload button_to(url, options = {}, &block)
|
28
|
+
# @param [#to_s] url the URL to link to (see above).
|
29
|
+
# @param [Hash] options the options for the original `link_to` method.
|
30
|
+
# @yieldreturn [#to_s] the caption to display in the link.
|
31
|
+
# @example Display a link with HTML inside a dropdown.
|
32
|
+
# dropdown 'Menu' do
|
33
|
+
# link_to '/#terms' do
|
34
|
+
# content_tag :strong, 'Check the terms and conditions'
|
35
|
+
# end
|
36
|
+
# end
|
14
37
|
def link_to(*args, &block)
|
15
|
-
|
16
|
-
super *add_link_class!('alert-link', *args, &block), &block
|
17
|
-
elsif @navbar_vertical
|
18
|
-
super *add_link_class!('navbar-brand', *args, &block), &block
|
19
|
-
elsif @dropdown_link
|
20
|
-
content_tag :li, role: :presentation do
|
21
|
-
super *add_menu_item_attributes!(*args, &block), &block
|
22
|
-
end
|
23
|
-
elsif @nav_link
|
24
|
-
content_tag :li, super(*args, &block), nav_item_options(*args, &block)
|
25
|
-
else
|
26
|
-
super *args, &block
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
38
|
+
link_to = Bh::LinkTo.new self, *args, &block
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
options = (block_given? ? args[0] : args[1]) || {}
|
38
|
-
{class: 'active'} if current_page? options
|
39
|
-
end
|
40
|
+
link_to.append_class! :'alert-link' if Bh::Stack.find(Bh::AlertBox)
|
41
|
+
link_to.append_class! :'navbar-brand' if Bh::Stack.find(Bh::Vertical)
|
42
|
+
link_to.merge! role: :menuitem if Bh::Stack.find(Bh::Dropdown)
|
43
|
+
link_to.merge! tabindex: -1 if Bh::Stack.find(Bh::Dropdown)
|
44
|
+
html = super link_to.content, link_to.url, link_to.attributes, &nil
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
if Bh::Stack.find(Bh::Dropdown)
|
47
|
+
container = Bh::Base.new(self) { html }
|
48
|
+
container.merge! role: :presentation
|
49
|
+
container.render_tag :li
|
50
|
+
elsif Bh::Stack.find(Bh::Nav)
|
51
|
+
container = Bh::Base.new(self) { html }
|
52
|
+
container.append_class! :active if link_to.current_page?
|
53
|
+
container.render_tag :li
|
54
|
+
else
|
55
|
+
html
|
56
|
+
end
|
46
57
|
end
|
47
58
|
end
|
48
|
-
end
|
59
|
+
end
|
@@ -1,85 +1,55 @@
|
|
1
|
-
require 'bh/
|
1
|
+
require 'bh/classes/modal'
|
2
2
|
|
3
3
|
module Bh
|
4
|
-
|
5
|
-
|
6
|
-
module ModalHelper
|
7
|
-
include BaseHelper
|
8
|
-
|
9
|
-
# Returns an HTML block tag that follows the Bootstrap documentation
|
10
|
-
# on how to display *modals*.
|
11
|
-
#
|
12
|
-
# The content of the modal can either be passed as the first parameter (in
|
13
|
-
# which case, the options are the second parameter), or as a block (in
|
14
|
-
# which case, the options are the first paramter).
|
15
|
-
# @example An modal with plain-text content passed as the first parameter.
|
16
|
-
# modal 'Your profile was updated!', context: :info, title: 'Profile'
|
17
|
-
# @example A panel with HTML content passed as a block.
|
18
|
-
# modal context: :info, title: 'Profile' do
|
19
|
-
# content_tag :div, "Your profile was updated!", class: 'modal-footer'
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# @return [String] an HTML block tag for a panel.
|
23
|
-
# @param [String] content_or_options_with_block the content to display in
|
24
|
-
# the panel.
|
25
|
-
# @param [Hash] options the display options for the panel.
|
26
|
-
# @option options [#to_s] :title ('Modal') the title to display inside the modal.
|
27
|
-
# @option options [#to_s] :body if present, the panel will include the
|
28
|
-
# provided text wrapped in a 'modal-body' block, for proper padding
|
29
|
-
# @option options [#to_s] :size the size of the modal.
|
30
|
-
# @option options [Hash] :button the options for the "toggle" button.
|
31
|
-
# * :caption (#to_s) ('Modal') the caption for the "toggle" button.
|
32
|
-
# * :context (#to_s) (:default) the context for the "toggle" button,
|
33
|
-
# which determines the button color
|
34
|
-
# * :size (#to_s) the size of the "toggle" button.
|
4
|
+
module Helpers
|
5
|
+
# Displays a Bootstrap-styled modal.
|
35
6
|
# @see http://getbootstrap.com/javascript/#modals
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
content_tag :div, body, class: 'modal-body' if body
|
7
|
+
# @return [String] the HTML to display a Bootstrap-styled modal.
|
8
|
+
# @overload modal(body, options = {})
|
9
|
+
# @param [#to_s] body the content to display as the modal body.
|
10
|
+
# @param [Hash] options the options for the modal. Any option not listed
|
11
|
+
# below is ignored, except for `:id` which is passed as an HTML
|
12
|
+
# attribute to the modal’s `<div>`.
|
13
|
+
# @option options [#to_s] :title ('Modal') the title of the modal.
|
14
|
+
# @option options [#to_s] :body the content to display as the modal body.
|
15
|
+
# Using this option is equivalent to passing the body as an argument.
|
16
|
+
# @option options [#to_s] :size the size of the modal. Can be `:large`
|
17
|
+
# (alias `:lg`) or `:small` (alias `:sm`).
|
18
|
+
# @option options [Hash] :button the options for the toggle button.
|
19
|
+
# * :caption (#to_s) ('Modal') the caption of the toggle button.
|
20
|
+
# * :context (#to_s) (:default) the contextual alternative to apply to
|
21
|
+
# the toggle button. Can be `:danger`, `:info`, `:link`, `:primary`,
|
22
|
+
# `:success` or `:warning`.
|
23
|
+
# * :size (#to_s) the size of the toggle button. Can be `:extra_small`
|
24
|
+
# (alias `:xs`), `:large` (alias `:lg`) or `:small` (alias `:sm`).
|
25
|
+
# * :layout (#to_s) if set to `:block`, span the button for the full
|
26
|
+
# width of the parent.
|
27
|
+
# @example Display a simple modal toggled by a blue button.
|
28
|
+
# modal 'You clicked me!', title: 'Click me', button: {context: :info}
|
29
|
+
# @overload modal(options = {}, &block)
|
30
|
+
# @param [Hash] options the options for the modal (see above).
|
31
|
+
# @yieldreturn [#to_s] the content to display in the modal.
|
32
|
+
# @example Display a modal with HTML content.
|
33
|
+
# modal title: 'Click me' do
|
34
|
+
# content_tag :div, class: 'modal-body' do
|
35
|
+
# content_tag :em, 'You clicked me!'
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
def modal(*args, &block)
|
39
|
+
modal = Bh::Modal.new self, *args, &block
|
40
|
+
modal.extract! :button, :size, :body, :title, :id
|
41
|
+
|
42
|
+
modal.extract_from :button, [:context, :size, :layout, :caption]
|
43
|
+
modal.append_class_to! :button, :btn
|
44
|
+
modal.append_class_to! :button, modal.button_context_class
|
45
|
+
modal.append_class_to! :button, modal.button_size_class
|
46
|
+
modal.merge! button: {caption: modal.caption}
|
47
|
+
|
48
|
+
modal.append_class_to! :div, :'modal-dialog'
|
49
|
+
modal.append_class_to! :div, modal.dialog_size_class
|
50
|
+
modal.merge! div: {title: modal.title, id: modal.id}
|
51
|
+
|
52
|
+
modal.render_partial 'modal'
|
83
53
|
end
|
84
54
|
end
|
85
55
|
end
|
@@ -1,51 +1,36 @@
|
|
1
|
-
require 'bh/
|
1
|
+
require 'bh/classes/nav'
|
2
|
+
require 'bh/classes/navbar'
|
2
3
|
|
3
4
|
module Bh
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
# @example An justified nav with two links.
|
18
|
-
# nav layout: :justified do
|
5
|
+
module Helpers
|
6
|
+
# Displays a Bootstrap-styled nav.
|
7
|
+
# @see http://getbootstrap.com/components/#nav
|
8
|
+
# @return [String] the HTML to display a Bootstrap-styled nav.
|
9
|
+
# @param [Hash] options the options for the nav. Any option not listed below
|
10
|
+
# is passed as an HTML attribute to the alert’s `<ul>`.
|
11
|
+
# @option options [#to_s] :as (:tabs) the style of the nav. Can be `:tabs`
|
12
|
+
# or `:pills`.
|
13
|
+
# @option options [#to_s] :layout the layout of the nav. Can be
|
14
|
+
# `:justified` or `:stacked`.
|
15
|
+
# @yieldreturn [#to_s] the content to display in the nav.
|
16
|
+
# @example Display a pills-styled nav with a link.
|
17
|
+
# nav as: :pills do
|
19
18
|
# link_to 'Home', '/'
|
20
|
-
# link_to 'Profile', '/profile'
|
21
19
|
# end
|
22
|
-
#
|
23
|
-
# @return [String] an HTML block tag for a nav.
|
24
|
-
# @param [Hash] options the display options for the nav.
|
25
|
-
# @option options [#to_s] :as ('tabs') the style to use for the nav.
|
26
|
-
# Valid values are: :tabs and :pills.
|
27
|
-
# @option options [#to_s] :layout (nil) if set, the layout of the nav.
|
28
|
-
# Valid values are: :justified and :stacked.
|
29
|
-
# @yield block the content of the nav
|
30
|
-
# @see http://getbootstrap.com/components/#nav
|
31
20
|
def nav(options = {}, &block)
|
32
|
-
|
33
|
-
nav
|
34
|
-
nav.tap{ @nav_link = false }
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
21
|
+
nav = Bh::Nav.new(self, options, &block)
|
22
|
+
nav.extract! :as, :layout
|
38
23
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
append_class! options, 'navbar-nav'
|
24
|
+
nav.append_class! :nav
|
25
|
+
if Bh::Stack.find(Bh::Navbar)
|
26
|
+
nav.append_class! :'navbar-nav'
|
43
27
|
else
|
44
|
-
|
45
|
-
append_class!
|
46
|
-
append_class!
|
28
|
+
nav.merge! role: :tablist
|
29
|
+
nav.append_class! nav.style_class
|
30
|
+
nav.append_class! nav.layout_class
|
47
31
|
end
|
48
|
-
|
32
|
+
|
33
|
+
nav.render_tag :ul
|
49
34
|
end
|
50
35
|
end
|
51
36
|
end
|
@@ -1,182 +1,48 @@
|
|
1
|
-
require 'bh/helpers/
|
1
|
+
require 'bh/helpers/horizontal_helper'
|
2
|
+
require 'bh/helpers/vertical_helper'
|
2
3
|
|
3
4
|
module Bh
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# The skeleton of the nav is a <div> container inside a <nav> tag; its
|
13
|
-
# content is passed as a block.
|
14
|
-
#
|
15
|
-
# Bootstrap allows to differentiate between the content of a navtab that
|
16
|
-
# should remain visible even on a mobile (in a 'vertical' layout) and the
|
17
|
-
# content that should only be visible when there is enough horizontal space
|
18
|
-
# (in a 'horizontal') layout.
|
19
|
-
#
|
20
|
-
# The +vertical+ and +horizontal+ helpers can be used inside a navbar to
|
21
|
-
# specify these types of content.
|
22
|
-
# @example An inverted navbar with the company logo and two links.
|
23
|
-
# navbar inverted: false do
|
24
|
-
# vertical image_tag('logo')
|
25
|
-
# horizontal nav do
|
26
|
-
# link_to 'Home', '/'
|
27
|
-
# link_to 'Profile', '/profile'
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# @return [String] an HTML block tag for a navbar.
|
32
|
-
# @param [Hash] options the display options for the nav.
|
5
|
+
module Helpers
|
6
|
+
# Displays a Bootstrap-styled navbar.
|
7
|
+
# @see http://getbootstrap.com/components/#navbar
|
8
|
+
# @return [String] the HTML to display a Bootstrap-styled navbar.
|
9
|
+
# @param [Hash] options the options for the navbar. Any option not listed
|
10
|
+
# below is ignored, except for `:id` which is passed as an HTML
|
11
|
+
# attribute to the navbar’s collapsable `<div>`.
|
33
12
|
# @option options [Boolean] :fluid (false) whether to use a fluid container
|
34
13
|
# to surround the navbar content.
|
35
14
|
# @option options [Boolean] :inverted (false) whether to use an inverted
|
36
15
|
# palette of colors.
|
37
|
-
# @option options [#to_s] :position
|
38
|
-
#
|
39
|
-
#
|
16
|
+
# @option options [#to_s] :position the position of the navbar. Can be
|
17
|
+
# `:top` (alias `:fixed_top`), `:bottom` (alias `:fixed_bottom`) or
|
18
|
+
# `:static` (alias `:static_top`).
|
40
19
|
# @option options [#to_s] :padding (70) if position is set to :top or
|
41
|
-
# :bottom,
|
42
|
-
#
|
43
|
-
# @
|
44
|
-
# @
|
20
|
+
# :bottom, the padding to at the top (or bottom) of <body> to prevent the
|
21
|
+
# navbar from overlaying the content.
|
22
|
+
# @yieldreturn [#to_s] the content to display in the navbar.
|
23
|
+
# @example Display an inverted navbar with three links.
|
24
|
+
# navbar inverted: true do
|
25
|
+
# vertical do
|
26
|
+
# image_tag('logo')
|
27
|
+
# end
|
28
|
+
# horizontal do
|
29
|
+
# nav do
|
30
|
+
# link_to 'Home', '/'
|
31
|
+
# link_to 'Profile', '/profile'
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
# end
|
45
35
|
def navbar(options = {}, &block)
|
46
|
-
|
47
|
-
|
48
|
-
navbar = safe_join [navbar_style_tag(options), nav_tag].compact, "\n"
|
49
|
-
navbar.tap{ @navbar_id = nil }
|
50
|
-
end
|
51
|
-
|
52
|
-
def vertical(content_or_options_with_block = nil, options = nil, &block)
|
53
|
-
if block_given?
|
54
|
-
vertical_string (content_or_options_with_block || {}), &block
|
55
|
-
else
|
56
|
-
vertical_string (options || {}), &Proc.new { content_or_options_with_block }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def horizontal(content_or_options_with_block = nil, options = nil, &block)
|
61
|
-
if block_given?
|
62
|
-
horizontal_string (content_or_options_with_block || {}), &block
|
63
|
-
else
|
64
|
-
horizontal_string (options || {}), &Proc.new { content_or_options_with_block }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def navbar_string(options = {}, &block)
|
71
|
-
content_tag :nav, role: 'navigation', class: navbar_class(options) do
|
72
|
-
content_tag :div, class: navbar_container_class(options), &block
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# @private
|
77
|
-
# The fixed navbar will overlay your other content, unless you add padding
|
78
|
-
# to the top or bottom of the <body>. Try out your own values or use our
|
79
|
-
# snippet below. Tip: By default, the navbar is 50px high.
|
80
|
-
# @see http://getbootstrap.com/components/#navbar-fixed-top
|
81
|
-
def navbar_style_tag(options = {})
|
82
|
-
padding_value = options.fetch :padding, 70
|
83
|
-
if padding_value && padding_type = padding_type_for(options[:position])
|
84
|
-
content_tag :style, "body {padding-#{padding_type}: #{padding_value}px}"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def padding_type_for(position)
|
89
|
-
/fixed-(?<type>top|bottom)$/ =~ navbar_position_class_for(position)
|
90
|
-
type
|
91
|
-
end
|
36
|
+
navbar = Bh::Navbar.new(self, options, &block)
|
37
|
+
navbar.extract! :inverted, :position, :padding, :fluid, :id
|
92
38
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
append_class! options, 'navbar-header'
|
99
|
-
vertical = content_tag :div, options do
|
100
|
-
safe_join [toggle_button, capture(&block)], "\n"
|
101
|
-
end
|
102
|
-
vertical.tap{ @navbar_vertical = false }
|
103
|
-
end
|
104
|
-
|
105
|
-
def horizontal_string(options = {}, &block)
|
106
|
-
append_class! options, 'collapse navbar-collapse'
|
107
|
-
options[:id] = navbar_id
|
108
|
-
content_tag :div, options, &block
|
109
|
-
end
|
110
|
-
|
111
|
-
def toggle_button(options = {})
|
112
|
-
options['type'] = 'button'
|
113
|
-
options['class'] = 'navbar-toggle'
|
114
|
-
options['data-toggle'] = 'collapse'
|
115
|
-
options['data-target'] = "##{navbar_id}"
|
116
|
-
content_tag :button, options do
|
117
|
-
safe_join [toggle_text, toggle_bar, toggle_bar, toggle_bar], "\n"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def toggle_text
|
122
|
-
content_tag :span, 'Toggle navigation', class: 'sr-only'
|
123
|
-
end
|
124
|
-
|
125
|
-
def toggle_bar
|
126
|
-
content_tag :span, nil, class: 'icon-bar'
|
127
|
-
end
|
128
|
-
|
129
|
-
private
|
39
|
+
navbar.append_class_to! :navigation, :navbar
|
40
|
+
navbar.append_class_to! :navigation, navbar.style_class
|
41
|
+
navbar.append_class_to! :navigation, navbar.position_class
|
42
|
+
navbar.append_class_to! :div, navbar.layout_class
|
43
|
+
navbar.prepend_html! navbar.body_padding_style
|
130
44
|
|
131
|
-
|
132
|
-
"navbar-collapse-#{@navbar_id}"
|
133
|
-
end
|
134
|
-
|
135
|
-
def navbar_class(options = {})
|
136
|
-
style = options[:inverted] ? 'inverse' : 'default'
|
137
|
-
position = navbar_position_class_for options[:position]
|
138
|
-
append_class! options, 'navbar'
|
139
|
-
append_class! options, "navbar-#{style}"
|
140
|
-
append_class! options, "navbar-#{position}" if position
|
141
|
-
options[:class]
|
142
|
-
end
|
143
|
-
|
144
|
-
def navbar_position_class_for(position)
|
145
|
-
case position.to_s
|
146
|
-
when 'static', 'static_top' then 'static-top'
|
147
|
-
when 'top', 'fixed_top' then 'fixed-top'
|
148
|
-
when 'bottom', 'fixed_bottom' then 'fixed-bottom'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def navbar_container_class(options = {})
|
153
|
-
options[:fluid] ? 'container-fluid' : 'container'
|
45
|
+
navbar.render_partial 'navbar'
|
154
46
|
end
|
155
47
|
end
|
156
|
-
end
|
157
|
-
|
158
|
-
|
159
|
-
# STILL TO DO
|
160
|
-
# 2) Add class to form and button and nav and p inside navbar
|
161
|
-
|
162
|
-
|
163
|
-
#
|
164
|
-
# <%= navbar do %>
|
165
|
-
# <%= vertical do %>
|
166
|
-
# <%= link_to image_tag('/assets/fullscreen-standard-logo-white.png', alt: 'Fullscreen'), root_path %>
|
167
|
-
# <% end %>
|
168
|
-
# <%= horizontal do %>
|
169
|
-
# <%= nav do %>
|
170
|
-
# <%= link_to 'Campaigns', root_path %>
|
171
|
-
# <%= link_to 'Users', users_path if current_user.admin? %>
|
172
|
-
# <% end %>
|
173
|
-
# <%= nav class: 'navbar-right' do %>
|
174
|
-
# <!-- button_to needs to:
|
175
|
-
# * be surrounded in <li> AND use navbar-form inside a navbar
|
176
|
-
# * add navbar-btn is inside a navbar, else add btn
|
177
|
-
# -->
|
178
|
-
# <%= button_to 'Sign out', destroy_user_session_path, class: 'btn-link', method: :delete %>
|
179
|
-
# <% end %>
|
180
|
-
# <% end %>
|
181
|
-
# <% end if user_signed_in? %>
|
182
|
-
#
|
48
|
+
end
|