semantic_navigation 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +7 -1
- data/README.md +3 -3
- data/lib/semantic_navigation/configuration.rb +9 -3
- data/lib/semantic_navigation/core/base.rb +11 -0
- data/lib/semantic_navigation/core/leaf.rb +6 -2
- data/lib/semantic_navigation/core/navigation.rb +2 -2
- data/lib/semantic_navigation/core/node.rb +7 -3
- data/lib/semantic_navigation/helper_methods.rb +1 -1
- data/lib/semantic_navigation/renderers/acts_as_breadcrumb.rb +4 -1
- data/lib/semantic_navigation/renderers/acts_as_list.rb +3 -2
- data/lib/semantic_navigation/renderers/render_helpers.rb +2 -2
- data/lib/semantic_navigation/version.rb +1 -1
- metadata +5 -5
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
This is semantic_navigation
|
2
2
|
|
3
|
-
Current version: 0.0.
|
3
|
+
Current version: 0.0.9
|
4
4
|
|
5
5
|
###Purpose
|
6
6
|
This gem generates the navigation for your Rails app.
|
7
7
|
Really customizable and simple to use.
|
8
8
|
Using this gem you have 4 types of renderers: menu, breadcrumb, tabs, and, pills
|
9
9
|
|
10
|
-
You can define different menus and render them
|
10
|
+
You can define different menus and render them separate.
|
11
11
|
|
12
|
-
Now with simple integration with a twitter-bootstrap
|
12
|
+
Now with simple integration with a twitter-bootstrap CSS framework.
|
13
13
|
|
14
14
|
###How to install
|
15
15
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module SemanticNavigation
|
2
2
|
class Configuration
|
3
3
|
|
4
|
+
@@view_object = nil
|
4
5
|
@@navigations = {}
|
5
6
|
@@renderers = {:list => Renderers::List,
|
6
7
|
:breadcrumb => Renderers::BreadCrumb,
|
@@ -27,13 +28,14 @@ module SemanticNavigation
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def render(menu_id, renderer_name, options, view_object)
|
30
|
-
|
31
|
+
@@view_object = view_object
|
32
|
+
renderer = @@renderers[renderer_name].new
|
31
33
|
unless @@render_styles[renderer_name].nil?
|
32
34
|
renderer.instance_eval &@@render_styles[renderer_name]
|
33
35
|
end
|
34
36
|
options.keys.each{|key| renderer.send "#{key}=", options[key]}
|
35
37
|
navigation = @@navigations[menu_id]
|
36
|
-
navigation.mark_active
|
38
|
+
navigation.mark_active
|
37
39
|
navigation.render(renderer)
|
38
40
|
end
|
39
41
|
|
@@ -55,7 +57,11 @@ module SemanticNavigation
|
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
|
-
def
|
60
|
+
def self.view_object
|
61
|
+
@@view_object
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.navigation(name)
|
59
65
|
@@navigations[name]
|
60
66
|
end
|
61
67
|
|
@@ -3,6 +3,11 @@ module SemanticNavigation
|
|
3
3
|
class Base
|
4
4
|
|
5
5
|
attr :id, :level, :classes, :active
|
6
|
+
attr_writer :render_if
|
7
|
+
|
8
|
+
def render_if
|
9
|
+
!@render_if.nil? ? view_object.instance_eval(&@render_if) : true
|
10
|
+
end
|
6
11
|
|
7
12
|
def initialize(options, level)
|
8
13
|
@level = level
|
@@ -16,6 +21,12 @@ module SemanticNavigation
|
|
16
21
|
renderer.send :"render_#{class_name}", self
|
17
22
|
end
|
18
23
|
|
24
|
+
private
|
25
|
+
|
26
|
+
def view_object
|
27
|
+
SemanticNavigation::Configuration.view_object
|
28
|
+
end
|
29
|
+
|
19
30
|
end
|
20
31
|
end
|
21
32
|
end
|
@@ -9,10 +9,14 @@ module SemanticNavigation
|
|
9
9
|
|
10
10
|
def name
|
11
11
|
rendering_name = @name || I18n.t("#{@i18n_name}.#{@id}", :default => '')
|
12
|
-
rendering_name.is_a?(Proc)
|
12
|
+
if rendering_name.is_a?(Proc)
|
13
|
+
view_object.instance_eval(&rendering_name).to_s
|
14
|
+
else
|
15
|
+
rendering_name
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
|
-
def mark_active
|
19
|
+
def mark_active
|
16
20
|
if @url
|
17
21
|
@active = view_object.current_page?(@url)
|
18
22
|
else
|
@@ -23,9 +23,9 @@ module SemanticNavigation
|
|
23
23
|
@sub_elements.push element
|
24
24
|
end
|
25
25
|
|
26
|
-
def mark_active
|
26
|
+
def mark_active
|
27
27
|
@sub_elements.each do |element|
|
28
|
-
element.mark_active
|
28
|
+
element.mark_active
|
29
29
|
end
|
30
30
|
@active = !@sub_elements.find{|element| element.active}.nil?
|
31
31
|
end
|
@@ -9,11 +9,15 @@ module SemanticNavigation
|
|
9
9
|
|
10
10
|
def name
|
11
11
|
rendering_name = @name || i18n_name
|
12
|
-
rendering_name.is_a?(Proc)
|
12
|
+
if rendering_name.is_a?(Proc)
|
13
|
+
view_object.instance_eval(&rendering_name).to_s
|
14
|
+
else
|
15
|
+
rendering_name
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
|
-
def mark_active
|
16
|
-
@sub_elements.each{|element| element.mark_active
|
19
|
+
def mark_active
|
20
|
+
@sub_elements.each{|element| element.mark_active}
|
17
21
|
@active = view_object.current_page?(@url)
|
18
22
|
@active |= !@sub_elements.find{|element| element.active}.nil?
|
19
23
|
end
|
@@ -7,7 +7,7 @@ module SemanticNavigation::HelperMethods
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def active_item_for(name, level = nil)
|
10
|
-
navigation = SemanticNavigation::Configuration.
|
10
|
+
navigation = SemanticNavigation::Configuration.navigation(name)
|
11
11
|
item = navigation
|
12
12
|
while !item.is_a?(SemanticNavigation::Core::Leaf) &&
|
13
13
|
!item.sub_elements.find{|e| e.active}.nil? &&
|
@@ -3,6 +3,7 @@ module SemanticNavigation
|
|
3
3
|
module ActsAsBreadcrumb
|
4
4
|
|
5
5
|
def render_navigation(object)
|
6
|
+
return '' unless object.render_if
|
6
7
|
navigation(object) do
|
7
8
|
while !object.class.in?(SemanticNavigation::Core::Leaf, NilClass) &&
|
8
9
|
from_level.to_i > object.level
|
@@ -17,7 +18,9 @@ module SemanticNavigation
|
|
17
18
|
|
18
19
|
def render_node(object)
|
19
20
|
active_element = object.sub_elements.find{|e| e.active}
|
20
|
-
|
21
|
+
if active_element && !active_element.id.in?([except_for].flatten) && active_element.render_if
|
22
|
+
render_element = active_element.render(self)
|
23
|
+
end
|
21
24
|
if render_element
|
22
25
|
node(object) do
|
23
26
|
render_element
|
@@ -3,6 +3,7 @@ module SemanticNavigation
|
|
3
3
|
module ActsAsList
|
4
4
|
|
5
5
|
def render_navigation(object)
|
6
|
+
return '' unless object.render_if
|
6
7
|
navigation(object) do
|
7
8
|
while !object.class.in?(SemanticNavigation::Core::Leaf, NilClass) &&
|
8
9
|
from_level.to_i > object.level
|
@@ -16,7 +17,7 @@ module SemanticNavigation
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def render_node(object)
|
19
|
-
if !object.id.in?([except_for].flatten)
|
20
|
+
if !object.id.in?([except_for].flatten) && object.render_if
|
20
21
|
content = render_node_content(object)
|
21
22
|
if content
|
22
23
|
node(object) do
|
@@ -37,7 +38,7 @@ module SemanticNavigation
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def render_leaf(object)
|
40
|
-
if !object.id.in?([except_for].flatten)
|
41
|
+
if !object.id.in?([except_for].flatten) && object.render_if
|
41
42
|
leaf(object)
|
42
43
|
end
|
43
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_navigation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &22911060 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.1
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22911060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &22910500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *22910500
|
36
36
|
description: ! "Simply and customizable navigation in the Ruby on Rails 3 application.\n
|
37
37
|
\ Predefined bootstrap renderers"
|
38
38
|
email:
|