gryphon_sitemap 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # GryphonSitemap
2
+
3
+ Adds a very simple sitemap generator for well-behaved classes.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/skandragon/gryphon_sitemap.png?branch=master)](http://travis-ci.org/skandragon/gryphon_sitemap)
6
+
7
+ Generate Rails sitemaps and sitemap indexes for well-behaved models quickly and mostly painlessly. In this context, a "sitemap" is what a search engine uses to find content on your site, and is required for "hidden" content. For example, if you have a search field, indexing won't reach past that. You could use GryphonSitemap to provide direct links to each item that could be returned in a search.
8
+
9
+ GryphonSitemap generates a sitemap index (usually at /sitemap.xml) which contains pointers to all the other sitemaps for the static and dynamic content.
10
+
11
+ In the default index, no last-modified times are provided. In each sitemap page for actual items, the updated_at value is used to provide the timestamp, and a standard link is made for each item.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'gryphon_sitemap'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install gryphon_sitemap
26
+
27
+ ## Usage
28
+
29
+ In your models:
30
+
31
+ has_sitemap
32
+
33
+ By default, 5,000 items are included in each page.
34
+ You may choose to change this if this puts too much load on your server,
35
+ or you just wish to have more pages with less on each. You may customize
36
+ this with:
37
+
38
+ has_sitemap :per_page => 50
39
+
40
+ To minimize database load, only :id and :updated_at are retrieved.
41
+ In some cases, these are not sufficient when a custom to_param method
42
+ is used. In these cases, you may add additional fields to fetch for
43
+ each item:
44
+
45
+ has_sitemap :fields => [ :first_name, :last_name ]
46
+
47
+ This would be useful for a to_param such as:
48
+
49
+ ```ruby
50
+ def to_param
51
+ "#{id}-#{first_name.downcase.parameterize}-#{last_name.downcase.parameterize}"
52
+ end
53
+ ```
54
+
55
+ ### Routing
56
+
57
+ You must add a route manually. For the sample SitemapController shown below, you
58
+ would use:
59
+
60
+ resources :sitemap
61
+
62
+ ### Controller
63
+
64
+ Currently, a fair bit of code is required in a controller you must provide.
65
+ Here is an example which handles some static content (see below for the XML used),
66
+ two models with custom XML templates (see below), and several "automatic" models.
67
+
68
+ The hash key, if dynamic, should map to a class name: "sony_characters" would
69
+ be "SonyCharacter", etc. There is currently no way to override the automatic
70
+ class name discovery.
71
+
72
+ The method indexed_pages returns a hash with keys being page names. The
73
+ configuration of number of pages can be set, which is common for static templates,
74
+ or marked as dynamic. If it is dynamic, the page count provided is ignored, and
75
+ each time the sitemap index is retrieved, the model is counted.
76
+
77
+ ```ruby
78
+ class SitemapController < ApplicationController
79
+ include GryphonSitemap::SitemapController
80
+
81
+ respond_to :xml
82
+
83
+ def static
84
+ end
85
+
86
+ def classes
87
+ @classes = Character::ADVENTURE_CLASS_NAMES
88
+ end
89
+
90
+ def zones
91
+ @items = Zone.all
92
+ end
93
+
94
+ private
95
+
96
+ def indexed_pages
97
+ {
98
+ static: { pages: 1 },
99
+ classes: { pages: 1 },
100
+ zones: { pages: 1 },
101
+ sony_characters: { dynamic: true },
102
+ sony_guilds: { dynamic: true },
103
+ sony_items: { dynamic: true }
104
+ }
105
+ end
106
+ end
107
+ ```
108
+
109
+ A static template could look like:
110
+
111
+ ```ruby
112
+ xml.instruct!
113
+ xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
114
+ xml.url do
115
+ xml.loc root_url
116
+ xml.changefreq 'daily'
117
+ end
118
+
119
+ for url in [ changelog_about_index_url, contact_about_index_url, developer_about_index_url ]
120
+ xml.url do
121
+ xml.loc url
122
+ xml.changefreq 'weekly'
123
+ end
124
+ end
125
+ end
126
+ ```
127
+
128
+ The custom template for Zones just uses a different URL:
129
+
130
+ ```ruby
131
+ xml.instruct!
132
+ xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
133
+ #
134
+ # Zone Mobs
135
+ #
136
+ for item in @items
137
+ xml.url do
138
+ xml.loc zone_mobs_url(item)
139
+ xml.lastmod item.updated_at.to_s(:w3c)
140
+ end
141
+ end
142
+ end
143
+ ```
144
+
145
+ And the one for "classes" is just iterating through fixed values:
146
+
147
+ ```ruby
148
+ xml.instruct!
149
+ xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
150
+ #
151
+ # adventure class main index page
152
+ #
153
+ xml.url do
154
+ xml.loc adventure_classes_url
155
+ end
156
+
157
+ #
158
+ # spells for classes
159
+ #
160
+ @classes.each do |adventure_class_name|
161
+ xml.url do
162
+ xml.loc adventure_class_spells_url(adventure_class_name)
163
+ end
164
+ end
165
+ end
166
+ ```
167
+
168
+ ### Error Pages
169
+
170
+ It is important to provide a good error page which returns status
171
+ 404 for items that do not exist. The default behavior of Model.find
172
+ will return a server error (500) if the record is not found.
173
+
174
+ I use this in my controllers, coupled with a pleasing to the end user
175
+ (who will see the page if they follow a link) error page:
176
+
177
+ ```ruby
178
+ def show
179
+ @user = User.where(:id => params[:id].to_i).first
180
+ if @user.blank?
181
+ render "not_found", :status => 404
182
+ return
183
+ end
184
+ end
185
+ ```
186
+
187
+ ### robots.txt
188
+
189
+ You will want to add some content to your robots.txt to allow for automatic sitemap
190
+ discovery.
191
+
192
+ ```text
193
+ User-Agent: *
194
+ Disallow: /auth
195
+ Sitemap: http://eq2mission.flame.org/sitemap.xml
196
+ ```
197
+
198
+ ## Authors
199
+
200
+ Michael Graff
201
+ [twitter](https://twitter.com/skandragon)
202
+ [github](https://github.com/skandragon)
@@ -1,3 +1,3 @@
1
1
  module GryphonSitemap
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,5 +1,7 @@
1
1
  Connecting to database specified by database.yml
2
-  (88.9ms) CREATE TABLE "foos" ("id" serial primary key, "name" character varying(255)) 
2
+ Connecting to database specified by database.yml
3
+ Connecting to database specified by database.yml
4
+  (4.5ms) CREATE TABLE "foos" ("id" serial primary key, "name" character varying(255)) 
3
5
   (0.2ms) BEGIN
4
6
   (0.1ms) ROLLBACK
5
7
   (0.1ms) BEGIN
@@ -7,11 +9,11 @@ Connecting to database specified by database.yml
7
9
   (0.0ms) BEGIN
8
10
   (0.1ms) ROLLBACK
9
11
   (0.0ms) BEGIN
10
-  (0.1ms) ROLLBACK
12
+  (0.0ms) ROLLBACK
11
13
   (0.0ms) BEGIN
12
14
   (0.1ms) ROLLBACK
13
-  (0.1ms) BEGIN
15
+  (0.0ms) BEGIN
14
16
   (0.1ms) ROLLBACK
15
-  (0.1ms) BEGIN
17
+  (0.0ms) BEGIN
16
18
   (0.2ms) ROLLBACK
17
-  (28.3ms) DROP TABLE "foos"
19
+  (1.8ms) DROP TABLE "foos"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gryphon_sitemap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
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-10-31 00:00:00.000000000 Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -109,7 +109,7 @@ files:
109
109
  - lib/tasks/gryphon_sitemap_tasks.rake
110
110
  - MIT-LICENSE
111
111
  - Rakefile
112
- - README.rdoc
112
+ - README.md
113
113
  - spec/dummy/app/assets/javascripts/application.js
114
114
  - spec/dummy/app/assets/stylesheets/application.css
115
115
  - spec/dummy/app/controllers/application_controller.rb
@@ -155,15 +155,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
+ segments:
159
+ - 0
160
+ hash: 2211880127869497148
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  none: false
160
163
  requirements:
161
164
  - - ! '>='
162
165
  - !ruby/object:Gem::Version
163
166
  version: '0'
167
+ segments:
168
+ - 0
169
+ hash: 2211880127869497148
164
170
  requirements: []
165
171
  rubyforge_project:
166
- rubygems_version: 1.8.23
172
+ rubygems_version: 1.8.25
167
173
  signing_key:
168
174
  specification_version: 3
169
175
  summary: Simple sitemaps for rails.
@@ -201,4 +207,3 @@ test_files:
201
207
  - spec/gryphon_sitemap_test.rb
202
208
  - spec/pager/pager_spec.rb
203
209
  - spec/spec_helper.rb
204
- has_rdoc:
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = GryphonSitemap
2
-
3
- This project rocks and uses MIT-LICENSE.