innetra-easy_navigation 2.1.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,4 +1,10 @@
1
1
  Manifest
2
+ easy_navigation.gemspec
3
+ generators/easy_navigation/templates/stylesheets/sass/easy_navigation.sass
4
+ generators/easy_navigation/templates/javascripts/easy_navigation.js
5
+ generators/easy_navigation/templates/images/arrow.png
6
+ generators/easy_navigation/templates/images/arrow.svg
7
+ generators/easy_navigation/easy_navigation_generator.rb
2
8
  README.rdoc
3
9
  Rakefile
4
10
  init.rb
data/README.rdoc CHANGED
@@ -4,7 +4,8 @@ Rails gem/plugin for generating a tabbed navigation for Rails.
4
4
 
5
5
  == Requirements
6
6
 
7
- This gem/plugin is intented to be used with Rails 2.2 as it uses i18n
7
+ This gem/plugin is intented to be used with Rails 2.2 as it uses i18n,
8
+ also you'll need to install Haml as it uses Sass for CSS.
8
9
 
9
10
  == Install
10
11
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('easy_navigation', '2.1.0') do |e|
5
+ Echoe.new('easy_navigation', '2.1.2') do |e|
6
6
  e.description = "Easy navigation for Ruby on Rails 2.2 (i18n)"
7
7
  e.url = "http://github.com/innetra/easy_navigation"
8
8
  e.author = "Ivan Torres"
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{easy_navigation}
5
- s.version = "2.1.0"
5
+ s.version = "2.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ivan Torres"]
9
- s.date = %q{2009-04-25}
9
+ s.date = %q{2009-05-02}
10
10
  s.description = %q{Easy navigation for Ruby on Rails 2.2 (i18n)}
11
11
  s.email = %q{mexpolk@gmail.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/easy_navigation.rb"]
13
- s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/easy_navigation.rb", "easy_navigation.gemspec"]
13
+ s.files = ["Manifest", "easy_navigation.gemspec", "generators/easy_navigation/templates/stylesheets/sass/easy_navigation.sass", "generators/easy_navigation/templates/javascripts/easy_navigation.js", "generators/easy_navigation/templates/images/arrow.png", "generators/easy_navigation/templates/images/arrow.svg", "generators/easy_navigation/easy_navigation_generator.rb", "README.rdoc", "Rakefile", "init.rb", "lib/easy_navigation.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/innetra/easy_navigation}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Easy_navigation", "--main", "README.rdoc"]
@@ -0,0 +1,53 @@
1
+ class EasyNavigationGenerator < Rails::Generator::Base
2
+ attr_accessor :controllers
3
+ def manifest
4
+
5
+ record do |m|
6
+
7
+ # CSS rules for EasyNavigation
8
+ m.directory("public/stylesheets/sass")
9
+ m.template "stylesheets/sass/easy_navigation.sass", "public/stylesheets/sass/easy_navigation.sass"
10
+
11
+ # Javascript for horizontal dropdown menu's
12
+ m.directory("public/javascripts")
13
+ m.template "javascripts/easy_navigation.js", "public/javascripts/easy_navigation.js"
14
+
15
+ m.directory("public/images/easy_navigation")
16
+ m.file "images/arrow.png", "public/images/arrow.png"
17
+
18
+ end
19
+ end
20
+
21
+ protected
22
+
23
+ def extract_routes
24
+
25
+ self.controllers = {}
26
+
27
+ ActionController::Routing::Routes.routes.each do |route|
28
+
29
+ if route.parameter_shell.has_key?(:controller)
30
+
31
+ unless self.controllers.has_key?(route.parameter_shell[:controller])
32
+ self.controllers[route.parameter_shell[:controller]] = { :actions => [] }
33
+ end
34
+
35
+ unless self.controllers[route.parameter_shell[:controller]].include? route.parameter_shell[:action]
36
+ self.controllers[route.parameter_shell[:controller]][:actions] << route.parameter_shell[:action]
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ def build_easy_navigation_configuration
45
+ extract_routes
46
+ self.controllers.keys.sort.each do |controller_name|
47
+ self.controllers[controller_name][:actions].each do |action_name|
48
+ p "#{controller_name} => #{action_name}"
49
+ end
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,99 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Created with Inkscape (http://www.inkscape.org/) -->
3
+ <svg
4
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
5
+ xmlns:cc="http://creativecommons.org/ns#"
6
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
7
+ xmlns:svg="http://www.w3.org/2000/svg"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
10
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
11
+ width="744.09448819"
12
+ height="1052.3622047"
13
+ id="svg2"
14
+ sodipodi:version="0.32"
15
+ inkscape:version="0.46"
16
+ sodipodi:docname="arrow.svg"
17
+ inkscape:output_extension="org.inkscape.output.svg.inkscape">
18
+ <defs
19
+ id="defs4">
20
+ <inkscape:perspective
21
+ sodipodi:type="inkscape:persp3d"
22
+ inkscape:vp_x="0 : 526.18109 : 1"
23
+ inkscape:vp_y="0 : 1000 : 0"
24
+ inkscape:vp_z="744.09448 : 526.18109 : 1"
25
+ inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
26
+ id="perspective10" />
27
+ </defs>
28
+ <sodipodi:namedview
29
+ id="base"
30
+ pagecolor="#ffffff"
31
+ bordercolor="#666666"
32
+ borderopacity="1.0"
33
+ gridtolerance="10000"
34
+ guidetolerance="10"
35
+ objecttolerance="10"
36
+ inkscape:pageopacity="0.0"
37
+ inkscape:pageshadow="2"
38
+ inkscape:zoom="12.068065"
39
+ inkscape:cx="27.92494"
40
+ inkscape:cy="998.95349"
41
+ inkscape:document-units="px"
42
+ inkscape:current-layer="layer1"
43
+ showgrid="false"
44
+ inkscape:window-width="1280"
45
+ inkscape:window-height="725"
46
+ inkscape:window-x="0"
47
+ inkscape:window-y="25" />
48
+ <metadata
49
+ id="metadata7">
50
+ <rdf:RDF>
51
+ <cc:Work
52
+ rdf:about="">
53
+ <dc:format>image/svg+xml</dc:format>
54
+ <dc:type
55
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
56
+ </cc:Work>
57
+ </rdf:RDF>
58
+ </metadata>
59
+ <g
60
+ inkscape:label="Layer 1"
61
+ inkscape:groupmode="layer"
62
+ id="layer1">
63
+ <g
64
+ id="g2502"
65
+ inkscape:export-filename="/home/itorres/code/easy_navigation/generators/easy_navigation/templates/images/arrow.png"
66
+ inkscape:export-xdpi="90"
67
+ inkscape:export-ydpi="90">
68
+ <rect
69
+ inkscape:export-ydpi="90"
70
+ inkscape:export-xdpi="90"
71
+ inkscape:export-filename="/home/itorres/Desktop/arrow.png"
72
+ y="40.312904"
73
+ x="30.299774"
74
+ height="14"
75
+ width="10"
76
+ id="rect3277"
77
+ style="fill:none;fill-opacity:1;stroke:none;stroke-width:5;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
78
+ <path
79
+ inkscape:export-ydpi="90"
80
+ inkscape:export-xdpi="90"
81
+ inkscape:export-filename="/home/itorres/Desktop/arrow.png"
82
+ transform="matrix(-0.9483359,0,0,-0.821283,49.36601,77.264811)"
83
+ d="M 18.52321,39.665869 L 14.832535,39.665869 L 11.141859,39.665869 L 12.987197,36.469651 L 14.832535,33.273432 L 16.677872,36.469651 L 18.52321,39.665869 z"
84
+ inkscape:randomized="0"
85
+ inkscape:rounded="0"
86
+ inkscape:flatsided="false"
87
+ sodipodi:arg2="1.5707963"
88
+ sodipodi:arg1="0.52359878"
89
+ sodipodi:r2="2.1308122"
90
+ sodipodi:r1="4.2616248"
91
+ sodipodi:cy="37.535057"
92
+ sodipodi:cx="14.832535"
93
+ sodipodi:sides="3"
94
+ id="path2385"
95
+ style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:5;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
96
+ sodipodi:type="star" />
97
+ </g>
98
+ </g>
99
+ </svg>
@@ -0,0 +1,37 @@
1
+ var EasyNavigation = Class.create();
2
+ EasyNavigation.prototype = {
3
+
4
+ timeout: null,
5
+ menu: null,
6
+
7
+ initialize: function(navigation) {
8
+ $(navigation).select('li.tab.drop, li.tab div').each(
9
+ function(node) {
10
+ Event.observe(node, 'mouseover', this.displayMenu.bind(this));
11
+ Event.observe(node, 'mouseout', this.hideMenu.bind(this));
12
+ }.bind(this)
13
+ );
14
+ },
15
+
16
+ displayMenu: function(event) {
17
+ clearTimeout(this.timeout);
18
+ this.menu = $(Event.element(event)).up('.tab div') ||
19
+ $(Event.element(event)).down('.tab div') ||
20
+ $(Event.element(event)).next('.tab div');
21
+ if (this.menu.style.display == 'none')
22
+ this.toggleMenu(this.menu);
23
+ },
24
+
25
+ hideMenu: function(event) {
26
+ if (this.menu.style.display == 'none') {
27
+ clearTimeout(this.timeout);
28
+ } else {
29
+ this.timeout = window.setTimeout(this.toggleMenu.bind(this, this.menu), 1000);
30
+ }
31
+ },
32
+
33
+ toggleMenu: function(element) {
34
+ Effect.toggle($(element), 'slide', {duration: 0.3});
35
+ }
36
+
37
+ }
@@ -0,0 +1,84 @@
1
+ // Default colors
2
+ !tab_text_color = #FFF
3
+ !tab_bg_color = transparent
4
+ !menu_text_color = #FFF
5
+ !menu_bg_color = #257291
6
+
7
+ // Current tab|menu being viewed
8
+ !current_tab_text_color = #FFFF00
9
+ !current_tab_bg_color = #257291
10
+ !current_menu_text_color = #FFFF00
11
+ !current_menu_bg_color = #257291
12
+
13
+ // Hover style for tab and menus
14
+ !hover_tab_bg_color = #257291
15
+ !hover_menu_bg_color = #258BB4
16
+
17
+ // Drop down menu image (arrow down)
18
+ !drop_down_image = "url(/images/easy_navigation/arrow.png)"
19
+
20
+ .navigation
21
+ font-size: 12px
22
+ font-weight: bold
23
+ line-height: 30px
24
+ margin: 0
25
+ padding: 0
26
+
27
+ a
28
+ display: block
29
+ padding: 0 10px
30
+ text-decoration: none
31
+
32
+ li
33
+ list-style: none
34
+
35
+ ul
36
+ margin: 0
37
+ padding: 0
38
+
39
+ .tab
40
+ float: left
41
+ margin-right: 5px
42
+
43
+ a.tab_link
44
+ color = !tab_text_color
45
+ background-color = !tab_bg_color
46
+
47
+ div
48
+ background-color: !tab_bg_color
49
+ left: auto
50
+ min-width: 150px
51
+ padding: 0
52
+ position: absolute
53
+ top: auto
54
+ z-index: 10000
55
+
56
+ .menu, a.menu_link
57
+ color = !menu_text_color
58
+ background-color = !menu_bg_color
59
+
60
+ .drop
61
+ background:
62
+ image: url(/images/arrow.png)
63
+ repeat: no-repeat
64
+ position: 95% 60%
65
+ padding-right: 5px
66
+
67
+ // Current
68
+ .tab.current
69
+ background-color = !current_tab_bg_color
70
+ a.tab_link
71
+ color = !current_tab_text_color
72
+
73
+ .menu.current a.menu_link
74
+ background-color = !current_menu_bg_color
75
+ color = !current_menu_text_color
76
+
77
+ // Hovers
78
+ .tab
79
+ &:hover
80
+ background-color = !hover_tab_bg_color
81
+
82
+ .menu a.menu_link
83
+ &:hover
84
+ background-color = !hover_menu_bg_color
@@ -13,65 +13,95 @@ module EasyNavigation
13
13
  tabs_html = ""
14
14
 
15
15
  EasyNavigation::Builder.navigation[name][:tabs].each do |tab|
16
+
16
17
  menus_html = ""
17
18
  current_tab = false
19
+
18
20
  tab[:menus].each do |menu|
19
- if current = current_menu?(menu)
20
- current_tab = true
21
- end
21
+
22
+ current_tab = true if current = current_menu?(menu)
23
+
24
+ # Render menu's HTML class attribute
25
+ menu_class = ""
26
+ menu_class << menu_class_name
27
+ menu_class << " current" if current
28
+
29
+ # Render menu's HTML
22
30
  menus_html << self.render_menu(menu[:name], menu[:text],
23
- menu[:url].merge!(:skip_relative_url_root => true),
24
- ("#{menu_class_name} current" if current) || menu_class_name)
31
+ menu[:url].merge!(:skip_relative_url_root => true), menu_class)
25
32
  if separator
26
- menus_html << self.render_separator(separator_class_name)
33
+ menus_html << self.render_separator(separator_class_name)
27
34
  end
35
+
36
+ end
37
+
38
+ # If tab has no menus mark detect if match current url
39
+ current_tab = current_menu?(tab) if tab[:menus].empty?
40
+
41
+ # Render tab's HTML class attribute
42
+ tab_class = ""
43
+ tab_class << tab_class_name
44
+ tab_class << " current" if current_tab
45
+
46
+ if tab[:menus].empty?
47
+ tabs_html << self.render_empty_tab(tab[:name], tab[:text],
48
+ tab[:url].merge!(:skip_relative_url_root => true),
49
+ tab_class)
50
+ else
51
+ tab_class << " drop"
52
+ tabs_html << self.render_tab(tab[:name], tab[:text],
53
+ tab[:url].merge!(:skip_relative_url_root => true),
54
+ menus_html, tab_class)
28
55
  end
29
- tabs_html << self.render_tab(tab[:name],
30
- tab[:text],
31
- tab[:url].merge!(:skip_relative_url_root => true),
32
- menus_html, ("#{tab_class_name} current" if current_tab) || tab_class_name)
56
+
33
57
  end
34
58
  self.render_navigation("navigation_" << name.to_s, tabs_html, navigation_class_name)
35
59
  end
36
60
 
37
61
  protected
38
62
 
39
- def render_separator(class_name)
40
- content_tag("li", "|", :class => class_name)
41
- end
63
+ def render_separator(class_name)
64
+ content_tag("li", "|", :class => class_name)
65
+ end
42
66
 
43
- def render_menu(id, text, url, class_name)
44
- content_tag("li", link_to(text, url), :id => id, :class => class_name)
45
- end
67
+ def render_menu(id, text, url, class_name)
68
+ content_tag("li", link_to(text, url, :class => "menu_link"),
69
+ :id => id, :class => class_name)
70
+ end
46
71
 
47
- def render_tab(id, text, url, menus_html, class_name)
48
- content_tag("li",
49
- "#{link_to(text, url)} #{content_tag("ul", menus_html)}",
50
- :id => id, :class => class_name)
51
- end
72
+ def render_tab(id, text, url, menus_html, class_name)
73
+ content_tag(:li,"#{link_to(text, url, :class => 'tab_link')} #{content_tag(:div,
74
+ content_tag(:ul, menus_html), :id => "#{id}_menus", :style => "display:none;")}",
75
+ :id => id, :class => class_name)
76
+ end
52
77
 
