navigasmic 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,9 +82,9 @@ Navigasmic.setup do |config|
82
82
  # want to change.
83
83
  #
84
84
  # Changing the default ListBuilder options:
85
- config.builder Navigasmic::Builder::ListBuilder do |builder|
86
- builder.wrapper_class = 'semantic-navigation'
87
- end
85
+ #config.builder Navigasmic::Builder::ListBuilder do |builder|
86
+ # builder.wrapper_class = 'semantic-navigation'
87
+ #end
88
88
 
89
89
 
90
90
  # Naming Builder Configurations:
@@ -119,7 +119,7 @@ Navigasmic.setup do |config|
119
119
 
120
120
  # For dropdowns to work you'll need to include the bootstrap dropdown js
121
121
  # For groups, we adjust the markup so they'll be clickable and be picked up by the javascript.
122
- builder.label_generator = proc do |label, has_link, has_nested|
122
+ builder.label_generator = proc do |label, options, has_link, has_nested|
123
123
  if !has_nested || has_link
124
124
  "<span>#{label}</span>"
125
125
  else
@@ -129,13 +129,13 @@ Navigasmic.setup do |config|
129
129
 
130
130
  # For items, we adjust the links so they're '#', and do the same as for groups. This allows us to use more complex
131
131
  # highlighting rules for dropdowns.
132
- builder.link_generator = proc do |label, link, options, has_nested|
132
+ builder.link_generator = proc do |label, link, link_options, has_nested|
133
133
  if has_nested
134
134
  link = '#'
135
135
  label << "<b class='caret'></b>"
136
136
  options.merge!(class: 'dropdown-toggle', data: {toggle: 'dropdown'})
137
137
  end
138
- link_to(label, link, options)
138
+ link_to(label, link, link_options)
139
139
  end
140
140
 
141
141
  end
@@ -2,7 +2,7 @@ module Navigasmic::Builder
2
2
  class ListBuilder < Base
3
3
  class Configuration < Base::Configuration
4
4
 
5
- attr_accessor :wrapper_class, :has_nested_class, :is_nested_class, :disabled_class, :highlighted_class
5
+ attr_accessor :wrapper_class, :item_class, :has_nested_class, :is_nested_class, :disabled_class, :highlighted_class
6
6
  attr_accessor :wrapper_tag, :group_tag, :item_tag
7
7
  attr_accessor :link_generator, :label_generator
8
8
 
@@ -17,6 +17,7 @@ module Navigasmic::Builder
17
17
 
18
18
  # class configurations
19
19
  @wrapper_class = 'semantic-navigation'
20
+ @item_class = nil
20
21
  @has_nested_class = 'has-nested'
21
22
  @is_nested_class = 'is-nested'
22
23
  @disabled_class = 'disabled'
@@ -58,6 +59,7 @@ module Navigasmic::Builder
58
59
 
59
60
  item = Navigasmic::Item.new(label, extract_and_determine_link(label, options, *args), visible?(options), options)
60
61
 
62
+ merge_classes!(options, @config.item_class)
61
63
  merge_classes!(options, @config.disabled_class) if item.disabled?
62
64
  merge_classes!(options, @config.highlighted_class) if item.highlights_on?(@context.request.path, @context.params)
63
65
 
@@ -80,13 +82,14 @@ module Navigasmic::Builder
80
82
 
81
83
  def label_for(label, link, is_nested = false, options = {})
82
84
  if label.present?
83
- label = @context.instance_exec(label, !!link, is_nested, &@config.label_generator).html_safe
85
+ label = @context.instance_exec(label, options, !!link, is_nested, &@config.label_generator).html_safe
84
86
  end
85
87
  label = @context.instance_exec(label, link, options.delete(:link_html) || {}, is_nested, &@config.link_generator).html_safe if link
86
88
  label
87
89
  end
88
90
 
89
91
  def merge_classes!(hash, classname)
92
+ return if classname.blank?
90
93
  hash[:class] = (hash[:class] ? "#{hash[:class]} " : '') << classname
91
94
  end
92
95
 
@@ -1,3 +1,3 @@
1
1
  module Navigasmic
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -2,17 +2,14 @@ Navigasmic.setup do |config|
2
2
 
3
3
  # Defining Navigation Structures:
4
4
  #
5
- # You can begin by defining your navigation structures here. You can also define them directly in the view if you'd
6
- # like, but it's recommended to eventually move them here to clean help up your views. You can read about Navigasmic
7
- # at https://github.com/jejacks0n/navigasmic
5
+ # You can define your navigation structures and configure the builders in this initializer.
8
6
  #
9
- # When you're defining navigation here, it's basically the same as if you were doing it in the view but the scope is
10
- # different. It's important to understand that -- and use procs where you want things to execute in the view scope.
7
+ # When defining navigation here, it's important to understand that the scope is not the same as the view scope -- and
8
+ # you should use procs where you want things to execute in the view scope.
11
9
  #
12
10
  # Once you've defined some navigation structures and configured your builders you can render navigation in your views
13
11
  # using the `semantic_navigation` view helper. You can also use the same syntax to define your navigation structures
14
- # in your views, and eventually move them here (it's handy to prototype navigation/css by putting them in the views
15
- # first).
12
+ # in your views -- and eventually move them here if you want.
16
13
  #
