semantic_navigation 0.0.3 → 0.0.4

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.
@@ -1,3 +1,9 @@
1
+ ### 0.0.4 / Januarry 6th, 2012
2
+
3
+ * Added helper method wrapping the level 1 (root) render
4
+ * Fix breadcrumbs render
5
+ * Added helper method rendering menu from some level
6
+
1
7
  ### 0.0.3 / January 4th, 2012
2
8
 
3
9
  * Added levels rendering
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- This is semantic_menu manual
2
- Current version: 0.0.3
1
+ This is semantic_navigation
2
+
3
+ Current version: 0.0.4
3
4
 
4
5
  ###Purpose
5
6
  The purpose of this gem is to generate simple and usefull navigation. You can define different menus and render them separately, specify root nodes, setup your own renderers and other.
@@ -7,18 +8,18 @@ The purpose of this gem is to generate simple and usefull navigation. You can de
7
8
  ###How to install
8
9
 
9
10
  Write the gem dependency in your Gemfile:
10
- ```
11
+ <pre><code>
11
12
  gem 'semantic_navigation'
12
- ```
13
+ </code></pre>
13
14
 
14
15
  Make the install by bundler
15
- ```
16
+ <pre><code>
16
17
  $ bundle install
17
- ```
18
+ </code></pre>
18
19
 
19
20
  Generate the config file:
20
- ```
21
+ <pre><code>
21
22
  $ rake semantic_navigation:install
22
- ```
23
-
23
+ </code></pre>
24
24
 
25
+ For the information of how to configure and render your menus read the <a href='https://github.com/fr33z3/semantic_navigation/wiki'>Wiki</a>
@@ -37,8 +37,12 @@ module SemanticNavigation
37
37
  !item.nil? && !item.parent.nil? ? item.parent.name : ''
38
38
  elsif command == :breadcrumb
39
39
  return @menus[name.to_sym].render_breadcrumb
40
+ elsif command == :root
41
+ return @menus[name.to_sym].render_levels 1
40
42
  elsif command.is_a?(Hash) && command.keys == [:levels]
41
43
  return @menus[name.to_sym].render_levels command[:levels]
44
+ elsif command.is_a?(Hash) && command.keys == [:from_level]
45
+ return @menus[name.to_sym].render_from command[:from_level]
42
46
  else
43
47
  raise NoMethodError.new("Wrong menu render parameter:`#{command.to_s}`")
44
48
  end
@@ -7,7 +7,7 @@ module SemanticNavigation
7
7
  if @parent
8
8
  level_condition = last_level.nil? ? true : @level < last_level
9
9
  sub = (@active || show_submenu?) && level_condition ? render_submenu(last_level) : nil
10
- view_object.content_tag(:li, item_link + sub, :id => li_id, :class => classes)
10
+ view_object.content_tag(:li, item_link(classes) + sub, :id => li_id, :class => classes)
11
11
  else
12
12
  render_submenu
13
13
  end
@@ -42,7 +42,7 @@ module SemanticNavigation
42
42
  breadcrumb = nil
43
43
  if @active
44
44
  if @name
45
- breadcrumb = view_object.content_tag(:li, item_link + breadcrumb_name, :id => li_id) if @name
45
+ breadcrumb = view_object.content_tag(:li, item_link(breadcrumb_classes) + breadcrumb_divider, :id => li_id) if @name
46
46
  end
47
47
  buff = @sub_items.map{|s| s.render_breadcrumb}.find{|s| !s.nil?}
48
48
  if !breadcrumb.nil?
@@ -51,7 +51,7 @@ module SemanticNavigation
51
51
  breadcrumb = buff
52
52
  end
53
53
  end
54
- breadcrumb = view_object.content_tag(:ul, breadcrumb, :id => ul_id, :class => breadcrumb_classes) if !@parent
54
+ breadcrumb = view_object.content_tag(:ul, breadcrumb, :id => ul_id, :class => breadcrumb_menu_classes) if !@parent
55
55
  breadcrumb
56
56
  end
57
57
 
@@ -64,14 +64,22 @@ module SemanticNavigation
64
64
  item.level == levels.first-1 ? item.render_submenu(levels.last) : nil
65
65
  end
66
66
 
67
+ def render_from level_num
68
+ item = find_active_item
69
+ while item.level > level_num-1 && item.level != 0
70
+ item = item.parent
71
+ end
72
+ item.level == level_num-1 ? item.render_submenu : nil
73
+ end
74
+
67
75
  private
68
76
 
69
77
  def active?
70
78
  !@parent.nil? ? view_object.current_page?(@url_options) : false
71
79
  end
72
80
 
73
- def item_link
74
- view_object.link_to @name, @url_options, :class => classes, :id => a_id
81
+ def item_link(classes_string)
82
+ view_object.link_to @name, @url_options, :class => classes_string, :id => a_id
75
83
  end
76
84
 
77
85
  end
@@ -17,6 +17,7 @@ module SemanticNavigation
17
17
 
18
18
  #Breadcrumb variables
19
19
  @@breadcrumb_divider = "/"
20
+ @@breadcrumb_active_class = 'active'
20
21
 
21
22
 
22
23
 
@@ -78,6 +79,13 @@ module SemanticNavigation
78
79
  class_array.flatten.join(' ')
79
80
  end
80
81
 
82
+ def breadcrumb_classes
83
+ class_array = []
84
+ class_array += item_classes.to_a
85
+ class_array.push(@@breadcrumb_active_class) if active?
86
+ class_array
87
+ end
88
+
81
89
  def view_object
82
90
  @@view_object
83
91
  end
@@ -86,11 +94,11 @@ module SemanticNavigation
86
94
  @show_submenu.nil? ? @@show_submenu : @show_submenu
87
95
  end
88
96
 
89
- def breadcrumb_name
90
- @@breadcrumb_divider.html_safe
97
+ def breadcrumb_divider
98
+ @@breadcrumb_divider.html_safe if !active?
91
99
  end
92
100
 
93
- def breadcrumb_classes
101
+ def breadcrumb_menu_classes
94
102
  if @@breadcrumb_classes.is_a? Array
95
103
  return @@breadcrumb_classes.join(' ')
96
104
  else
@@ -1,3 +1,3 @@
1
1
  module SemanticNavigation
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,9 +5,4 @@ namespace :semantic_navigation do
5
5
  task :install => :environment do
6
6
  File.copy("#{File.dirname(__FILE__)}/templates/semantic_navigation.rb", "#{Rails.root}/config")
7
7
  end
8
-
9
- desc "Shows the menu hierarchy"
10
- task :show => :environment do
11
- puts "Here will be the navigation printout"
12
- end
13
8
  end
@@ -3,7 +3,7 @@
3
3
  #Wiki pages link: https://github.com/fr33z3/semantic_navigation/wiki/_pages
4
4
  SemanticNavigation::Configuration.run do |config|
5
5
 
6
- #What's the name of the active menu class will be (the dafault is 'active')
6
+ #What's the name of the active item class will be (the dafault is 'active')
7
7
  #config.active_class = 'active';
8
8
 
9
9
  #Do you want to show active class? (default = true)
@@ -33,9 +33,12 @@ SemanticNavigation::Configuration.run do |config|
33
33
  #Define breadcrumb divider
34
34
  #config.breadcrumb_divider = "<span class ='divider'>/</span>"
35
35
 
36
- #Define bread crumb classes
36
+ #Define breadcrumb classes
37
37
  #config.breadcrumb_classes = "breadcrumb"
38
38
 
39
+ #Define breadcrumb active class name (default = 'active')
40
+ #config.breadcrumb_active_class = 'active'
41
+
39
42
  #That's the creation of the `navigation` menu
40
43
  #config.navigation {|n|
41
44
  # n.dashboard 'Dashboard', :controller => :dashboard, :action => :index do |d|
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "rspec", "2.7.0"
23
- s.add_runtime_dependency "rails", "~>3.1.0"
23
+ s.add_runtime_dependency "rails", ">=3.0.0"
24
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_navigation
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergey Gribovski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-03 00:00:00 Z
18
+ date: 2012-01-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -39,14 +39,14 @@ dependencies:
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ~>
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
- hash: 3
44
+ hash: 7
45
45
  segments:
46
46
  - 3
47
- - 1
48
47
  - 0
49
- version: 3.1.0
48
+ - 0
49
+ version: 3.0.0
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  description: Simply and customizable navigation in the Rails application