alacarte 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -73,7 +73,8 @@ 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 => lambda{ current_user }
76
+ # add menu items with runtime methods for path generation
77
+ link :my_account, lambda { account_path(current_user) }, :if => lambda{ current_user }
77
78
 
78
79
  end
79
80
 
@@ -101,4 +102,4 @@ The output is generated as a ul-li list with anchor elements. If there is an ele
101
102
  <li><a href="/" class="nl active">nl</a></li>
102
103
  <li><a href="/" class="fr">fr</a></li>
103
104
  </ul>
104
- </pre>
105
+ </pre>
@@ -20,7 +20,8 @@ module AlacarteHelper
20
20
 
21
21
  _item = case item.type
22
22
  when :link
23
- link_to(item.label.html_safe, item.path, _html_options)
23
+ _path = item.path.respond_to?(:call) ? item.path.call : item.path
24
+ link_to(item.label.html_safe, _path, _html_options)
24
25
  else
25
26
  content_tag(item.type, item.label, _html_options)
26
27
  end
@@ -3,10 +3,10 @@ module Alacarte
3
3
  # Alacarte::Menu is the base class for defining menu items.
4
4
  class Menu
5
5
 
6
- VALID_ELEMENTS = [:link, :span]
6
+ VALID_ELEMENTS = [:link, :span, :separator, :title, :subtitle, :line]
7
7
  @@env = nil
8
8
 
9
- attr_reader :parent, :type, :name, :deep_name, :path, :as, :label, :options, :items, :block, :html_options, :group_options, :wrapper_options, :translation_key
9
+ attr_reader :parent, :type, :name, :deep_name, :path, :as, :label, :options, :items, :blocks, :html_options, :group_options, :wrapper_options, :translation_key
10
10
 
11
11
  # Tests if an environment was set to the Alacarte::Menu
12
12
  def self.env?
@@ -49,7 +49,8 @@ module Alacarte
49
49
  @translation_key = (block_given? && @type != :menu) ? "#{deep_name}.root" : "#{deep_name}"
50
50
  @label = options[:label] || I18n.t("alacarte.menus.#{@translation_key}", :default => @translation_key.to_s)
51
51
  @as = options[:as] || @name
52
- @block = block if block_given?
52
+ @blocks = []
53
+ @blocks << block if block_given?
53
54
  @html_options = options[:html]
54
55
  @group_options = options[:group]
55
56
  @wrapper_options = options[:wrapper]
@@ -57,9 +58,13 @@ module Alacarte
57
58
  build
58
59
  end
59
60
 
61
+ def extend(&block)
62
+ @blocks << block if block_given?
63
+ end
64
+
60
65
  # Tests if a block was passed to the Alacarte::Menu object
61
66
  def block?
62
- !!@block
67
+ (@blocks.size > 0)
63
68
  end
64
69
 
65
70
  # Builds the menu, based on the environment that is passed.
@@ -67,7 +72,11 @@ module Alacarte
67
72
  @@env = env if env
68
73
  @items = []
69
74
 
70
- self.instance_eval(&@block) if Menu.env? && self.block?
75
+ if Menu.env? && self.block?
76
+ @blocks.each do |block|
77
+ self.instance_eval(&block)
78
+ end
79
+ end
71
80
  end
72
81
 
73
82
  # Tests to see if the current menu item is valid in the current setting
@@ -9,7 +9,11 @@ module Alacarte
9
9
 
10
10
  # Define a menu in a draw block
11
11
  def menu(name, *args, &block)
12
- self[name] = Menu.new(nil, :menu, name, *args, &block)
12
+ if self[name]
13
+ self[name].extend(&block)
14
+ else
15
+ self[name] = Menu.new(nil, :menu, name, *args, &block)
16
+ end
13
17
  end
14
18
 
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module Alacarte
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alacarte
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stijn Mathysen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-24 00:00:00 Z
18
+ date: 2012-04-24 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: This Rails plugin allows you to create a menu system, using a dsl (similar to routes).
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements: []
76
76
 
77
77
  rubyforge_project: alacarte
78
- rubygems_version: 1.8.3
78
+ rubygems_version: 1.8.10
79
79
  signing_key:
80
80
  specification_version: 3
81
81
  summary: Provides a generic menu system for Rails