navigasmic 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,76 @@
|
|
1
1
|
module Navigasmic::Builder
|
2
2
|
class CrumbBuilder < Base
|
3
3
|
class Configuration < Base::Configuration
|
4
|
+
|
5
|
+
attr_accessor :item_class
|
6
|
+
attr_accessor :link_generator, :label_generator
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
# which keys (for other builder) should be removed from options
|
10
|
+
@excluded_keys = [:map]
|
11
|
+
|
12
|
+
# class configurations
|
13
|
+
@item_class = nil
|
14
|
+
|
15
|
+
# generator callbacks
|
16
|
+
@link_generator = proc{ |label, link, options, is_nested| link_to(label, link, options.delete(:link_html)) }
|
17
|
+
@label_generator = proc{ |label, is_linked, is_nested| "<span>#{label}</span>" }
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
4
21
|
end
|
5
22
|
|
6
23
|
def initialize(context, name, options, &block)
|
7
24
|
super
|
25
|
+
@path = []
|
26
|
+
@crumb_path = []
|
8
27
|
end
|
9
28
|
|
10
29
|
def render
|
30
|
+
capture(&@definition)
|
31
|
+
@path.join(' ').html_safe
|
11
32
|
end
|
12
33
|
|
13
34
|
def group(label = nil, options = {}, &block)
|
35
|
+
if block_given?
|
36
|
+
@crumb_path << label_for(label, false, false, options) if label
|
37
|
+
capture(&block)
|
38
|
+
end
|
14
39
|
end
|
15
40
|
|
16
41
|
def item(label, *args, &block)
|
42
|
+
options = args.extract_options!
|
43
|
+
options = flatten_and_eval_options(options)
|
44
|
+
return '' unless visible?(options)
|
45
|
+
|
46
|
+
merge_classes!(options, @config.item_class)
|
47
|
+
item = Navigasmic::Item.new(label, extract_and_determine_link(label, options, *args), visible?(options), options)
|
48
|
+
|
49
|
+
if item.highlights_on?(@context.request.path, @context.params)
|
50
|
+
@crumb_path << label_for(label, false, false, options)
|
51
|
+
@path += @crumb_path
|
52
|
+
@crumb_path = []
|
53
|
+
end
|
54
|
+
|
55
|
+
if block_given?
|
56
|
+
@crumb_path << label_for(label, item.link? ? item.link : false, false, options) if label
|
57
|
+
capture(&block)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def label_for(label, link, is_nested = false, options = {})
|
64
|
+
if label.present?
|
65
|
+
label = @context.instance_exec(label, options, !!link, is_nested, &@config.label_generator).html_safe
|
66
|
+
end
|
67
|
+
label = @context.instance_exec(label, link, options.delete(:link_html) || {}, is_nested, &@config.link_generator).html_safe if link
|
68
|
+
label
|
69
|
+
end
|
70
|
+
|
71
|
+
def merge_classes!(hash, classname)
|
72
|
+
return if classname.blank?
|
73
|
+
hash[:class] = (hash[:class] ? "#{hash[:class]} " : '') << classname
|
17
74
|
end
|
18
75
|
|
19
76
|
end
|
@@ -5,5 +5,11 @@ module Navigasmic
|
|
5
5
|
initializer "navigasmic.view_helpers" do
|
6
6
|
ActionView::Base.send :include, ViewHelpers
|
7
7
|
end
|
8
|
+
|
9
|
+
config.to_prepare do
|
10
|
+
if File.exists?(Rails.root.join('config', 'initializers', 'navigasmic'))
|
11
|
+
require Rails.root.join('config', 'initializers', 'navigasmic')
|
12
|
+
end
|
13
|
+
end
|
8
14
|
end
|
9
15
|
end
|
data/lib/navigasmic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: navigasmic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: 4331876644713175306
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
none: false
|
127
127
|
requirements:
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: 4331876644713175306
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
136
|
rubygems_version: 1.8.24
|