alacarte 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.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg/*
3
3
  .bundle
4
4
  .DS_Store
5
5
  doc/*
6
+ memprof.rb
data/CHANGES CHANGED
@@ -1,5 +1,10 @@
1
1
  = Change Log
2
2
 
3
+ == Version 0.0.4
4
+
5
+ * Improved documentation for the usage of :if and :unless
6
+ * Added .root to the root element of a menu item with child items, so it can be addressed uniquely with I18n
7
+
3
8
  == Version 0.0.3
4
9
 
5
10
  * Typo fix in README "Output example"
data/README.textile CHANGED
@@ -73,7 +73,7 @@ YourApplication::Application.menus.draw do
73
73
  link :other_site, 'http://someurl.com'
74
74
  # ...
75
75
 
76
- link :my_account, account_path(:current), :if => { current_user }
76
+ link :my_account, account_path(:current), :if => lambda{ current_user }
77
77
 
78
78
  end
79
79
 
data/lib/alacarte/menu.rb CHANGED
@@ -6,7 +6,7 @@ module Alacarte
6
6
  VALID_ELEMENTS = [:link, :span]
7
7
  @@env = nil
8
8
 
9
- attr_reader :parent, :type, :name, :deep_name, :path, :as, :label, :options, :items, :block, :html_options, :group_options
9
+ attr_reader :parent, :type, :name, :deep_name, :path, :as, :label, :options, :items, :block, :html_options, :group_options, :translation_key
10
10
 
11
11
  # Tests if an environment was set to the Alacarte::Menu
12
12
  def self.env?
@@ -45,7 +45,8 @@ module Alacarte
45
45
  @name = options[:name] || args[0]
46
46
  @path = options[:path] || args[1]
47
47
  @deep_name = @parent ? "#{@parent.deep_name}.#{@name.to_s}" : @name.to_s
48
- @label = options[:label] || I18n.t("alacarte.menus.#{@deep_name}", :default => @deep_name.to_s)
48
+ @translation_key = (block_given? && @type != :menu) ? "#{deep_name}.root" : "#{deep_name}"
49
+ @label = options[:label] || I18n.t("alacarte.menus.#{@translation_key}", :default => @translation_key.to_s)
49
50
  @as = options[:as] || @name
50
51
  @block = block if block_given?
51
52
  @html_options = options[:html]
@@ -1,3 +1,3 @@
1
1
  module Alacarte
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -109,5 +109,26 @@ describe Alacarte::Menu do
109
109
  @menu = Alacarte::Menu.new(nil, :menu, :unless => lambda{ 4 == 4 })
110
110
  @menu.valid?.should be_false
111
111
  end
112
+
113
+ it "should add .root to the translation key of a root link or span element" do
114
+ @menu = Alacarte::Menu.new(nil, :menu, 'name') do
115
+ link :global, '/global'
116
+ link :account, '/account' do
117
+ link :settings, '/settings'
118
+ link :logout, '/logout'
119
+ end
120
+ end
121
+
122
+ @object = Object.new
112
123
 
124
+ @menu.build(@object)
125
+ @menu.deep_name.should eql 'name'
126
+ @menu.items.first.deep_name.should eql 'name.global'
127
+ @menu.items.last.deep_name.should eql 'name.account'
128
+ @menu.items.last.translation_key.should eql 'name.account.root'
129
+ @menu.items.last.items.first.deep_name.should eql 'name.account.settings'
130
+ @menu.items.last.items.first.translation_key.should eql 'name.account.settings'
131
+ @menu.items.last.items.last.deep_name.should eql 'name.account.logout'
132
+ @menu.items.last.items.last.translation_key.should eql 'name.account.logout'
133
+ end
113
134
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alacarte
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 3
10
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
11
10
  platform: ruby
12
11
  authors:
13
12
  - Stijn Mathysen
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-01-05 00:00:00 +01:00
17
+ date: 2011-08-17 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -57,27 +56,23 @@ rdoc_options: []
57
56
  require_paths:
58
57
  - lib
59
58
  required_ruby_version: !ruby/object:Gem::Requirement
60
- none: false
61
59
  requirements:
62
60
  - - ">="
63
61
  - !ruby/object:Gem::Version
64
- hash: 3
65
62
  segments:
66
63
  - 0
67
64
  version: "0"
68
65
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
66
  requirements:
71
67
  - - ">="
72
68
  - !ruby/object:Gem::Version
73
- hash: 3
74
69
  segments:
75
70
  - 0
76
71
  version: "0"
77
72
  requirements: []
78
73
 
79
74
  rubyforge_project: alacarte
80
- rubygems_version: 1.4.1
75
+ rubygems_version: 1.3.6
81
76
  signing_key:
82
77
  specification_version: 3
83
78
  summary: Provides a generic menu system for Rails