milk-it-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 CHANGED
@@ -7,17 +7,132 @@ auto generation.
7
7
 
8
8
  You can install the development version with
9
9
 
10
- % sudo gem sources -a http://gems.github.com # (you only need to do this once)
11
- % sudo gem install milk-it-sitemapper
10
+ % sudo gem install milk-it-sitemapper -s http://gems.github.com
12
11
 
13
12
  Or the release version with
14
13
 
15
14
  % sudo gem install sitemapper
16
15
 
17
16
 
18
- == Example
17
+ == Examples
19
18
 
20
- TODO: examples
19
+ === Ruby On Rails
20
+
21
+ Sitemapper will automagically generate a sitemap.xml file for you when
22
+ your rails application start, this sitemap.xml will include all your
23
+ URLs that Sitemapper consider 'static', for example:
24
+
25
+ map.todo '/to-do' # Sitemapper will consider this as static
26
+ map.articles '/articles/:year/:month' # Will be considered this dynamic
27
+ map.connect '*path' # Will be considered dynamic
28
+
29
+ The generation of your sitemap.xml will happen on your application boot,
30
+ but it won't delete any URL previous added (we hope to be able to do so
31
+ very soon - a merge).
32
+
33
+ In your application, you can use the accessors provided by Sitemapper to
34
+ dynamically add URLs, for example, supose a blog app:
35
+
36
+ class ArticlesController < ApplicationController
37
+ ...
38
+ def create
39
+ # do all the creation stuff
40
+ map_url(article_url(@article)) # add the URL to your sitemap
41
+ end
42
+
43
+ def destroy
44
+ # do all the deletion stuff
45
+ unmap_url(article_url(@article))
46
+ end
47
+ ...
48
+ end
49
+
50
+ You can also do it on your sweepers (which is a better choice)
51
+
52
+ class ArticleSweeper < ActionController::Caching::Sweeper
53
+ observe Article, Account
54
+
55
+ def after_create(record)
56
+ # expire everything you need
57
+ map_url(polymorphic_url(record))
58
+ end
59
+
60
+ def after_destroy(record)
61
+ # expire everything you need
62
+ map_url(polymorphic_url(record))
63
+ end
64
+ end
65
+
66
+ === Merb
67
+
68
+ Sorry, we do not support Merb yet. (Actually, it will depend on the
69
+ demand)
70
+
71
+ === Other SEO techniques
72
+
73
+ With SEO, you'll have some view helpers to easily apply some SEO
74
+ techniques to your website/webapp.
75
+
76
+ In your application layout, just do it:
77
+
78
+ <head>
79
+ <%= title('My Personal Blog') %>
80
+ <%= page_meta %>
81
+ </head>
82
+
83
+ And in your action views, you put this:
84
+
85
+ <% page(:title => 'Contact',
86
+ :desc => 'Here you'll can contact our customer support ...',
87
+ :keywords => 'contact, support, customer') %>
88
+
89
+ In this case, the view will be rendered in this way:
90
+
91
+ <head>
92
+ <title>Contact :: My Personal Blog</title>
93
+ <meta name="description" content="Here you'll can contact our customer support ..." />
94
+ <meta name="keywords" content="contact, support, customer" />
95
+ </head>
96
+
97
+ If you want to change the title separator, just do:
98
+
99
+ ...
100
+ <%= title('My Personal Blog', :separator => ' - ') %>
101
+ ...
102
+
103
+ Or, you can als use any object that respond to title or name (for
104
+ page title), short_description or description, tag_list or keywords.
105
+
106
+ <% page(@event) %>
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
+
124
+ If you want to suggest any other SEO technique, suggest it on
125
+ carlos@milk-it.net
126
+
127
+ === Hope you enjoy!
128
+
129
+ == To do:
130
+
131
+ * Add sitemap options to routes
132
+ * Create separate files for dynamic and static routes (then, we'll can
133
+ delete all the static on startup)
134
+ * Write test code (sorry, I really didn't it)
135
+ * Write the Sitemapper::Map#map_urls method
21
136
 
22
137
  Copyright (c) 2008 Carlos Júnior, released under the MIT license
23
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
@@ -4,3 +4,4 @@ if Object.const_defined?('Rails')
4
4
  require 'sitemapper/adapters/rails_adapter'
5
5
  Sitemapper::Adapters::RailsAdapter.install!
6
6
  end
7
+ Object.send(:include, Sitemapper::ObjectMapper)
@@ -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
- @_title = if defs.respond_to?(:title)
26
- defs.title
27
- elsif defs.respond_to?(:name)
28
- defs.name
29
- end
30
- @_desc = if defs.respond_to?(:short_description)
31
- defs.short_description
32
- elsif defs.respond_to?(:description)
33
- defs.description
34
- end
35
- @_keys = if defs.respond_to?(:tag_list)
36
- defs.tag_list
37
- elsif defs.respond_to?(:keywords)
38
- defs.keywords
39
- end
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
- alias_method_chain :page, :object
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
  #
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, 2, 0 #:nodoc:
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milk-it-sitemapper
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
  - Carlos Junior