mariner 0.0.2 → 0.0.3

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
@@ -48,7 +48,8 @@ After creating your nav, render it in your views with:
48
48
 
49
49
  <%= render_navigation :topbar %>
50
50
 
51
- See Mariner::Helper for usage on `render_navigation`.
51
+ See Mariner::Helper for usage on `#render_navigation`. See also
52
+ `#render_navigations` and `#render_sub_navigations`.
52
53
 
53
54
  ## Contributing
54
55
 
@@ -1,3 +1,5 @@
1
+ require 'active_support/core_ext/array/extract_options'
2
+
1
3
  module Mariner
2
4
 
3
5
  # Public: Gets included in controllers (see the Railtie)
@@ -41,6 +43,9 @@ module Mariner
41
43
  # render_navigation :a_group, FakeRenderingStrategy.new
42
44
  # #=> renders `a_group` with a FakeRenderingStrategy instance
43
45
  #
46
+ # render_navigation :a_group, :other_strategy
47
+ # #=> renders `a_group` with Mariner.rendering_strategies[:other_strategy]
48
+ #
44
49
  def render_navigation(config_path=nil, renderer=nil)
45
50
  target = target_from_path(config_path)
46
51
  strategy = rendering_strategy_from(renderer)
@@ -63,10 +68,10 @@ module Mariner
63
68
  # end
64
69
  # end
65
70
  #
66
- # render_navigations
71
+ # render_sub_navigations
67
72
  # #=> renders the group_a and group_b trees and joins the result
68
73
  #
69
- def render_navigations(config_path=nil, renderer=nil)
74
+ def render_sub_navigations(config_path=nil, renderer=nil)
70
75
  target = target_from_path(config_path)
71
76
  strategy = rendering_strategy_from(renderer)
72
77
 
@@ -76,6 +81,38 @@ module Mariner
76
81
  end.join
77
82
  end
78
83
 
84
+ # Public: For when you want to render multiple specific nav trees
85
+ #
86
+ # *args - A comma separated list of groups to render. The last argument
87
+ # may be an options hash. Options:
88
+ #
89
+ # - :rendering_strategy - A symbol, class, or object to use for rendering.
90
+ # See #render_navigation for details.
91
+ #
92
+ # Examples:
93
+ #
94
+ # Mariner.configure do
95
+ # group_a do
96
+ # root_path "Home"
97
+ #
98
+ # sub_group do
99
+ # products_path "Products"
100
+ # end
101
+ # end
102
+ #
103
+ # group_b do
104
+ # users_path "Manage Users"
105
+ # end
106
+ # end
107
+ #
108
+ # render_navigations 'group_a/sub_group', :group_b
109
+ # render_navigations :group_a, :group_b, :rendering_strategy => :different_strategy
110
+ #
111
+ def render_navigations(*args)
112
+ renderer = args.extract_options![:rendering_strategy]
113
+ args.map { |target_path| render_navigation(*[target_path, renderer].compact) }.join
114
+ end
115
+
79
116
  private
80
117
 
81
118
  def target_from_path(config_path)
@@ -12,7 +12,7 @@ module Mariner
12
12
 
13
13
  ActiveSupport.on_load(:action_controller) do
14
14
  include Mariner::Helper
15
- helper_method :render_navigation, :render_navigations
15
+ helper_method :render_navigation, :render_navigations, :render_sub_navigations
16
16
  end
17
17
  end
18
18
 
@@ -1,3 +1,3 @@
1
1
  module Mariner
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -97,7 +97,7 @@ module Mariner
97
97
 
98
98
  end
99
99
 
100
- describe "#render_navigations" do
100
+ describe "#render_sub_navigations" do
101
101
 
102
102
  before do
103
103
  Mariner.configure do
@@ -121,7 +121,44 @@ module Mariner
121
121
  entity.should_receive(:render)
122
122
  end
123
123
 
124
- render_navigations
124
+ render_sub_navigations
125
+ end
126
+
127
+ end
128
+
129
+ describe "#render_navigations" do
130
+
131
+ before do
132
+ Mariner.configure do
133
+ group_one {}
134
+ group_two do
135
+ sub_group {}
136
+ end
137
+ group_three {}
138
+ end
139
+
140
+ end
141
+
142
+ context "without rendering options" do
143
+
144
+ it "renders each navigation given" do
145
+ helper.should_receive(:render_navigation).with('group_two/sub_group').once.ordered
146
+ helper.should_receive(:render_navigation).with(:group_three).once.ordered
147
+
148
+ helper.render_navigations 'group_two/sub_group', :group_three
149
+ end
150
+
151
+ end
152
+
153
+ context "with rendering options" do
154
+
155
+ it "renders each navigation with the specified renderer" do
156
+ helper.should_receive(:render_navigation).with('group_two/sub_group', :default).once.ordered
157
+ helper.should_receive(:render_navigation).with(:group_three, :default).once.ordered
158
+
159
+ helper.render_navigations 'group_two/sub_group', :group_three, :rendering_strategy => :default
160
+ end
161
+
125
162
  end
126
163
 
127
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mariner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-24 00:00:00.000000000 Z
13
+ date: 2012-05-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: abyss
17
- requirement: &70198988231340 !ruby/object:Gem::Requirement
17
+ requirement: &70093358817540 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70198988231340
25
+ version_requirements: *70093358817540
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
- requirement: &70198984120560 !ruby/object:Gem::Requirement
28
+ requirement: &70093358817040 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 3.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70198984120560
36
+ version_requirements: *70093358817040
37
37
  description: A DSL for creating navigation structures based on the Rails routing table
38
38
  using Abyss.
39
39
  email: