semantic_navigation 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/Changelog.md +10 -1
  2. data/README.md +33 -4
  3. data/Rakefile +3 -0
  4. data/lib/generators/semantic_navigation/install/install_generator.rb +20 -0
  5. data/lib/generators/semantic_navigation/install/templates/semantic_navigation.en.yml +2 -0
  6. data/lib/generators/semantic_navigation/install/templates/semantic_navigation.rb +25 -0
  7. data/lib/semantic_navigation.rb +2 -0
  8. data/lib/semantic_navigation/configuration.rb +52 -44
  9. data/lib/semantic_navigation/core.rb +4 -0
  10. data/lib/semantic_navigation/core/base.rb +21 -0
  11. data/lib/semantic_navigation/core/leaf.rb +25 -0
  12. data/lib/semantic_navigation/core/navigation.rb +35 -0
  13. data/lib/semantic_navigation/core/node.rb +29 -0
  14. data/lib/semantic_navigation/helper_methods.rb +14 -17
  15. data/lib/semantic_navigation/railtie.rb +14 -6
  16. data/lib/semantic_navigation/renderers.rb +8 -0
  17. data/lib/semantic_navigation/renderers/acts_as_breadcrumb.rb +39 -0
  18. data/lib/semantic_navigation/renderers/acts_as_list.rb +46 -0
  19. data/lib/semantic_navigation/renderers/bread_crumb.rb +50 -0
  20. data/lib/semantic_navigation/renderers/list.rb +44 -0
  21. data/lib/semantic_navigation/renderers/render_helpers.rb +113 -0
  22. data/lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb +58 -0
  23. data/lib/semantic_navigation/twitter_bootstrap/list.rb +76 -0
  24. data/lib/semantic_navigation/twitter_bootstrap/tabs.rb +70 -0
  25. data/lib/semantic_navigation/version.rb +1 -1
  26. data/semantic_navigation.gemspec +3 -3
  27. data/spec/lib/semantic_navigation/configuration_spec.rb +55 -0
  28. data/spec/lib/semantic_navigation/custom_renderer.rb +3 -0
  29. data/spec/lib/semantic_navigation/helper_methods_spec.rb +1 -0
  30. data/spec/lib/semantic_navigation_spec.rb +1 -0
  31. data/spec/spec_helper.rb +8 -0
  32. metadata +32 -14
  33. data/lib/semantic_navigation/core/procs.rb +0 -15
  34. data/lib/semantic_navigation/core/render.rb +0 -94
  35. data/lib/semantic_navigation/item.rb +0 -118
  36. data/lib/tasks/semantic_navigation.rake +0 -8
  37. data/lib/tasks/templates/semantic_navigation.rb +0 -53
@@ -1,3 +1,3 @@
1
1
  module SemanticNavigation
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -9,7 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.email = ["megacoder@rambler.ru"]
10
10
  s.homepage = "https://github.com/fr33z3/semantic_navigation"
11
11
  s.summary = %q{Make the navigation in your Rails app by several lines}
12
- s.description = %q{Simply and customizable navigation in the Rails application}
12
+ s.description = %q{Simply and customizable navigation in the Ruby on Rails 3 application.
13
+ Predefined bootstrap renderers}
13
14
 
14
15
  s.rubyforge_project = "semantic_navigation"
15
16
 
@@ -19,7 +20,6 @@ Gem::Specification.new do |s|
19
20
  s.require_paths = ["lib"]
20
21
 
21
22
  # specify any dependencies here; for example:
22
- s.add_development_dependency "rspec", "2.7.0"
23
+ s.add_development_dependency "rspec", ">=2.0.1"
23
24
  s.add_runtime_dependency "rails", ">=3.0.0"
24
- #s.add_runtime_dependency "fileutils"
25
25
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe SemanticNavigation::Configuration do
4
+
5
+ before :all do
6
+ @config_class = SemanticNavigation::Configuration
7
+ default_renderers = @config_class.class_variable_get("@@renderers")
8
+ default_renderers.keys.should == [:list, :breadcrumb, :bootstrap_breadcrumb, :bootstrap_list, :bootstrap_tabs, :bootstrap_pills]
9
+ end
10
+
11
+ describe '#navigate' do
12
+ it 'should accept navigation method' do
13
+ @config_class.class_variable_get("@@navigations").should == {}
14
+ SemanticNavigation::Configuration.run do
15
+ navigate :navigation
16
+ end
17
+ navigations = @config_class.class_variable_get("@@navigations")
18
+ navigations[:navigation].should_not be_nil
19
+ navigations[:navigation].id.should == :navigation
20
+ navigations[:navigation].instance_variable_get("@i18n_name").should == 'semantic_navigation.navigation'
21
+ end
22
+ end
23
+
24
+ describe '#styles_for' do
25
+ it 'should save the proc' do
26
+
27
+ SemanticNavigation::Configuration.run do
28
+ styles_for :navigation do
29
+ navigation_default_classes [:default]
30
+ end
31
+ end
32
+
33
+ render_styles = @config_class.class_variable_get("@@render_styles")
34
+ render_styles[:navigation].should_not be_nil
35
+ render_styles[:navigation].class.should == Proc
36
+ end
37
+ end
38
+
39
+ describe 'register_render' do
40
+ it 'should get the name and render class and reg as renderer' do
41
+ @config_class.register_renderer(:some_renderer,CustomRenderer)
42
+ renderers = @config_class.class_variable_get("@@renderers")
43
+ renderers[:some_renderer].should_not be_nil
44
+ renderers[:some_renderer].should == CustomRenderer
45
+ end
46
+
47
+ it 'should receive only renderer class and make a renderer name for itself' do
48
+ @config_class.register_renderer(CustomRenderer)
49
+ renderers = @config_class.class_variable_get("@@renderers")
50
+ renderers[:custom_renderer].should_not be_nil
51
+ renderers[:custom_renderer].should == CustomRenderer
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,3 @@
1
+ class CustomRenderer
2
+
3
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path(File.dirname(__FILE__)+'/semantic_navigation/custom_renderer')
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+ require 'rspec'
3
+ require 'semantic_navigation'
4
+
5
+ RSpec.configure do |config|
6
+ config.color_enabled = true
7
+ config.formatter = 'documentation'
8
+ 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.6
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-09 00:00:00.000000000 Z
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &12288140 !ruby/object:Gem::Requirement
16
+ requirement: &11286240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - =
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.7.0
21
+ version: 2.0.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *12288140
24
+ version_requirements: *11286240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &12299540 !ruby/object:Gem::Requirement
27
+ requirement: &11285680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,8 +32,9 @@ dependencies:
32
32
  version: 3.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *12299540
36
- description: Simply and customizable navigation in the Rails application
35
+ version_requirements: *11285680
36
+ description: ! "Simply and customizable navigation in the Ruby on Rails 3 application.\n
37
+ \ Predefined bootstrap renderers"
37
38
  email:
38
39
  - megacoder@rambler.ru
39
40
  executables: []
@@ -45,17 +46,34 @@ files:
45
46
  - Gemfile
46
47
  - README.md
47
48
  - Rakefile
49
+ - lib/generators/semantic_navigation/install/install_generator.rb
50
+ - lib/generators/semantic_navigation/install/templates/semantic_navigation.en.yml
51
+ - lib/generators/semantic_navigation/install/templates/semantic_navigation.rb
48
52
  - lib/semantic_navigation.rb
49
53
  - lib/semantic_navigation/configuration.rb
50
- - lib/semantic_navigation/core/procs.rb
51
- - lib/semantic_navigation/core/render.rb
54
+ - lib/semantic_navigation/core.rb
55
+ - lib/semantic_navigation/core/base.rb
56
+ - lib/semantic_navigation/core/leaf.rb
57
+ - lib/semantic_navigation/core/navigation.rb
58
+ - lib/semantic_navigation/core/node.rb
52
59
  - lib/semantic_navigation/helper_methods.rb
53
- - lib/semantic_navigation/item.rb
54
60
  - lib/semantic_navigation/railtie.rb
61
+ - lib/semantic_navigation/renderers.rb
62
+ - lib/semantic_navigation/renderers/acts_as_breadcrumb.rb
63
+ - lib/semantic_navigation/renderers/acts_as_list.rb
64
+ - lib/semantic_navigation/renderers/bread_crumb.rb
65
+ - lib/semantic_navigation/renderers/list.rb
66
+ - lib/semantic_navigation/renderers/render_helpers.rb
67
+ - lib/semantic_navigation/twitter_bootstrap/breadcrumb.rb
68
+ - lib/semantic_navigation/twitter_bootstrap/list.rb
69
+ - lib/semantic_navigation/twitter_bootstrap/tabs.rb
55
70
  - lib/semantic_navigation/version.rb
56
- - lib/tasks/semantic_navigation.rake
57
- - lib/tasks/templates/semantic_navigation.rb
58
71
  - semantic_navigation.gemspec
72
+ - spec/lib/semantic_navigation/configuration_spec.rb
73
+ - spec/lib/semantic_navigation/custom_renderer.rb
74
+ - spec/lib/semantic_navigation/helper_methods_spec.rb
75
+ - spec/lib/semantic_navigation_spec.rb
76
+ - spec/spec_helper.rb
59
77
  homepage: https://github.com/fr33z3/semantic_navigation
60
78
  licenses: []
61
79
  post_install_message:
@@ -1,15 +0,0 @@
1
- module SemanticNavigation
2
- module Core
3
- module Procs
4
-
5
- def show_if
6
- @condition = Proc.new
7
- end
8
-
9
- def render_item?
10
- !@condition.nil? ? @condition.call : true
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,94 +0,0 @@
1
- module SemanticNavigation
2
- module Core
3
- module Render
4
-
5
- def render(last_level = nil)
6
- return nil if !render_item?
7
- if @parent
8
- level_condition = last_level.nil? ? true : @level < last_level
9
- sub = (@active || show_submenu?) && level_condition ? render_submenu(last_level) : nil
10
- view_object.content_tag(:li, item_link(classes) + sub, :id => li_id, :class => classes)
11
- else
12
- render_submenu
13
- end
14
- end
15
-
16
- def render_submenu(last_level = nil)
17
- if @sub_items.count > 0
18
- sub = @sub_items.map{|s| s.render(last_level)}.sum
19
- view_object.content_tag(:ul, sub, :id => ul_id, :class => menu_classes) if sub != 0
20
- end
21
- end
22
-
23
- def set_as_active
24
- @active = true
25
- @parent.set_as_active if @parent
26
- end
27
-
28
- def find_active_item
29
- item = nil
30
- if active?
31
- item = self
32
- elsif @active
33
- @sub_items.each do |s|
34
- buff = s.find_active_item
35
- item = buff if !buff.nil?
36
- end
37
- end
38
- item
39
- end
40
-
41
- def render_breadcrumb
42
- breadcrumb = nil
43
- if @active
44
- if @name
45
- breadcrumb = view_object.content_tag(:li, item_link(breadcrumb_classes) + breadcrumb_divider, :id => li_id) if @name
46
- end
47
- buff = @sub_items.map{|s| s.render_breadcrumb}.find{|s| !s.nil?}
48
- if !breadcrumb.nil?
49
- breadcrumb += buff if !buff.nil?
50
- else
51
- breadcrumb = buff
52
- end
53
- end
54
- breadcrumb = view_object.content_tag(:ul, breadcrumb, :id => ul_id, :class => breadcrumb_menu_classes) if !@parent
55
- breadcrumb
56
- end
57
-
58
- def render_levels levels
59
- if levels.is_a? Fixnum
60
- levels = [levels]
61
- else
62
- levels = levels.to_a
63
- end
64
- item = find_active_item
65
- return nil if item.nil?
66
- while item.level > levels.first-1 && item.level != 0
67
- item = item.parent
68
- end
69
- item.level == levels.first-1 ? item.render_submenu(levels.last) : nil
70
- end
71
-
72
- def render_from level_num
73
- item = find_active_item
74
- return nil if item.nil?
75
- while item.level > level_num-1 && item.level != 0
76
- item = item.parent
77
- end
78
- item.level == level_num-1 ? item.render_submenu : nil
79
- end
80
-
81
- private
82
-
83
- def active?
84
- !@parent.nil? ? view_object.current_page?(@url_options) : false
85
- end
86
-
87
- def item_link(classes_string)
88
- view_object.link_to @name, @url_options, :class => classes_string, :id => a_id
89
- end
90
-
91
- end
92
- end
93
- end
94
-
@@ -1,118 +0,0 @@
1
- require 'semantic_navigation/core/render'
2
- require 'semantic_navigation/core/procs'
3
- module SemanticNavigation
4
- class Item
5
- include Core::Render
6
- include Core::Procs
7
-
8
- #Menu variables
9
- @@active_class = 'active'
10
- @@show_active_class = true
11
- @@show_menu_id = true
12
- @@show_submenu = false
13
-
14
- #Item variables
15
- @@show_name_id = true
16
- @@show_item_id = true
17
-
18
- #Breadcrumb variables
19
- @@breadcrumb_divider = "/"
20
- @@breadcrumb_active_class = 'active'
21
-
22
-
23
-
24
- attr_accessor :active_class, :show_active_class, :show_menu_id,
25
- :show_item_id, :show_name_id, :show_submenu,
26
- :menu_prefix, :item_prefix, :name_prefix,
27
- :item_classes, :menu_classes,
28
- :name, :parent, :level
29
-
30
- def initialize(id, args, parent)
31
- @item_id = id
32
- @name = args.first
33
- @url_options = args.second
34
- @parent = parent
35
- @sub_items = []
36
-
37
- set_as_active if active?
38
- end
39
-
40
- def method_missing(name, *args)
41
- item = SemanticNavigation::Item.new(name.to_s, args, self)
42
- item.level = @level + 1
43
- @sub_items << item
44
- yield item if block_given?
45
- end
46
-
47
- def self.set_default_option(name, value)
48
- class_variable_set("@@#{name}".to_sym, value)
49
- end
50
-
51
- private
52
-
53
- def ul_id
54
- prefix = @menu_prefix.nil? ? @@menu_prefix : @menu_prefix
55
- flag = @show_menu_id.nil? ? @@show_menu_id : @show_menu_id
56
- flag ? prefix+@item_id : nil
57
- end
58
-
59
- def li_id
60
- prefix = @item_prefix.nil? ? @@item_prefix : @item_prefix
61
- flag = @show_item_id.nil? ? @@show_item_id : @show_item_id
62
- flag ? prefix+@item_id : nil
63
- end
64
-
65
- def a_id
66
- prefix = @name_prefix.nil? ? @@name_prefix : @name_prefix
67
- flag = @show_name_id.nil? ? @@show_name_id : @show_name_id
68
- flag ? prefix+@item_id : nil
69
- end
70
-
71
- def classes
72
- class_array = []
73
- class_array << item_classes
74
- active_class = @active_class.nil? ? @@active_class : @active_class
75
- flag = @show_active_class.nil? ? @@show_active_class : @show_active_class
76
- if @active && flag
77
- class_array << active_class
78
- end
79
- class_array.flatten.join(' ')
80
- end
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
-
89
- def view_object
90
- @@view_object
91
- end
92
-
93
- def show_submenu?
94
- @show_submenu.nil? ? @@show_submenu : @show_submenu
95
- end
96
-
97
- def breadcrumb_divider
98
- @@breadcrumb_divider.html_safe if !active?
99
- end
100
-
101
- def breadcrumb_menu_classes
102
- if @@breadcrumb_classes.is_a? Array
103
- return @@breadcrumb_classes.join(' ')
104
- else
105
- return @@breadcrumb_classes
106
- end
107
- end
108
-
109
- def menu_classes
110
- if @menu_classes.is_a? Array
111
- return @menu_classes.join(' ')
112
- else
113
- return @menu_classes
114
- end
115
- end
116
-
117
- end
118
- end
@@ -1,8 +0,0 @@
1
- require 'fileutils'
2
-
3
- namespace :semantic_navigation do
4
- desc "The semantic navigation install"
5
- task :install => :environment do
6
- File.copy("#{File.dirname(__FILE__)}/templates/semantic_navigation.rb", "#{Rails.root}/config")
7
- end
8
- end
@@ -1,53 +0,0 @@
1
- #This file need to create the navigation in your app.
2
- #You can learn more about how to customize your menu reading the wiki
3
- #Wiki pages link: https://github.com/fr33z3/semantic_navigation/wiki/_pages
4
- SemanticNavigation::Configuration.run do |config|
5
-
6
- #What's the name of the active item class will be (the dafault is 'active')
7
- #config.active_class = 'active';
8
-
9
- #Do you want to show active class? (default = true)
10
- #config.show_active_class = true
11
-
12
- #Create the item ids (in the `li` tag) automatically (default = true)?
13
- #config.show_item_id = true
14
-
15
- #Create the menu ids (in the `ul` tag) automatically (default = true)?
16
- #config.show_menu_id = true
17
-
18
- #Create the name id (in the `a` tag) automatically (default = true)?
19
- #config.show_name_id = true
20
-
21
- #Show the submenu only when the menu is active (default = false)
22
- #config.show_submenu = false
23
-
24
- #Add menu prefix (`ul` tag)
25
- #config.menu_prefix = 'menu_'
26
-
27
- #Add item prefix (`li` tag)
28
- #config.item_prefix = 'item_'
29
-
30
- #Add name preifx (`a` tag)
31
- #config.name_prefix = 'name_'
32
-
33
- #Define breadcrumb divider
34
- #config.breadcrumb_divider = "<span class ='divider'>/</span>"
35
-
36
- #Define breadcrumb classes
37
- #config.breadcrumb_classes = "breadcrumb"
38
-
39
- #Define breadcrumb active class name (default = 'active')
40
- #config.breadcrumb_active_class = 'active'
41
-
42
- #That's the creation of the `navigation` menu
43
- #config.navigation {|n|
44
- # n.dashboard 'Dashboard', :controller => :dashboard, :action => :index do |d|
45
- # d.first 'First', :controller => :first, :action => :index do |f|
46
- # f.sub_first 'Sub First', sub_first_index_path
47
- # f.sub_second 'Sub Second', :controller => :sub_second, :action => :index
48
- # end
49
- # end
50
- # n.second 'Help', :controller => :second, :action => :index
51
- #}
52
-
53
- end