17
14
  # <%= semantic_navigation :primary %>
18
15
  #
@@ -21,7 +18,7 @@ Navigasmic.setup do |config|
21
18
  # <%= semantic_navigation :primary, config: :blockquote %>
22
19
  # <%= semantic_navigation :primary, builder: Navigasmic::Builder::MapBuilder %>
23
20
  #
24
- # When defining navigation in your views just pass it a block (the same as here basically).
21
+ # When defining navigation in your views just pass it a block.
25
22
  #
26
23
  # <%= semantic_navigation :primary do |n| %>
27
24
  # <% n.item 'About Me' %>
@@ -34,9 +31,9 @@ Navigasmic.setup do |config|
34
31
 
35
32
  # Groups and Items:
36
33
  #
37
- # You can create a structure using `group`, and `item`. You can nest items inside groups or items. In the
38
- # following example, the "Articles" item will always highlight on the blog/posts controller, and the nested article
39
- # items will only highlight when on those specific pages. The "Links" item will be disabled unless the user is
34
+ # Create navigation structures using the `group`, and `item` methods. You can nest items inside groups or items.
35
+ # In the following example, the "Articles" item will always highlight on the blog/posts controller, and the nested
36
+ # article items will only highlight on those specific pages. The "Links" item will be disabled unless the user is
40
37
  # logged in.
41
38
  #
42
39
  #n.group 'Blog' do
@@ -47,11 +44,11 @@ Navigasmic.setup do |config|
47
44
  # n.item 'Links', controller: '/blog/links', disabled_if: proc{ !logged_in? }
48
45
  #end
49
46
  #
50
- # You can hide specific specific items or groups. Here we specify that the "About" section of navigation should
47
+ # You can hide specific specific items or groups, and here we specify that the "Admin" section of navigation should
51
48
  # only be displayed if the user is logged in.
52
49
  #
53
- #n.group 'About', hidden_unless: proc{ logged_in? } do
54
- # n.item 'About Me', class: 'featured', link_html: {class: 'about-me'}
50
+ #n.group 'Admin', hidden_unless: proc{ logged_in? } do
51
+ # n.item 'Manage Posts', class: 'posts', link_html: {data: {tools: 'posts'}}
55
52
  #end
56
53
  #
57
54
  # Scoping:
@@ -85,16 +82,16 @@ Navigasmic.setup do |config|
85
82
  # want to change.
86
83
  #
87
84
  # Changing the default ListBuilder options:
88
- config.builder Navigasmic::Builder::ListBuilder do |builder|
89
- builder.wrapper_class = 'semantic-navigation'
90
- end
85
+ #config.builder Navigasmic::Builder::ListBuilder do |builder|
86
+ # builder.wrapper_class = 'semantic-navigation'
87
+ #end
91
88
 
92
89
 
93
90
  # Naming Builder Configurations:
94
91
  #
95
- # If you want to define a named configuration for a builder, just provide a hash with the name, and the builder to
92
+ # If you want to define a named configuration for a builder, just provide a hash with the name and the builder to
96
93
  # configure. The named configurations can then be used during rendering by specifying a `:config => :bootstrap`
97
- # option to the `semantic_navigation` view helper.
94
+ # option.
98
95
  #
99
96
  # A Twitter Bootstrap configuration:
100
97
  #
@@ -103,6 +100,7 @@ Navigasmic.setup do |config|
103
100
  # <%= semantic_navigation :primary, config: :bootstrap, class: 'nav-pills' %>
104
101
  #
105
102
  # Or to create a full navigation bar using twitter bootstrap you could use the following in your view:
103
+ #
106
104
  # <div class="navbar">
107
105
  # <div class="navbar-inner">
108
106
  # <a class="brand" href="/">Title</a>
@@ -121,7 +119,7 @@ Navigasmic.setup do |config|
121
119
 
122
120
  # For dropdowns to work you'll need to include the bootstrap dropdown js
123
121
  # For groups, we adjust the markup so they'll be clickable and be picked up by the javascript.
124
- builder.label_generator = proc do |label, has_link, has_nested|
122
+ builder.label_generator = proc do |label, options, has_link, has_nested|
125
123
  if !has_nested || has_link
126
124
  "<span>#{label}</span>"
127
125
  else
@@ -131,13 +129,13 @@ Navigasmic.setup do |config|
131
129
 
132
130
  # For items, we adjust the links so they're '#', and do the same as for groups. This allows us to use more complex
133
131
  # highlighting rules for dropdowns.
134
- builder.link_generator = proc do |label, link, options, has_nested|
132
+ builder.link_generator = proc do |label, link, link_options, has_nested|
135
133
  if has_nested
136
134
  link = '#'
137
135
  label << "<b class='caret'></b>"
138
136
  options.merge!(class: 'dropdown-toggle', data: {toggle: 'dropdown'})
139
137
  end
140
- link_to(label, link, options)
138
+ link_to(label, link, link_options)
141
139
  end
142
140
 
143
141
  end
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.1
4
+ version: 1.0.2
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-09-20 00:00:00.000000000 Z
12
+ date: 2012-09-23 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: 185969563685699556
124
+ hash: -3392907034543902986
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: 185969563685699556
133
+ hash: -3392907034543902986
134
134
  requirements: []
135
135
  rubyforge_project:
136
136
  rubygems_version: 1.8.24