53
- def render_navigation(id, tabs_html, class_name)
54
- content_tag("ul", tabs_html, :id => id, :class => class_name)
55
- end
78
+ def render_empty_tab(id, text, url, class_name)
79
+ content_tag("li", link_to(text, url, :class => 'tab_link'), :id => id, :class => class_name)
80
+ end
56
81
 
57
- def current_menu?(menu)
58
- current = controller.params[:controller] == menu[:url][:controller].gsub(/^\//, "") &&
59
- (controller.action_name == menu[:url][:action] || menu[:url][:action] == nil)
60
- if menu.has_key?:on
61
- (menu[:on].is_a?(Array) ? menu[:on] : [menu[:on]]).each do |controllers|
62
- (controllers.is_a?(Array) ? controllers : [controllers]).each do |c|
63
- current |= controller.params[:controller] == c[:controller].gsub(/^\//, "")
64
- if c.has_key?:only
65
- current &= (c[:only].is_a?(Array) ? c[:only] : [c[:only]]).include?controller.action_name
66
- end
67
- if c.has_key?:except
68
- current &= !((c[:except].is_a?(Array) ? c[:except] : [c[:except]]).include?controller.action_name)
82
+ def render_navigation(id, tabs_html, class_name)
83
+ tabs_html << javascript_tag("var navigation = new EasyNavigation('#{id}');")
84
+ content_tag("ul", tabs_html, :id => id, :class => class_name)
85
+ end
86
+
87
+ def current_menu?(menu)
88
+ current = controller.params[:controller] == menu[:url][:controller].gsub(/^\//, "") &&
89
+ (controller.action_name == menu[:url][:action] || menu[:url][:action] == nil)
90
+ if menu.has_key?:on
91
+ (menu[:on].is_a?(Array) ? menu[:on] : [menu[:on]]).each do |controllers|
92
+ (controllers.is_a?(Array) ? controllers : [controllers]).each do |c|
93
+ current |= controller.params[:controller] == c[:controller].gsub(/^\//, "")
94
+ if c.has_key?:only
95
+ current &= (c[:only].is_a?(Array) ? c[:only] : [c[:only]]).include?controller.action_name
96
+ end
97
+ if c.has_key?:except
98
+ current &= !((c[:except].is_a?(Array) ? c[:except] : [c[:except]]).include?controller.action_name)
99
+ end
69
100
  end
70
101
  end
71
102
  end
103
+ current
72
104
  end
73
- current
74
- end
75
105
 
76
106
  end # EasyNavigation::Helper
77
107
 
@@ -120,9 +150,11 @@ module EasyNavigation
120
150
  end
121
151
 
122
152
  def tab(name, options = {}, &block)
123
- options.merge!(self.options)
124
- tab = Tab.new(name, options.merge!(:prefix => [self.options[:prefix], self.name]))
125
- yield tab
153
+ # Pass i18n and prefix options
154
+ options.merge!(:i18n => self.options[:i18n] || false)
155
+ options.merge!(:prefix => [self.options[:prefix], self.name])
156
+ tab = Tab.new(name, options)
157
+ yield tab if block
126
158
  self.tabs << tab.build
127
159
  end
128
160
 
@@ -139,14 +171,19 @@ module EasyNavigation
139
171
  self.menus = []
140
172
  self.name = name
141
173
  self.options = options
142
- self.text = name.to_s.gsub(/_/, " ").gsub(/\b('?[a-z])/) { $1.capitalize }
143
- self.text = I18n.t([self.options[:prefix], self.name, "title"].join(".")) if self.options[:i18n] == true
174
+ if self.options[:i18n] == true
175
+ self.text = I18n.t([self.options[:prefix], self.name, "title"].join("."))
176
+ else
177
+ self.text = name.to_s.gsub(/_/, " ").gsub(/\b('?[a-z])/) { $1.capitalize }
178
+ end
144
179
  end
145
180
 
146
181
  def menu(name, options = {}, &block)
147
- options.merge!(self.options)
148
- menu = Menu.new(name, options.merge!(:prefix => [self.options[:prefix], self.name, "menus"]))
149
- yield menu
182
+ # Pass i18n and prefix options
183
+ options.merge!(:i18n => self.options[:i18n] || false)
184
+ options.merge!(:prefix => [self.options[:prefix], self.name, "menus"])
185
+ menu = Menu.new(name, options)
186
+ yield menu if block
150
187
  self.menus << menu.build
151
188
  end
152
189
 
@@ -164,15 +201,18 @@ module EasyNavigation
164
201
 
165
202
  def initialize(name, options = {})
166
203
  self.active_urls = []
167
- self.name = name
168
204
  self.options = options
169
- self.text = self.name.to_s.gsub(/_/, " ").gsub(/\b('?[a-z])/) { $1.capitalize }
170
- self.text = I18n.t([self.options[:prefix], self.name, "title"].join(".")) if self.options[:i18n] == true
205
+ self.name = [options[:prefix], name].join("_")
206
+ if options[:i18n] == true
207
+ self.text = I18n.t([self.options[:prefix], name].join("."))
208
+ else
209
+ self.text = name.to_s.gsub(/_/, " ").gsub(/\b('?[a-z])/) { $1.capitalize }
210
+ end
171
211
  end
172
212
 
173
213
  def build
174
- { :name => self.options[:prefix].join("_").to_sym,
175
- :text => text,
214
+ { :name => self.name,
215
+ :text => self.text,
176
216
  :url => self.options[:url],
177
217
  :on => self.active_urls }
178
218
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: innetra-easy_navigation
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Torres
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-25 00:00:00 -07:00
12
+ date: 2009-05-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,11 +24,16 @@ extra_rdoc_files:
24
24
  - lib/easy_navigation.rb
25
25
  files:
26
26
  - Manifest
27
+ - easy_navigation.gemspec
28
+ - generators/easy_navigation/templates/stylesheets/sass/easy_navigation.sass
29
+ - generators/easy_navigation/templates/javascripts/easy_navigation.js
30
+ - generators/easy_navigation/templates/images/arrow.png
31
+ - generators/easy_navigation/templates/images/arrow.svg
32
+ - generators/easy_navigation/easy_navigation_generator.rb
27
33
  - README.rdoc
28
34
  - Rakefile
29
35
  - init.rb
30
36
  - lib/easy_navigation.rb
31
- - easy_navigation.gemspec
32
37
  has_rdoc: true
33
38
  homepage: http://github.com/innetra/easy_navigation
34
39
  post_install_message: