navigasmic 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document CHANGED
@@ -1,4 +1,4 @@
1
- README.rdoc
1
+ README.textile
2
2
  lib/**/*.rb
3
3
  bin/*
4
4
  features/**/*.feature
data/README.textile CHANGED
@@ -6,7 +6,29 @@ h2. The Story
6
6
 
7
7
  Most of the navigation styles I've done over the years pretty much boil down to this idea: Use simple markup, and do the rest with css (and javascript if you need it). So, yeah, the default markup is beautifully simple (UL and LI tags).
8
8
 
9
- I wanted something that allowed for customization and ended up deciding that Rails forms outline that nicely. With some ideas taken from formtastic, I setup navigasmic to work a lot like how Rails forms work, in that it uses builders. For example, there are two builders that are provided (HTML for ERB, HAML, etc. and XML for ERB, Builder, etc), and these builders can be extended or replaced if you need more custom markup.
9
+ Ok, so navigation is easy right? Until you start managing active/highlighted, disabled states, and more if you may need them. This can quickly become a mess, and all too often it just stays in the views with whatever logic tossed on top of it as people go. I've seen it too many times, and I wanted to do something about it.
10
+
11
+ I went in with these requirements:
12
+
13
+ * Should be simple
14
+ * Should be easily customizable
15
+ * Should handle active/highlighted states
16
+ * Should handle disabled states
17
+ * Should be pleasant to use
18
+ * Should use less code to create than it generates
19
+
20
+ And then I wrote a DSL that met those requirements:
21
+
22
+ <pre>
23
+ <% semantic_navigation :main do |n| %>
24
+ <%= n.group 'Media' do %>
25
+ <%= n.item 'Image Gallery', :link => '/media/images', :highlights_on => '/media/videos' %>
26
+ <%= n.item 'Videos', :link => '/media/videos', :disabled_if => proc { true } %>
27
+ <% end %>
28
+ <% end %>
29
+ </pre>
30
+
31
+ Since I clearly needed something that allowed for customization I ended up emulating the way Rails uses form builders. With some ideas taken from formtastic, I setup navigasmic to use builders. There are two builders that are provided (HTML for ERB, HAML, etc. and XML for ERB, Builder, etc), and these builders can be extended or replaced if you need more custom markup.
10
32
 
11
33
  Currently the HTML builder generates UL and LI tags, which helps with SEO, and the XML builder generates tags that can be used for XML site maps.
12
34
 
@@ -197,7 +219,7 @@ I'm only testing with the latest Rails 2.4.x stable release, and it should work
197
219
 
198
220
  h2. Project Info
199
221
 
200
- Navigasmic is hosted on Github: "http://github.com/jejacks0n/navigasmic":http://github.com/jejacks0n/navigasmic, and the gem is available on Gemcutter: "http://gemcutter.org/navigasmic":http://gemcutter.org/navigasmic
222
+ Navigasmic is hosted on Github: "http://github.com/jejacks0n/navigasmic":http://github.com/jejacks0n/navigasmic, and the gem is available on Gemcutter: "http://gemcutter.org/gems/navigasmic":http://gemcutter.org/gems/navigasmic
201
223
 
202
224
 
203
225
  Copyright (c) Jeremy Jackson, released under the MIT license.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.3
@@ -6,6 +6,10 @@ module Navigasmic
6
6
  :disabled => 'disabled',
7
7
  :highlighted => 'highlighted'
8
8
  }
9
+ @@wrapper_tag = :ul
10
+ @@group_tag = :ul
11
+ @@item_tag = :li
12
+ @@label_tag = :span
9
13
 
10
14
  attr_accessor :template, :name, :items
11
15
 
@@ -16,7 +20,7 @@ module Navigasmic
16
20
 
17
21
  def render(options, &proc)
18
22
  buffer = template.capture(self, &proc)
19
- template.concat(template.content_tag(:ul, buffer, options))
23
+ template.concat(template.content_tag(@@wrapper_tag, buffer, options))
20
24
  end
21
25
 
22
26
  def group(label = nil, options = {}, &proc)
@@ -27,10 +31,10 @@ module Navigasmic
27
31
  options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
28
32
 
29
33
  buffer = template.capture(self, &proc)
30
- group = template.content_tag(:ul, buffer)
34
+ group = template.content_tag(@@group_tag, buffer)
31
35
  label = label_for_group(label) unless label.blank?
32
36
 
33
- template.content_tag(:li, label.to_s + group, options.delete(:html))
37
+ template.content_tag(@@item_tag, label.to_s + group, options.delete(:html))
34
38
  end
35
39
 
36
40
  def item(label, options = {}, &proc)
@@ -47,15 +51,15 @@ module Navigasmic
47
51
  label = label_for_item(label)
48
52
  label = template.link_to(label, item.link) unless item.link.empty?
49
53
 
50
- template.content_tag(:li, label + buffer, options.delete(:html))
54
+ template.content_tag(@@item_tag, label + buffer, options.delete(:html))
51
55
  end
52
56
 
53
57
  def label_for_group(label)
54
- template.content_tag(:span, label.to_s)
58
+ template.content_tag(@@label_tag, label.to_s)
55
59
  end
56
60
 
57
61
  def label_for_item(label)
58
- template.content_tag(:span, label.to_s)
62
+ template.content_tag(@@label_tag, label.to_s)
59
63
  end
60
64
 
61
65
  end
data/navigasmic.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{navigasmic}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Jackson"]
@@ -53,3 +53,4 @@ Gem::Specification.new do |s|
53
53
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
54
  end
55
55
  end
56
+
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: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Jackson