semantic_navigation 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/README.md +24 -0
- data/Rakefile +1 -0
- data/lib/semantic_navigation.rb +4 -0
- data/lib/semantic_navigation/configuration.rb +38 -0
- data/lib/semantic_navigation/helper_methods.rb +19 -0
- data/lib/semantic_navigation/item.rb +62 -0
- data/lib/semantic_navigation/railtie.rb +15 -0
- data/lib/semantic_navigation/version.rb +3 -0
- data/lib/tasks/semantic_navigation.rake +13 -0
- data/lib/tasks/templates/semantic_navigation.rb +15 -0
- data/semantic_navigation.gemspec +24 -0
- metadata +109 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is semantic_menu manual
|
2
|
+
Current version: 0.0.1
|
3
|
+
|
4
|
+
###Purpose
|
5
|
+
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.
|
6
|
+
|
7
|
+
###How to install
|
8
|
+
|
9
|
+
Write the gem dependency in your Gemfile:
|
10
|
+
```
|
11
|
+
gem 'semantic_navigation', :git => 'git://github.com/fr33z3/semantic_navigation.git'
|
12
|
+
```
|
13
|
+
|
14
|
+
Make the install by bundler
|
15
|
+
```
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Generate the config file:
|
20
|
+
```
|
21
|
+
$ rake semantic_navigation:install
|
22
|
+
```
|
23
|
+
|
24
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'semantic_navigation/item'
|
2
|
+
|
3
|
+
module SemanticNavigation
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
attr_accessor :active_class, :create_ids, :show_submenu
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def run
|
10
|
+
instance = self.new
|
11
|
+
yield instance if block_given?
|
12
|
+
instance
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@active_class = 'active'
|
18
|
+
@create_ids = true
|
19
|
+
@show_submenu = false
|
20
|
+
@menus = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(name, *args)
|
24
|
+
menu = Item.new(name.to_s, args, self)
|
25
|
+
@menus.merge!({name => menu})
|
26
|
+
yield menu if block_given?
|
27
|
+
end
|
28
|
+
|
29
|
+
def render(view_object, name)
|
30
|
+
if @menus[name.to_sym]
|
31
|
+
return @menus[name.to_sym].render(view_object)
|
32
|
+
else
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SemanticNavigation::HelperMethods
|
2
|
+
|
3
|
+
def method_missing(name)
|
4
|
+
name_parts = name.to_s.split('_')
|
5
|
+
if (name_parts.count == 3 && name_parts[0] == 'render' && name_parts[2] == 'menu')
|
6
|
+
semantic_navigation_config.render(self, name_parts[1])
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def semantic_navigation_config
|
15
|
+
eval(IO.read("#{Rails.root}/config/semantic_navigation.rb"))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module SemanticNavigation
|
2
|
+
class Item
|
3
|
+
|
4
|
+
def initialize(id, args, parent)
|
5
|
+
@item_id = id
|
6
|
+
@name = args.first
|
7
|
+
@url_options = args.second
|
8
|
+
@parent = parent
|
9
|
+
|
10
|
+
@sub_items = []
|
11
|
+
@active_class = 'active'
|
12
|
+
@active = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(name, *args)
|
16
|
+
item = SemanticNavigation::Item.new(name.to_s, args, self)
|
17
|
+
@sub_items << item
|
18
|
+
yield item if block_given?
|
19
|
+
end
|
20
|
+
|
21
|
+
def render(view_object)
|
22
|
+
@view_object = view_object
|
23
|
+
if parent
|
24
|
+
set_as_active if active?
|
25
|
+
sub = render_subitems
|
26
|
+
link = view_object.link_to @name, @url_options, :class => classes, :id => @item_id
|
27
|
+
view_object.content_tag(:li, link + sub, :id => @item_id, :class => classes)
|
28
|
+
else
|
29
|
+
render_subitems
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_as_active
|
34
|
+
@active = true
|
35
|
+
parent.set_as_active if parent
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def render_subitems
|
41
|
+
if @sub_items.count > 0
|
42
|
+
sub = @sub_items.map{|s| s.render(@view_object)}.sum
|
43
|
+
@view_object.content_tag(:ul, sub, :id => @item_id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def classes
|
48
|
+
if @active
|
49
|
+
@active_class
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def active?
|
54
|
+
@view_object.current_page?(@url_options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def parent
|
58
|
+
@parent.is_a?(SemanticNavigation::Item) ? @parent : nil
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'semantic_navigation/helper_methods'
|
2
|
+
|
3
|
+
module SemanticNavigation
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
initializer "semantic_navigation.helper_methods" do
|
7
|
+
ActionView::Base.send :include, HelperMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
rake_tasks do
|
11
|
+
Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each {|f| load f}
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'ftools'
|
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
|
+
|
9
|
+
desc "Shows the menu hierarchy"
|
10
|
+
task :show => :environment do
|
11
|
+
puts "Here will be the navigation printout"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#This file need to create the navigation in your app.
|
2
|
+
SemanticNavigation::Configuration.run do |config|
|
3
|
+
|
4
|
+
#That's the creation of the navigation menu
|
5
|
+
config.navigation do |n|
|
6
|
+
n.main 'Main', :controller => :dashboard, :action => :index
|
7
|
+
n.about 'About', :controller => :about, :action => :index do |a|
|
8
|
+
a.company 'About company', :controller => :about, :action => :company
|
9
|
+
a.employes 'About our employes', :controller => :about, :action => :employes
|
10
|
+
end
|
11
|
+
n.feed_back 'Feedback', :controller => :feed_back, :action => :index
|
12
|
+
end
|
13
|
+
#You can render this menu by calling method render_navigation_menu
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "semantic_navigation/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "semantic_navigation"
|
7
|
+
s.version = SemanticNavigation::VERSION
|
8
|
+
s.authors = ["Sergey Gribovski"]
|
9
|
+
s.email = ["megacoder@rambler.ru"]
|
10
|
+
s.homepage = "https://github.com/fr33z3/semantic_navigation"
|
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}
|
13
|
+
|
14
|
+
s.rubyforge_project = "semantic_navigation"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec", "2.7.0"
|
23
|
+
s.add_runtime_dependency "rails", "~>3.1.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: semantic_navigation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sergey Gribovski
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-12-22 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 19
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 7
|
32
|
+
- 0
|
33
|
+
version: 2.7.0
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rails
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 3
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
version: 3.1.0
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Simply and customizable navigation in the Rails application
|
53
|
+
email:
|
54
|
+
- megacoder@rambler.ru
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/semantic_navigation.rb
|
67
|
+
- lib/semantic_navigation/configuration.rb
|
68
|
+
- lib/semantic_navigation/helper_methods.rb
|
69
|
+
- lib/semantic_navigation/item.rb
|
70
|
+
- lib/semantic_navigation/railtie.rb
|
71
|
+
- lib/semantic_navigation/version.rb
|
72
|
+
- lib/tasks/semantic_navigation.rake
|
73
|
+
- lib/tasks/templates/semantic_navigation.rb
|
74
|
+
- semantic_navigation.gemspec
|
75
|
+
homepage: https://github.com/fr33z3/semantic_navigation
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project: semantic_navigation
|
104
|
+
rubygems_version: 1.8.10
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Make the navigation in your Rails app by several lines
|
108
|
+
test_files: []
|
109
|
+
|