bh 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6522abb89dd53d34215f678b086d1e9414181039
4
- data.tar.gz: ce5a63947bd03e86eef43b9ea3801d8692605447
3
+ metadata.gz: bfa65b892278f33239299fce8ca41f8143bd0b21
4
+ data.tar.gz: c942fc8e67fad1ade0d91817d92e80d6b53dc9da
5
5
  SHA512:
6
- metadata.gz: 154e1ec61fee0870b2513f76ec23d7c4be8dc7c8dba2b4a2d8cc1ef3be493eebeb9f405c8f6e9e1557908d8d871df66e6e426b01d6b5f9c06e6128c6f7223e30
7
- data.tar.gz: 85e4fe4953a9cc6a6a1b221c76af892aecd330c22e4a499627298f748be4b0d7d938d831e815738e65154424b34a4a96ea977716816efa0e8cc0cd182a36f7ad
6
+ metadata.gz: 88f80274975d5bd6dbab430908032bbbf8f837d7e96d057769e62115a965594a0a3bfe990318d64cd7d9930d0c042fce831741ef3d5eb18f7fcc6a892fb61a1e
7
+ data.tar.gz: a7224ebd07b8f8443e61b37eca57afbfdf9a1eb392266d3ed113673b4b136dbe0b4c8590a5c70c3be26517ef60846232e162a7c18474d61d347131d4f15f0e4e
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 0.0.8 - 2014-08-25
10
+
11
+ * [FEATURE] Add `button_to` helper
12
+ * [FEATURE] Add `navbar` helper
13
+
9
14
  ## 0.0.7 - 2014-08-25
10
15
 
11
16
  * [FEATURE] Add `nav` helper
data/README.md CHANGED
@@ -46,7 +46,7 @@ How to install
46
46
 
47
47
  Bh is meant to be included in Rails apps by adding this line to the Gemfile:
48
48
 
49
- gem 'bh', '~> 0.0.7'
49
+ gem 'bh', '~> 0.0.8'
50
50
 
51
51
  Since the gem follows [Semantic Versioning](http://semver.org),
52
52
  indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
@@ -10,9 +10,16 @@ module Bh
10
10
 
11
11
  private
12
12
 
13
- def append_class!(hash, new_class)
14
- existing_class = hash[:class]
15
- hash[:class] = [existing_class, new_class].compact.join ' '
13
+ def append_class!(hash, new_class, attribute = :class)
14
+ existing_class = hash[attribute]
15
+ hash[attribute] = [existing_class, new_class].compact.join ' '
16
+ end
17
+
18
+ def append_class_as!(attribute, new_class, *args, &block)
19
+ html_options = (block_given? ? args[1] : args[2]) || {}
20
+ append_class! html_options, new_class, attribute
21
+ block_given? ? args[1] = html_options : args[2] = html_options
22
+ args
16
23
  end
17
24
  end
18
25
  end
@@ -0,0 +1,19 @@
1
+ require 'bh/helpers/base_helper'
2
+
3
+ module Bh
4
+ module ButtonToHelper
5
+ include BaseHelper
6
+
7
+ # Overrides ActionView +button_to+ to be able to add the 'btn' class
8
+ # to the link (or 'navbar-btn' if inside a navbar).
9
+ # @see http://getbootstrap.com/css/#buttons
10
+ # @see http://getbootstrap.com/components/#navbar-buttons
11
+ def button_to(*args, &block)
12
+ args = append_class_as! :class, 'btn', *args, &block
13
+ if @navbar_id
14
+ args = append_class_as! :form_class, 'navbar-form', *args, &block
15
+ end
16
+ super *args, &block
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'bh/helpers/base_helper'
2
+
3
+ module Bh
4
+ module LinkToHelper
5
+ include BaseHelper
6
+
7
+ # Overrides ActionView +link_to+ to be able to add the 'alert-link' class
8
+ # to the link in case the link is inside of an alert.
9
+ # @see http://getbootstrap.com/components/#alerts-links
10
+ # Overrides ActionView +link_to+ to be able to surround the link in a
11
+ # '<li>' item in case the link is inside of a nav.
12
+ # Overrides ActionView +link_to+ to be able to add the 'navbar-brand'
13
+ # class to the link in case the link is inside of an alert.
14
+ def link_to(*args, &block)
15
+ args = add_link_class!('alert-link', *args, &block) if @alert_link
16
+ args = add_link_class!('navbar-brand', *args, &block) if @navbar_vertical
17
+ link = super *args, &block
18
+ @nav_link ? content_tag(:li, link, nav_list_item_options(*args, &block)) : link
19
+ end
20
+
21
+ private
22
+
23
+ def add_link_class!(new_class, *args, &block)
24
+ append_class_as! :class, new_class, *args, &block
25
+ end
26
+
27
+ def nav_list_item_options(*args, &block)
28
+ options = (block_given? ? args[0] : args[1]) || {}
29
+ {class: 'active'} if current_page? options
30
+ end
31
+ end
32
+ end
@@ -30,29 +30,22 @@ module Bh
30
30
  # @see http://getbootstrap.com/components/#nav
31
31
  def nav(options = {}, &block)
32
32
  @nav_link = true
33
- nav = content_tag :ul, role: 'tablist', class: nav_class(options), &block
33
+ nav = content_tag :ul, nav_options(options), &block
34
34
  nav.tap{ @nav_link = false }
35
35
  end
36
36
 
37
- # Overrides ActionView +link_to+ to be able to surround the link in a
38
- # '<li>' item in case the link is inside of a nav.
39
- def link_to(*args, &block)
40
- link = super *args, &block
41
- @nav_link ? content_tag(:li, link, nav_list_item_options(*args)) : link
42
- end
43
-
44
37
  private
45
38
 
46
- def nav_list_item_options(*args)
47
- options = (block_given? ? args[0] : args[1]) || {}
48
- {class: 'active'} if current_page? options
49
- end
50
-
51
- def nav_class(options = {})
39
+ def nav_options(options = {})
52
40
  append_class! options, 'nav'
53
- append_class! options, "nav-#{options.fetch :as, 'tabs'}"
54
- append_class! options, "nav-#{options[:layout]}" if options[:layout]
55
- options[:class]
41
+ if @navbar_id
42
+ append_class! options, 'navbar-nav'
43
+ else
44
+ options[:role] = 'tablist'
45
+ append_class! options, "nav-#{options.fetch :as, 'tabs'}"
46
+ append_class! options, "nav-#{options[:layout]}" if options[:layout]
47
+ end
48
+ options.slice :role, :class
56
49
  end
57
50
  end
58
51
  end
@@ -0,0 +1,182 @@
1
+ require 'bh/helpers/base_helper'
2
+
3
+ module Bh
4
+ # Provides methods to include navbars.
5
+ # @see http://getbootstrap.com/components/#navbar
6
+ module NavbarHelper
7
+ include BaseHelper
8
+
9
+ # Returns an HTML block tag that follows the Bootstrap documentation
10
+ # on how to display *navbars*.
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.
33
+ # @option options [Boolean] :fluid (false) whether to use a fluid container
34
+ # to surround the navbar content.
35
+ # @option options [Boolean] :inverted (false) whether to use an inverted
36
+ # palette of colors.
37
+ # @option options [#to_s] :position (nil) if set, the position of the
38
+ # navbar. Valid values are: :top (alias :fixed_top), :bottom
39
+ # (alias :fixed_bottom) and :static (alias :static_top).
40
+ # @option options [#to_s] :padding (70) if position is set to :top or
41
+ # :bottom, then this padding will be added at the top (or bottom) of
42
+ # <body> to prevent the navbar from overlaying the content.
43
+ # @yield block the content of the nav
44
+ # @see http://getbootstrap.com/components/#navbar
45
+ def navbar(options = {}, &block)
46
+ @navbar_id = rand 10**7
47
+ nav_tag = navbar_string options, &block
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
92
+
93
+ # Yields the block as the vertical part of the navbar and sets a variable
94
+ # so that every +link_to+ helper called inside the block gets the
95
+ # "navbar-brand" class added, for links to look better.
96
+ def vertical_string(options = {}, &block)
97
+ @navbar_vertical = true
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
130
+
131
+ def navbar_id
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'
154
+ end
155
+ 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
+ #
data/lib/bh/railtie.rb CHANGED
@@ -1,25 +1,29 @@
1
1
  require 'bh/helpers/alert_helper'
2
+ require 'bh/helpers/button_to_helper'
2
3
  require 'bh/helpers/cdn_helper'
3
4
  require 'bh/helpers/form_for_helper'
4
5
  require 'bh/helpers/glyphicon_helper'
6
+ require 'bh/helpers/link_to_helper'
5
7
  require 'bh/helpers/modal_helper'
6
8
  require 'bh/helpers/nav_helper'
9
+ require 'bh/helpers/navbar_helper'
7
10
  require 'bh/helpers/panel_helper'
8
11
  require 'bh/helpers/panel_row_helper'
9
- require 'bh/helpers/url_helper'
10
12
 
11
13
  module Bh
12
14
  class Railtie < Rails::Railtie
13
15
  initializer 'bh.add_helpers' do
14
16
  ActionView::Base.send :include, AlertHelper
17
+ ActionView::Base.send :include, ButtonToHelper
15
18
  ActionView::Base.send :include, CdnHelper
16
19
  ActionView::Base.send :include, FormForHelper
17
20
  ActionView::Base.send :include, GlyphiconHelper
21
+ ActionView::Base.send :include, LinkToHelper
18
22
  ActionView::Base.send :include, ModalHelper
19
23
  ActionView::Base.send :include, NavHelper
24
+ ActionView::Base.send :include, NavbarHelper
20
25
  ActionView::Base.send :include, PanelHelper
21
26
  ActionView::Base.send :include, PanelRowHelper
22
- ActionView::Base.send :include, UrlHelper
23
27
  end
24
28
 
25
29
  initializer 'bh.add_views' do |app|
data/lib/bh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bh
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -1,10 +1,11 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'spec_helper'
4
+
4
5
  require 'bh/helpers/alert_helper'
5
- require 'bh/helpers/url_helper'
6
+ require 'bh/helpers/link_to_helper'
6
7
  include Bh::AlertHelper
7
- include Bh::UrlHelper
8
+ include Bh::LinkToHelper
8
9
 
9
10
  describe 'alert_box' do
10
11
  describe 'accepts as parameters:' do
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ require 'bh/helpers/button_to_helper'
4
+ require 'bh/helpers/navbar_helper'
5
+
6
+ include Bh::ButtonToHelper
7
+ include Bh::NavbarHelper
8
+
9
+ describe 'button_to' do
10
+ let(:protect_against_forgery?) { false }
11
+ attr_accessor :output_buffer
12
+ let(:url) { '/' }
13
+
14
+ context 'used without a block' do
15
+ let(:button) { button_to 'Home', url }
16
+
17
+ specify 'by default, applies the "btn" class' do
18
+ expect(button).to include 'input class="btn" type="submit" value="Home"'
19
+ end
20
+
21
+ specify 'inside a navbar, also applies the "navbar-form" class to the form' do
22
+ expect(navbar { button }).to match %r{<form .+?class="navbar-form" .+?input class="btn"}
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+ require 'action_dispatch'
3
+
4
+ require 'bh/helpers/alert_helper'
5
+ require 'bh/helpers/link_to_helper'
6
+ require 'bh/helpers/nav_helper'
7
+ require 'bh/helpers/navbar_helper'
8
+
9
+ include Bh::AlertHelper
10
+ include Bh::LinkToHelper
11
+ include Bh::NavHelper
12
+ include Bh::NavbarHelper
13
+
14
+ describe 'link_to' do
15
+ let(:request) { ActionDispatch::Request.new request_options }
16
+ let(:request_options) { {'REQUEST_METHOD' => 'GET'} }
17
+ let(:url) { '/' }
18
+
19
+ context 'used without a block' do
20
+ let(:link) { link_to 'Home', url }
21
+
22
+ specify 'by default, does not apply the "alert-link" class' do
23
+ expect(link).not_to include 'alert-link'
24
+ end
25
+
26
+ specify 'inside an alert, applies the "alert-link"' do
27
+ expect(alert_box { link }).to include 'alert-link'
28
+ end
29
+
30
+ specify 'by default, does not apply the "navbar-brand" class' do
31
+ expect(link).not_to include 'navbar-brand'
32
+ end
33
+
34
+ specify 'inside the vertical part of a navbar, applies the "navbar-brand"' do
35
+ expect(navbar { vertical { link } }).to include 'navbar-brand'
36
+ end
37
+
38
+ specify 'by default, does not surround the link in a list item' do
39
+ expect(link).not_to include '<li>'
40
+ end
41
+
42
+ context 'inside a nav' do
43
+ let(:html) { nav { link } }
44
+
45
+ specify 'surrounds the link in a list item' do
46
+ expect(html).to include '<li><a href="/">Home</a></li>'
47
+ end
48
+
49
+ specify 'by default, does not apply the "active" class' do
50
+ expect(link).not_to include 'active'
51
+ end
52
+
53
+ context 'given the link points to the current page, applies the "active" class' do
54
+ let(:url) { '' }
55
+ it { expect(html).to include 'li class="active"' }
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'used with a block' do
61
+ let(:link) { link_to(url) { 'Home' } }
62
+
63
+ specify 'by default, does not apply the "alert-link" class' do
64
+ expect(link).not_to include 'alert-link'
65
+ end
66
+
67
+ specify 'inside an alert, applies the "alert-link"' do
68
+ expect(alert_box { link }).to include 'alert-link'
69
+ end
70
+
71
+ specify 'by default, does not apply the "navbar-brand" class' do
72
+ expect(link).not_to include 'navbar-brand'
73
+ end
74
+
75
+ specify 'inside the vertical part of a navbar, applies the "navbar-brand"' do
76
+ expect(navbar { vertical { link } }).to include 'navbar-brand'
77
+ end
78
+
79
+ specify 'by default, does not surround the link in a list item' do
80
+ expect(link).not_to include '<li>'
81
+ end
82
+
83
+ context 'inside a nav' do
84
+ let(:html) { nav { link } }
85
+
86
+ specify 'surrounds the link in a list item' do
87
+ expect(html).to include '<li><a href="/">Home</a></li>'
88
+ end
89
+
90
+ specify 'by default, does not apply the "active" class' do
91
+ expect(link).not_to include 'active'
92
+ end
93
+
94
+ context 'given the link points to the current page, applies the "active" class' do
95
+ let(:url) { '' }
96
+ it { expect(html).to include 'li class="active"' }
97
+ end
98
+ end
99
+ end
100
+ end
@@ -1,10 +1,11 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'spec_helper'
4
- require 'action_dispatch'
5
4
  require 'bh/helpers/nav_helper'
5
+ require 'bh/helpers/navbar_helper'
6
6
 
7
7
  include Bh::NavHelper
8
+ include Bh::NavbarHelper
8
9
 
9
10
  describe 'nav' do
10
11
  let(:html) { nav options, &block }
@@ -43,19 +44,10 @@ describe 'nav' do
43
44
  end
44
45
  end
45
46
 
46
- describe 'given a +link_to+ in the content' do
47
- let(:block) { Proc.new { link_to 'Home', url} }
48
- let(:url) { '/any-page' }
49
- let(:request) { ActionDispatch::Request.new request_options }
50
- let(:request_options) { {'REQUEST_METHOD' => 'GET'} }
51
-
52
- specify 'surrounds the link in a list item' do
53
- expect(html).to include '<li><a href="/any-page">Home</a></li>'
54
- end
55
-
56
- context 'sets the "active" class if the link points to the same page' do
57
- let(:url) { '' }
58
- it { expect(html).to include 'li class="active"' }
47
+ describe 'within a navbar' do
48
+ let(:html) { navbar { nav options, &block } }
49
+ specify 'applies roles and classes specific to navbar' do
50
+ expect(html).to include 'ul class="nav navbar-nav">'
59
51
  end
60
52
  end
61
53
  end
@@ -0,0 +1,194 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'bh/helpers/navbar_helper'
5
+ require 'bh/helpers/nav_helper'
6
+
7
+ include Bh::NavbarHelper
8
+ include Bh::NavHelper
9
+
10
+ describe 'navbar' do
11
+ let(:html) { navbar options, &block }
12
+ let(:block) { Proc.new {} }
13
+ let(:options) { {} }
14
+
15
+ specify 'applies Boostrap attributes to the navbar' do
16
+ expect(html).to match %r{<nav.+? role="navigation">}
17
+ end
18
+
19
+ describe 'with the :fluid option' do
20
+ specify 'not set, adds a "container" div to the navbar' do
21
+ expect(html).to include '<div class="container">'
22
+ end
23
+
24
+ context 'set to false, adds a "container" div to the navbar' do
25
+ let(:options) { {fluid: false} }
26
+ it { expect(html).to include '<div class="container">' }
27
+ end
28
+
29
+ context 'set to true, adds a "container-fluid" div to the navbar' do
30
+ let(:options) { {fluid: true} }
31
+ it { expect(html).to include '<div class="container-fluid">' }
32
+ end
33
+ end
34
+
35
+ describe 'with the :inverted option' do
36
+ specify 'not set, shows a "default" navbar' do
37
+ expect(html).to include 'nav class="navbar navbar-default"'
38
+ end
39
+
40
+ context 'set to false, shows a "default" nav' do
41
+ let(:options) { {inverted: false} }
42
+ it { expect(html).to include 'nav class="navbar navbar-default"' }
43
+ end
44
+
45
+ context 'set to true, shows an "inverse" nav' do
46
+ let(:options) { {inverted: true} }
47
+ it { expect(html).to include 'nav class="navbar navbar-inverse"' }
48
+ end
49
+ end
50
+
51
+ describe 'with the :position option' do
52
+ specify 'not set, does not set a navbar position' do
53
+ expect(html).to include 'nav class="navbar navbar-default"'
54
+ end
55
+
56
+ context 'set to :static, shows the navbar at the top (static) without padding' do
57
+ let(:options) { {position: :static} }
58
+ it { expect(html).to include 'nav class="navbar navbar-default navbar-static-top"' }
59
+ it { expect(html).not_to include 'padding' }
60
+ end
61
+
62
+ context 'set to :static_top, shows the navbar at the top (static) without padding' do
63
+ let(:options) { {position: :static_top} }
64
+ it { expect(html).to include 'nav class="navbar navbar-default navbar-static-top"' }
65
+ it { expect(html).not_to include 'padding' }
66
+ end
67
+
68
+ context 'set to :top, shows the navbar at the top (fixed)' do
69
+ let(:options) { {position: :top} }
70
+ it { expect(html).to include 'nav class="navbar navbar-default navbar-fixed-top"' }
71
+
72
+ context 'with the :padding' do
73
+ specify 'not set, adds 70px to the top padding of the body' do
74
+ expect(html).to include '<style>body {padding-top: 70px}</style>'
75
+ end
76
+
77
+ context 'set to a value, adds those pixels to the top padding of the body' do
78
+ let(:options) { {position: :top, padding: 100} }
79
+
80
+ it { expect(html).to include '<style>body {padding-top: 100px}</style>' }
81
+ end
82
+
83
+ context 'set to nil, does not add a top padding to the body' do
84
+ let(:options) { {position: :top, padding: nil} }
85
+
86
+ it { expect(html).not_to include 'padding' }
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'set to :fixed_top, shows the navbar at the top (fixed)' do
92
+ let(:options) { {position: :fixed_top} }
93
+ it { expect(html).to include 'nav class="navbar navbar-default navbar-fixed-top"' }
94
+ end
95
+
96
+ context 'set to :bottom, shows the navbar at the bottom (fixed)' do
97
+ let(:options) { {position: :bottom} }
98
+ it { expect(html).to include 'nav class="navbar navbar-default navbar-fixed-bottom"' }
99
+
100
+ context 'with the :padding' do
101
+ specify 'not set, adds 70px to the bottom padding of the body' do
102
+ expect(html).to include '<style>body {padding-bottom: 70px}</style>'
103
+ end
104
+
105
+ context 'set to a value, adds those pixels to the bottom padding of the body' do
106
+ let(:options) { {position: :bottom, padding: 100} }
107
+
108
+ it { expect(html).to include '<style>body {padding-bottom: 100px}</style>' }
109
+ end
110
+
111
+ context 'set to nil, does not add a bottom padding to the body' do
112
+ let(:options) { {position: :bottom, padding: nil} }
113
+
114
+ it { expect(html).not_to include 'padding' }
115
+ end
116
+ end
117
+ end
118
+
119
+ context 'set to :fixed_bottom, shows the navbar at the bottom (fixed)' do
120
+ let(:options) { {position: :fixed_bottom} }
121
+ it { expect(html).to include 'nav class="navbar navbar-default navbar-fixed-bottom"' }
122
+ end
123
+ end
124
+ end
125
+
126
+ describe 'vertical' do
127
+ describe 'accepts as parameters:' do
128
+ let(:behave) { be_a String }
129
+
130
+ specify 'a string (content)' do
131
+ expect(vertical 'content').to behave
132
+ end
133
+
134
+ specify 'a block (content)' do
135
+ expect(vertical { 'content' }).to behave
136
+ end
137
+
138
+ specify 'a string (content) + a hash (options)' do
139
+ expect(vertical 'content', class: :important).to behave
140
+ end
141
+
142
+ specify 'a hash (options) + a block (content)' do
143
+ expect(vertical(class: :important) { 'content' }).to behave
144
+ end
145
+ end
146
+
147
+ describe 'adds a toggle button and bars' do
148
+ let(:html) { vertical 'content' }
149
+ it { expect(html).to match %r{<button class="navbar-toggle" data-target="#.+?" data-toggle="collapse" type="button"><span class="sr-only">Toggle navigation</span>\n<span class="icon-bar"></span>\n<span class="icon-bar"></span>\n<span class="icon-bar"></span></button}m }
150
+ end
151
+ end
152
+
153
+ describe 'horizontal' do
154
+ describe 'accepts as parameters:' do
155
+ let(:behave) { be_a String }
156
+
157
+ specify 'a string (content)' do
158
+ expect(horizontal 'content').to behave
159
+ end
160
+
161
+ specify 'a block (content)' do
162
+ expect(horizontal { 'content' }).to behave
163
+ end
164
+
165
+ specify 'a string (content) + a hash (options)' do
166
+ expect(horizontal 'content', class: :important).to behave
167
+ end
168
+
169
+ specify 'a hash (options) + a block (content)' do
170
+ expect(horizontal(class: :important) { 'content' }).to behave
171
+ end
172
+ end
173
+
174
+ describe 'adds a collapsable div' do
175
+ let(:html) { horizontal 'content' }
176
+ it { expect(html).to match %r{<div class="collapse navbar-collapse" id=".+?">content</div>} }
177
+ end
178
+ end
179
+
180
+ describe 'multiple navbars' do
181
+ let(:navbar_1) { navbar inverted: true do
182
+ safe_join [vertical(link_to 'Home', '/'), horizontal(content_tag :p, '')]
183
+ end }
184
+ let(:navbar_2) { navbar position: :top do
185
+ safe_join [vertical(content_tag :p, ''), horizontal(link_to 'Home', '/')]
186
+ end }
187
+ let(:html) { safe_join [navbar_1, navbar_2], "\n"}
188
+
189
+ specify 'toggle their own horizontal part when clicking on vertical' do
190
+ navbar_ids = html.scan %r{<nav.+?data-target="#(.+?)".+?id="(\1)".+?</nav>}m
191
+ expect(navbar_ids.size).to eq 2
192
+ expect(navbar_ids.uniq.size).to eq 2
193
+ end
194
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -145,6 +145,7 @@ files:
145
145
  - lib/bh/form_builders/form_builder.rb
146
146
  - lib/bh/helpers/alert_helper.rb
147
147
  - lib/bh/helpers/base_helper.rb
148
+ - lib/bh/helpers/button_to_helper.rb
148
149
  - lib/bh/helpers/cdn_helper.rb
149
150
  - lib/bh/helpers/form/base_helper.rb
150
151
  - lib/bh/helpers/form/check_box_helper.rb
@@ -158,15 +159,17 @@ files:
158
159
  - lib/bh/helpers/form/submit_helper.rb
159
160
  - lib/bh/helpers/form_for_helper.rb
160
161
  - lib/bh/helpers/glyphicon_helper.rb
162
+ - lib/bh/helpers/link_to_helper.rb
161
163
  - lib/bh/helpers/modal_helper.rb
162
164
  - lib/bh/helpers/nav_helper.rb
165
+ - lib/bh/helpers/navbar_helper.rb
163
166
  - lib/bh/helpers/panel_helper.rb
164
167
  - lib/bh/helpers/panel_row_helper.rb
165
- - lib/bh/helpers/url_helper.rb
166
168
  - lib/bh/railtie.rb
167
169
  - lib/bh/version.rb
168
170
  - lib/bh/views/bh/_modal.html.erb
169
171
  - spec/helpers/alert_helper_spec.rb
172
+ - spec/helpers/button_to_helper_spec.rb
170
173
  - spec/helpers/cdn_helper_spec.rb
171
174
  - spec/helpers/form/check_box_helper_spec.rb
172
175
  - spec/helpers/form/field_helper_spec.rb
@@ -179,11 +182,12 @@ files:
179
182
  - spec/helpers/form/submit_helper_spec.rb
180
183
  - spec/helpers/form_for_helper_spec.rb
181
184
  - spec/helpers/glyphicon_helper_spec.rb
185
+ - spec/helpers/link_to_helper_spec.rb
182
186
  - spec/helpers/modal_helper_spec.rb
183
187
  - spec/helpers/nav_helper_spec.rb
188
+ - spec/helpers/navbar_helper_spec.rb
184
189
  - spec/helpers/panel_helper_spec.rb
185
190
  - spec/helpers/panel_row_helper_spec.rb
186
- - spec/helpers/url_helper_spec.rb
187
191
  - spec/spec_helper.rb
188
192
  homepage: http://github.com/Fullscreen/bh
189
193
  licenses:
@@ -212,6 +216,7 @@ summary: Bh provides a set of powerful helpers that streamlines the use of Boots
212
216
  components in Rails views.
213
217
  test_files:
214
218
  - spec/helpers/alert_helper_spec.rb
219
+ - spec/helpers/button_to_helper_spec.rb
215
220
  - spec/helpers/cdn_helper_spec.rb
216
221
  - spec/helpers/form/check_box_helper_spec.rb
217
222
  - spec/helpers/form/field_helper_spec.rb
@@ -224,10 +229,11 @@ test_files:
224
229
  - spec/helpers/form/submit_helper_spec.rb
225
230
  - spec/helpers/form_for_helper_spec.rb
226
231
  - spec/helpers/glyphicon_helper_spec.rb
232
+ - spec/helpers/link_to_helper_spec.rb
227
233
  - spec/helpers/modal_helper_spec.rb
228
234
  - spec/helpers/nav_helper_spec.rb
235
+ - spec/helpers/navbar_helper_spec.rb
229
236
  - spec/helpers/panel_helper_spec.rb
230
237
  - spec/helpers/panel_row_helper_spec.rb
231
- - spec/helpers/url_helper_spec.rb
232
238
  - spec/spec_helper.rb
233
239
  has_rdoc:
@@ -1,23 +0,0 @@
1
- require 'action_view'
2
-
3
- module Bh
4
- module UrlHelper
5
- # Overrides ActionView +link_to+ to be able to add the 'alert_link' class
6
- # to the link in case the link is inside of an alert.
7
- # @see http://getbootstrap.com/components/#alerts-links
8
- def link_to(*args, &block)
9
- args = add_alert_class_to_link!(*args, &block) if @alert_link
10
- super *args, &block
11
- end
12
-
13
- private
14
-
15
- def add_alert_class_to_link!(*args, &block)
16
- html_options = (block_given? ? args[1] : args[2]) || {}
17
- klass = html_options[:class]
18
- html_options[:class] = [klass, 'alert-link'].compact.join ' '
19
- block_given? ? args[1] = html_options : args[2] = html_options
20
- args
21
- end
22
- end
23
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
- require 'bh/helpers/alert_helper'
3
- require 'bh/helpers/url_helper'
4
- include Bh::AlertHelper
5
- include Bh::UrlHelper
6
-
7
- describe 'link_to' do
8
- context 'used without a block' do
9
- let(:link) { link_to 'Home', '/' }
10
-
11
- specify 'does not apply the "alert_link" class if used outside of an alert' do
12
- expect(link).not_to include 'alert-link'
13
- end
14
-
15
- specify 'applies the "alert_link" class if used inside an alert' do
16
- expect(alert_box { link }).to include 'alert-link'
17
- end
18
- end
19
-
20
- context 'used with a block' do
21
- let(:link) { link_to('/') { 'Home' } }
22
-
23
- specify 'does not apply the "alert_link" class if used outside of an alert' do
24
- expect(link).not_to include 'alert-link'
25
- end
26
-
27
- specify 'applies the "alert_link" class if used inside an alert' do
28
- expect(alert_box { link }).to include 'alert-link'
29
- end
30
- end
31
- end