bh 0.0.6 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2efc7f83e6175dbda16f557b14d18d6889748c35
4
- data.tar.gz: d8f958fb28c28731a4fe32587b00f2767f1fc441
3
+ metadata.gz: 6522abb89dd53d34215f678b086d1e9414181039
4
+ data.tar.gz: ce5a63947bd03e86eef43b9ea3801d8692605447
5
5
  SHA512:
6
- metadata.gz: 16df29192db7253cda1592a8bdb3d0cad6272fe0eb6c5b6393f44dbd61b70fc1bba2117ee571b65d8283107fe4f9a91a546c41bb0894c950f94d95a03c9092dc
7
- data.tar.gz: 43106b14b0e3741cb56b2165d0babe1241056e2e23189efd2ed42dead693b3283e5c6d2afc013af415c36eece5c1acb072fd7895b9ef8ada27a6a7159c3e8355
6
+ metadata.gz: 154e1ec61fee0870b2513f76ec23d7c4be8dc7c8dba2b4a2d8cc1ef3be493eebeb9f405c8f6e9e1557908d8d871df66e6e426b01d6b5f9c06e6128c6f7223e30
7
+ data.tar.gz: 85e4fe4953a9cc6a6a1b221c76af892aecd330c22e4a499627298f748be4b0d7d938d831e815738e65154424b34a4a96ea977716816efa0e8cc0cd182a36f7ad
@@ -6,6 +6,10 @@ 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.7 - 2014-08-25
10
+
11
+ * [FEATURE] Add `nav` helper
12
+
9
13
  ## 0.0.6 - 2014-08-22
10
14
 
11
15
  * [FEATURE] Add `:prefix`, `:suffix` options to form field helpers
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.6'
49
+ gem 'bh', '~> 0.0.7'
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*)
@@ -276,7 +276,7 @@ will generate the HTML to render a panel with a heading:
276
276
  ![panel-heading](https://cloud.githubusercontent.com/assets/7408595/3941820/da58db3e-2543-11e4-811f-f7da4ffce77d.png)
277
277
 
278
278
  Panel with title
279
- ------------------
279
+ ----------------
280
280
 
281
281
  ```rhtml
282
282
  <%= panel body: 'You accepted the Terms of service.', title: 'Congratulations' %>
@@ -296,7 +296,7 @@ will generate the HTML to render a panel with a title:
296
296
  ![panel-title](https://cloud.githubusercontent.com/assets/7408595/3941816/da52b894-2543-11e4-99b8-4b6ffd47c167.png)
297
297
 
298
298
  Contextual panel
299
- -----------------
299
+ ----------------
300
300
 
301
301
  ```rhtml
302
302
  <%= panel body: 'You accepted the Terms of service.', title: 'Congratulations', context: :success %>
@@ -537,6 +537,59 @@ Here is how a form with a text field and a submit button looks like with each la
537
537
  ![form-for-inline](https://cloud.githubusercontent.com/assets/7408595/4015591/30609b74-2a2c-11e4-989e-e509d72ed224.png)
538
538
 
539
539
 
540
+ NavHelper
541
+ ===========
542
+
543
+ To include [Boostrap navs](http://getbootstrap.com/components/#nav)
544
+ in your Rails views, you can use the
545
+ [nav](http://rubydoc.info/github/Fullscreen/bh/master/Bh/NavHelper) helper.
546
+ Here are some examples.
547
+
548
+ Justified tabs nav
549
+ ------------------
550
+
551
+ ```rhtml
552
+ <%= nav layout: :justified do %>
553
+ <%= link_to 'Home', root_path %>
554
+ <%= link_to 'Profile', profile_path %>
555
+ <% end %>
556
+ ```
557
+
558
+ will generate the HTML to render a nav with two links (wrapped in the
559
+ appropriate list items, as specified by Bootstrap documentation):
560
+
561
+ ```html
562
+ <ul class="nav nav-tabs nav-justified" role="tablist">
563
+ <li class="active"><a href="/">Home</a></li>
564
+ <li><a href="/profile">Profile</a></li>
565
+ </ul>
566
+ ```
567
+
568
+ ![nav-tabs](https://cloud.githubusercontent.com/assets/7408595/4038705/9dede620-2cba-11e4-9543-6384e8ac9ace.png)
569
+
570
+ Stacked pills nav
571
+ -----------------
572
+
573
+ ```rhtml
574
+ <%= nav as: :pills, layout: :stacked do %>
575
+ <%= link_to 'Home', root_path %>
576
+ <%= link_to 'Profile', profile_path %>
577
+ <% end %>
578
+
579
+ ```
580
+
581
+ will generate the HTML to render a stacked *pills* nav:
582
+
583
+ ```html
584
+ <ul class="nav nav-pills nav-stacked" role="tablist">
585
+ <li class="active"><a href="/">Home</a></li>
586
+ <li><a href="/profile">Profile</a></li>
587
+ </ul>
588
+ ```
589
+
590
+ ![nav-pills](https://cloud.githubusercontent.com/assets/7408595/4038706/9df29ad0-2cba-11e4-83de-cd31b6659c78.png)
591
+
592
+
540
593
  How to release new versions
541
594
  ===========================
542
595
 
@@ -6,6 +6,7 @@ module Bh
6
6
  include ActionView::Context # for capture
7
7
  include ActionView::Helpers::OutputSafetyHelper # for safe_join
8
8
  include ActionView::Helpers::RenderingHelper # for render
9
+ include ActionView::Helpers::UrlHelper # for link_to
9
10
 
10
11
  private
11
12
 
@@ -0,0 +1,58 @@
1
+ require 'bh/helpers/base_helper'
2
+
3
+ module Bh
4
+ # Provides methods to include navs.
5
+ # @see http://getbootstrap.com/components/#nav
6
+ module NavHelper
7
+ include BaseHelper
8
+
9
+ # Returns an HTML block tag that follows the Bootstrap documentation
10
+ # on how to display *navs*.
11
+ #
12
+ # The skeleton of the nav is an unordered list; its content is passed as a
13
+ # block as a list of navigation items.
14
+ # Since the most common use for a nav is to display a menu of links, a
15
+ # variable is set inside the block so that every call to +link_to+
16
+ # generates a link *surrounded by a list item*.
17
+ # @example An justified nav with two links.
18
+ # nav layout: :justified do
19
+ # link_to 'Home', '/'
20
+ # link_to 'Profile', '/profile'
21
+ # 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
+ def nav(options = {}, &block)
32
+ @nav_link = true
33
+ nav = content_tag :ul, role: 'tablist', class: nav_class(options), &block
34
+ nav.tap{ @nav_link = false }
35
+ end
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
+ private
45
+
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 = {})
52
+ 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]
56
+ end
57
+ end
58
+ end
@@ -2,8 +2,6 @@ require 'action_view'
2
2
 
3
3
  module Bh
4
4
  module UrlHelper
5
- include ActionView::Helpers::UrlHelper # for link_to
6
-
7
5
  # Overrides ActionView +link_to+ to be able to add the 'alert_link' class
8
6
  # to the link in case the link is inside of an alert.
9
7
  # @see http://getbootstrap.com/components/#alerts-links
@@ -3,6 +3,7 @@ require 'bh/helpers/cdn_helper'
3
3
  require 'bh/helpers/form_for_helper'
4
4
  require 'bh/helpers/glyphicon_helper'
5
5
  require 'bh/helpers/modal_helper'
6
+ require 'bh/helpers/nav_helper'
6
7
  require 'bh/helpers/panel_helper'
7
8
  require 'bh/helpers/panel_row_helper'
8
9
  require 'bh/helpers/url_helper'
@@ -15,6 +16,7 @@ module Bh
15
16
  ActionView::Base.send :include, FormForHelper
16
17
  ActionView::Base.send :include, GlyphiconHelper
17
18
  ActionView::Base.send :include, ModalHelper
19
+ ActionView::Base.send :include, NavHelper
18
20
  ActionView::Base.send :include, PanelHelper
19
21
  ActionView::Base.send :include, PanelRowHelper
20
22
  ActionView::Base.send :include, UrlHelper
@@ -1,3 +1,3 @@
1
1
  module Bh
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -0,0 +1,61 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'action_dispatch'
5
+ require 'bh/helpers/nav_helper'
6
+
7
+ include Bh::NavHelper
8
+
9
+ describe 'nav' do
10
+ let(:html) { nav options, &block }
11
+ let(:block) { Proc.new {} }
12
+ let(:options) { {} }
13
+
14
+ describe 'with the :as option' do
15
+ specify 'not set, shows a "tabs" nav' do
16
+ expect(html).to include 'ul class="nav nav-tabs" role="tablist"'
17
+ end
18
+
19
+ context 'set to :tabs, shows a "tabs" nav' do
20
+ let(:options) { {as: :tabs} }
21
+ it { expect(html).to include 'ul class="nav nav-tabs"' }
22
+ end
23
+
24
+ context 'set to :pills, shows a "tabs" nav' do
25
+ let(:options) { {as: :pills} }
26
+ it { expect(html).to include 'ul class="nav nav-pills"' }
27
+ end
28
+ end
29
+
30
+ describe 'with the :layout option' do
31
+ specify 'not set, does not set a layout' do
32
+ expect(html).to include 'ul class="nav nav-tabs" role="tablist"'
33
+ end
34
+
35
+ context 'set to :justified, shows a "justified" nav' do
36
+ let(:options) { {layout: :justified} }
37
+ it { expect(html).to include 'nav-justified' }
38
+ end
39
+
40
+ context 'set to :stacked, shows a "stacked" nav' do
41
+ let(:options) { {layout: :stacked} }
42
+ it { expect(html).to include 'nav-stacked' }
43
+ end
44
+ end
45
+
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"' }
59
+ end
60
+ end
61
+ 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.6
4
+ version: 0.0.7
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-22 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -159,6 +159,7 @@ files:
159
159
  - lib/bh/helpers/form_for_helper.rb
160
160
  - lib/bh/helpers/glyphicon_helper.rb
161
161
  - lib/bh/helpers/modal_helper.rb
162
+ - lib/bh/helpers/nav_helper.rb
162
163
  - lib/bh/helpers/panel_helper.rb
163
164
  - lib/bh/helpers/panel_row_helper.rb
164
165
  - lib/bh/helpers/url_helper.rb
@@ -179,6 +180,7 @@ files:
179
180
  - spec/helpers/form_for_helper_spec.rb
180
181
  - spec/helpers/glyphicon_helper_spec.rb
181
182
  - spec/helpers/modal_helper_spec.rb
183
+ - spec/helpers/nav_helper_spec.rb
182
184
  - spec/helpers/panel_helper_spec.rb
183
185
  - spec/helpers/panel_row_helper_spec.rb
184
186
  - spec/helpers/url_helper_spec.rb
@@ -223,6 +225,7 @@ test_files:
223
225
  - spec/helpers/form_for_helper_spec.rb
224
226
  - spec/helpers/glyphicon_helper_spec.rb
225
227
  - spec/helpers/modal_helper_spec.rb
228
+ - spec/helpers/nav_helper_spec.rb
226
229
  - spec/helpers/panel_helper_spec.rb
227
230
  - spec/helpers/panel_row_helper_spec.rb
228
231
  - spec/helpers/url_helper_spec.rb