navigasmic 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -196,8 +196,60 @@ h3. ERB
196
196
 
197
197
  h3. XML
198
198
 
199
+ The XML Builder isn't hashed out completely, but it more or less generates google sitemap style xml. I don't know if the format is entirely correct in terms of nesting (it would make sense if it is), and I'd invite anyone who would like to hash it out more to do so.
200
+
201
+ *Simple Usage Using Builder*
202
+
203
+ <pre>
204
+ xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
205
+ semantic_navigation :primary, :builder => Navigasmic::XmlNavigationBuilder do |n|
206
+ n.group 'Media' do
207
+ n.item 'Image Gallery', :link => {:controller => 'media/images', :action => 'index'}
208
+ n.item 'Videos', :link => {:controller => 'media/videos'}, :changefreq => 'monthly'
209
+ end
210
+ end
211
+ </pre>
212
+ ...produces...
213
+ <pre>
214
+ <?xml version="1.0" encoding="UTF-8"?>
215
+ <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
216
+ <urlset>
217
+ <url>
218
+ <loc>http://host:port/media/images</loc>
219
+ <changefreq>yearly</changefreq>
220
+ </url>
221
+ <url>
222
+ <loc>http://host:port/media/videos</loc>
223
+ <changefreq>monthly</changefreq>
224
+ </url>
225
+ </urlset>
226
+ </urlset>
227
+ </pre>
228
+
229
+ *Simple Usage Using HAML*
230
+
231
+ <pre>
232
+ - semantic_navigation :primary, :builder => Navigasmic::XmlNavigationBuilder, :changefreq => 'daily' do |n|
233
+ = n.item 'Image Gallery', :link => {:controller => 'media/images', :action => 'index'}
234
+ = n.item 'Videos', :link => {:controller => 'media/videos'}, :changefreq => 'monthly'
235
+ </pre>
236
+ ...produces...
237
+ <pre>
238
+ <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
239
+ <url>
240
+ <loc>http://host:port/media/images</loc>
241
+ <changefreq>daily</changefreq>
242
+ </url>
243
+ <url>
244
+ <loc>http://host:port/media/videos</loc>
245
+ <changefreq>monthly</changefreq>
246
+ </url>
247
+ </urlset>
248
+ </pre>
249
+
250
+ Tip: You can check the template_format and use the XML Builder when it's :xml, and the HTML Builder if not.
199
251
  <pre>
200
- ...Still working on the xml builder...
252
+ :builder => template_format == :xml ? Navigasmic::XmlNavigationBuilder : nil
201
253
  </pre>
202
254
 
203
255
  h3. Other
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -1,36 +1,36 @@
1
1
  module Navigasmic
2
2
  class XmlNavigationBuilder
3
3
 
4
- @@classnames = {
5
- :with_group => 'with-group',
6
- :disabled => 'disabled',
7
- :highlighted => 'highlighted'
8
- }
4
+ @@wrapper_tag = :urlset
5
+ @@group_tag = :urlset
6
+ @@item_tag = :url
9
7
 
10
- attr_accessor :template, :name, :items
8
+ attr_accessor :template, :name, :items, :host
11
9
 
12
10
  def initialize(template, name, options = {}, &proc)
13
11
  @template, @name, @items = template, name.to_s, []
14
- render(options.delete(:html), &proc)
12
+ @host = options[:host] || "http://#{template.request.host_with_port}"
13
+ @changefreq = options[:changefreq] || 'yearly'
14
+ render(options.delete(:xml), &proc)
15
15
  end
16
16
 
17
17
  def render(options, &proc)
18
18
  buffer = template.capture(self, &proc)
19
- template.concat(template.content_tag(:ol, buffer, options))
19
+
20
+ options ||= {}
21
+ options['xmlns'] ||= 'http://www.sitemaps.org/schemas/sitemap/0.9'
22
+ options['xmlns:xsi'] ||= 'http://www.w3.org/2001/XMLSchema-instance'
23
+ options['xsi:schemaLocation'] ||= 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'
24
+
25
+ template.concat(template.content_tag(@@wrapper_tag, buffer, options))
20
26
  end
21
27
 
22
28
  def group(label = nil, options = {}, &proc)
23
29
  raise ArgumentError, "Missing block" unless block_given?
24
30
 
25
- options[:html] ||= {}
26
- options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:with_group])
27
- options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
28
-
29
31
  buffer = template.capture(self, &proc)
30
- group = template.content_tag(:ol, buffer)
31
- label = label_for_group(label) unless label.blank?
32
-
33
- template.content_tag(:li, label.to_s + group, options.delete(:html))
32
+ template.concat(template.content_tag(@@group_tag, buffer))
33
+ ''
34
34
  end
35
35
 
36
36
  def item(label, options = {}, &proc)
@@ -38,24 +38,13 @@ module Navigasmic
38
38
 
39
39
  item = NavigationItem.new(label, options, template)
40
40
 
41
- options[:html] ||= {}
42
- options[:html][:id] ||= label.to_s.gsub(/\s/, '_').underscore
43
-
44
- options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:disabled]) if item.disabled?
45
- options[:html][:class] = template.add_class(options[:html][:class], @@classnames[:highlighted]) if item.highlighted?(template.request.path, template.params)
46
-
47
- label = label_for_item(label)
48
- label = template.link_to(label, item.link) unless item.link.empty?
49
-
50
- template.content_tag(:li, label + buffer, options.delete(:html))
51
- end
52
-
53
- def label_for_group(label)
54
- template.content_tag(:span, label.to_s)
55
- end
56
-
57
- def label_for_item(label)
58
- template.content_tag(:span, label.to_s)
41
+ contents = template.content_tag(:loc, @host + template.url_for(item.link))
42
+ contents << template.content_tag(:changefreq, options[:changefreq] || @changefreq)
43
+ contents << template.content_tag(:lastmod, options[:lastmod]) if options[:lastmod]
44
+ contents << template.content_tag(:priority, options[:priority]) if options[:priority]
45
+
46
+ template.concat(template.content_tag(@@item_tag, contents + buffer, options.delete(:xml)))
47
+ ''
59
48
  end
60
49
 
61
50
  end
data/lib/navigasmic.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
- require File.join(File.dirname(__FILE__), *%w[builders html_builder])
3
- require File.join(File.dirname(__FILE__), *%w[builders xml_builder])
2
+ require 'builders/html_builder'
3
+ require 'builders/xml_builder'
4
4
 
5
5
  module Navigasmic #:nodoc:
6
6
 
@@ -41,7 +41,7 @@ module Navigasmic #:nodoc:
41
41
  options[:html][:class] = add_class(options[:html][:class], 'semantic-navigation')
42
42
  options[:html][:id] ||= name.to_s.underscore
43
43
 
44
- builder = options[:builder] || HtmlNavigationBuilder
44
+ builder = options.delete(:builder) || HtmlNavigationBuilder
45
45
  builder.new(@template, name, options, &proc)
46
46
  end
47
47
 
data/navigasmic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{navigasmic}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
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"]
12
- s.date = %q{2010-02-06}
12
+ s.date = %q{2010-02-08}
13
13
  s.description = %q{Semantic navigation; a semantic way to build beautifully simple navigation structures in Rails.}
14
14
  s.email = %q{jejacks0n@gmail.com}
15
15
  s.extra_rdoc_files = [
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Jackson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-06 00:00:00 -07:00
12
+ date: 2010-02-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency