sitemapper 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +17 -0
- data/Rakefile +2 -1
- data/init.rb +1 -0
- data/lib/sitemapper.rb +30 -2
- data/lib/sitemapper/helpers.rb +19 -16
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -105,6 +105,22 @@ page title), short_description or description, tag_list or keywords.
|
|
105
105
|
|
106
106
|
<% page(@event) %>
|
107
107
|
|
108
|
+
If you need to change the default method lookup for page, you have two ways:
|
109
|
+
|
110
|
+
==== Add an initializer with the following content (that will change the default method lookup sequence):
|
111
|
+
|
112
|
+
Sitemapper.meta_lookup = {:title => [:my_default_title_method, :my_second_default_title_method]
|
113
|
+
:desc => [:my_default_description_method, :my_second_default_description_method],
|
114
|
+
:keywords => [:my_default_keywords_method, :my_second_default_keywords_methods]
|
115
|
+
}
|
116
|
+
|
117
|
+
==== Configure per object (yes, object, not just ActiveRecord descendents) lookups:
|
118
|
+
|
119
|
+
class MyObject
|
120
|
+
map_fields :title => :weird_title, :desc => :weird_description, :keywords => :weird_keywords
|
121
|
+
...
|
122
|
+
end
|
123
|
+
|
108
124
|
If you want to suggest any other SEO technique, suggest it on
|
109
125
|
carlos@milk-it.net
|
110
126
|
|
@@ -116,6 +132,7 @@ carlos@milk-it.net
|
|
116
132
|
* Create separate files for dynamic and static routes (then, we'll can
|
117
133
|
delete all the static on startup)
|
118
134
|
* Write test code (sorry, I really didn't it)
|
135
|
+
* Write the Sitemapper::Map#map_urls method
|
119
136
|
|
120
137
|
Copyright (c) 2008 Carlos Júnior, released under the MIT license
|
121
138
|
Copyright (c) 2008 Milk-it Software House, released under the MIT license
|
data/Rakefile
CHANGED
@@ -17,6 +17,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
17
17
|
rdoc.rdoc_dir = 'rdoc'
|
18
18
|
rdoc.title = 'Sitemaper'
|
19
19
|
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README')
|
20
|
+
rdoc.rdoc_files.include('README.rdoc')
|
21
21
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
+
rdoc.main = 'README.rdoc'
|
22
23
|
end
|
data/init.rb
CHANGED
data/lib/sitemapper.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
1
2
|
require 'sitemapper/helpers'
|
2
3
|
require 'sitemapper/map'
|
3
4
|
require 'sitemapper/accessors'
|
5
|
+
require 'sitemapper/object_mapper'
|
4
6
|
|
5
7
|
module Sitemapper
|
6
|
-
MAJOR, MINOR, TINY = 0,
|
8
|
+
MAJOR, MINOR, TINY = 0, 3, 0 #:nodoc:
|
7
9
|
|
8
10
|
# Get the running version of Sitemapper
|
9
|
-
def version
|
11
|
+
def self.version
|
10
12
|
[MAJOR, MINOR, TINY].join('.')
|
11
13
|
end
|
12
14
|
|
@@ -17,4 +19,30 @@ module Sitemapper
|
|
17
19
|
def self.map
|
18
20
|
@map or raise 'Uninitialized Sitemapper.map'
|
19
21
|
end
|
22
|
+
|
23
|
+
# Define the default meta lookup for objects on <tt>page</tt> helper
|
24
|
+
#
|
25
|
+
# <tt>lookup</tt> is a hash with the following options:
|
26
|
+
#
|
27
|
+
# * <tt>:desc</tt> method to look for page description
|
28
|
+
# * <tt>:keywords</tt> method to look for page keywords
|
29
|
+
# * <tt>:title</tt> method to look for page title
|
30
|
+
#
|
31
|
+
# All these arguments can be an Array, String or Symbol and will
|
32
|
+
# be used to lookup a valid method when you call <tt>page</tt> using
|
33
|
+
# something different of a Hash as argument. For example:
|
34
|
+
#
|
35
|
+
# <% page(@contact) %>
|
36
|
+
#
|
37
|
+
def self.meta_lookup=(lookup)
|
38
|
+
@meta_lookup = lookup
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.meta_lookup
|
42
|
+
@meta_lookup || {
|
43
|
+
:desc => [:short_description, :description],
|
44
|
+
:keywords => [:tag_list, :keywords],
|
45
|
+
:title => [:title, :name]
|
46
|
+
}
|
47
|
+
end
|
20
48
|
end
|
data/lib/sitemapper/helpers.rb
CHANGED
@@ -18,27 +18,30 @@ module Sitemapper
|
|
18
18
|
@_title = defs.delete(:title)
|
19
19
|
@_desc = defs.delete(:desc)
|
20
20
|
@_keys = defs.delete(:keywords)
|
21
|
+
return nil # dummies safe!
|
21
22
|
end
|
22
23
|
|
23
24
|
def page_with_object(defs) # :nodoc:
|
24
25
|
return page_without_object(defs) if defs.is_a?(Hash)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
|
27
|
+
lookup_method = lambda do |obj, key|
|
28
|
+
methods = obj.class.respond_to?(:sitemapper_config)? obj.class.sitemapper_config : Sitemapper.meta_lookup
|
29
|
+
methods = methods[key]
|
30
|
+
method = if methods.is_a?(Array)
|
31
|
+
methods.find {|m| obj.respond_to?(m)}
|
32
|
+
elsif methods.is_a?(String) || methods.is_a?(Symbol)
|
33
|
+
methods
|
34
|
+
end
|
35
|
+
logger.debug(">>> #{method}")
|
36
|
+
return method.nil?? nil : obj.send(method)
|
37
|
+
end # Do you think it's ugly? You have to see my grandma in underwear
|
38
|
+
|
39
|
+
@_title = lookup_method.call(defs, :title)
|
40
|
+
@_desc = lookup_method.call(defs, :desc)
|
41
|
+
@_keys = lookup_method.call(defs, :keywords)
|
40
42
|
end
|
41
|
-
|
43
|
+
alias_method :page_without_object, :page
|
44
|
+
alias_method :page, :page_with_object
|
42
45
|
|
43
46
|
# Returns the title of the page with the website title
|
44
47
|
#
|