zomgrss 1.0.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/.document +3 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.markdown +170 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/examples/active_record_sample.rb +23 -0
- data/examples/datamapper_sample.rb +33 -0
- data/lib/zomgrss.rb +60 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/zomgrss_spec.rb +156 -0
- data/zomgrss.gemspec +59 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Federico Builes
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
ZOMGRSS
|
2
|
+
=======
|
3
|
+
ZOMGRSS is a Ruby gem to create RSS feeds from your Ruby collections.
|
4
|
+
|
5
|
+
Installation
|
6
|
+
-----------
|
7
|
+
|
8
|
+
$ gem install zomgrss
|
9
|
+
|
10
|
+
Example
|
11
|
+
-------
|
12
|
+
|
13
|
+
class BlogPost < ActiveRecord::Base
|
14
|
+
rss_me
|
15
|
+
end
|
16
|
+
|
17
|
+
print BlogPost.to_rss
|
18
|
+
|
19
|
+
# => (no line-breaks in original)
|
20
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
21
|
+
<rss version="2.0">
|
22
|
+
<channel>
|
23
|
+
<title>Your blog!</title>
|
24
|
+
<description>A nice description of your emo posts</description>
|
25
|
+
<link>http://example.com/blog</link>
|
26
|
+
<item>
|
27
|
+
<title>My first post</title>
|
28
|
+
<link isPermaLink="false">http://example.com/blog/1</link>
|
29
|
+
<description>Isnt this super interesting?</description>
|
30
|
+
<pubDate>Sat, 22 May 2010 21:38:17 -0500</pubDate>
|
31
|
+
<guid>1@http://exmaple.com/blog/</guid>
|
32
|
+
</item>
|
33
|
+
<item>
|
34
|
+
<title>My second post</title>
|
35
|
+
<link isPermaLink="false">http://example.com/blog/2</link>
|
36
|
+
<description>I wish my lawn was emo so I could stop doing silly jokes</description>
|
37
|
+
<pubDate>Sat, 22 May 2010 21:38:17 -0500</pubDate>
|
38
|
+
<guid>2@http://exmaple.com/blog/</guid>
|
39
|
+
</item>
|
40
|
+
</channel>
|
41
|
+
</rss>
|
42
|
+
|
43
|
+
You can see more examples in the `examples/` folder.
|
44
|
+
|
45
|
+
Usage
|
46
|
+
-----
|
47
|
+
For a basic dose of ZOMGRSS just call `rss_me` in your class and then call `Class.to_rss`. Example:
|
48
|
+
|
49
|
+
class BlogPost
|
50
|
+
include DataMapper::Resource
|
51
|
+
rss_me
|
52
|
+
|
53
|
+
property :id, Serial
|
54
|
+
property :title, String, :required => true
|
55
|
+
property :body, Text, :required => true
|
56
|
+
property :created_at, DateTime
|
57
|
+
end
|
58
|
+
|
59
|
+
BlogPost.to_rss # => returns the RSS feed for all the objects in BlogPost.
|
60
|
+
|
61
|
+
ZOMGRSS expects your class to have four basic attributes: `id`, `title`, `body` and `created_at`. These
|
62
|
+
are used to populate the RSS title, description, GUID and pubDate fields of each item in your feed. Users
|
63
|
+
of DataMapper and ActiveRecord should have instant access to the `id` and `created_at` fields. Read
|
64
|
+
Custom Options to find out how to modify these.
|
65
|
+
|
66
|
+
Your RSS feed also include three important fields:
|
67
|
+
|
68
|
+
* `title`: Your feed's title (i.e. _Brian's Emo Blog_)
|
69
|
+
* `description`: A description of your feed (i.e. _I'm Brian and I like to cut myself._)
|
70
|
+
* `base_url`: A base URL for your feed (i.e. _http://blog.emobrian.com/_)
|
71
|
+
|
72
|
+
To set these fields just call the `rss_options` class method:
|
73
|
+
|
74
|
+
BlogPost.rss_options[:title] = "My new not emo blog"
|
75
|
+
BlogPost.rss_options[:description] = "Emo no more, I'm HipsterBrian now"
|
76
|
+
BlogPost.rss_options[:base_url] = "http://blog.hipsterbrian.com/"
|
77
|
+
|
78
|
+
You'll also want to modify the `link_format` option, which specifies the format of the links used
|
79
|
+
in your site. A typical site will use the same URL for every item, changing only the ID of the
|
80
|
+
post. An example of the link format for Brian's Hipster blog would be:
|
81
|
+
|
82
|
+
BlogPost.rss_options[:link_format] = "http://blog.hipsterbrian.com/:id"
|
83
|
+
|
84
|
+
ZOMGRSS would replace `:id` with the object's ID field.
|
85
|
+
|
86
|
+
|
87
|
+
Custom Options
|
88
|
+
---------------
|
89
|
+
### Custom Method Names
|
90
|
+
|
91
|
+
If your class uses different names for the necessary methods (`title`, `body` and `created_at`) you
|
92
|
+
can set them in the rss_options. If you had the following class:
|
93
|
+
|
94
|
+
class BlogPost
|
95
|
+
include DataMapper::Resource
|
96
|
+
rss_me
|
97
|
+
|
98
|
+
property :id, Serial
|
99
|
+
property :title_text, String, :required => true
|
100
|
+
property :description, Text, :required => true
|
101
|
+
property :created, DateTime
|
102
|
+
end
|
103
|
+
|
104
|
+
You'd have to set the following options:
|
105
|
+
|
106
|
+
BlogPost.rss_options[:title_method] = :title_text
|
107
|
+
BlogPost.rss_options[:body_method] = :description
|
108
|
+
BlogPost.rss_options[:date_method] = :created
|
109
|
+
|
110
|
+
And then call the `to_rss` class method as you normally would:
|
111
|
+
|
112
|
+
BlogPost.to_rss
|
113
|
+
|
114
|
+
|
115
|
+
### Custom Finders
|
116
|
+
|
117
|
+
Sometimes you'll want to create an RSS feed of only certain objects. By default ZOMGRSS uses `:all`
|
118
|
+
as the finder, meaning it will call YourClass.all to find the records to be included in the feed. If
|
119
|
+
you want to use a different finder you can modify it through the `:finder` option:
|
120
|
+
|
121
|
+
class BlogPost < ActiveRecord::Base
|
122
|
+
rss_me
|
123
|
+
|
124
|
+
# return only 5 records
|
125
|
+
named_scope :only_five, { :limit => 5 }
|
126
|
+
end
|
127
|
+
|
128
|
+
BlogPost.rss_options[:finder] = :only_five
|
129
|
+
BlogPost.to_rss # => Will create a feed with only 5 items.
|
130
|
+
|
131
|
+
You can also pass options to your custom finders to use more complex queries:
|
132
|
+
|
133
|
+
class BlogPost < ActiveRecord::Base
|
134
|
+
rss_me
|
135
|
+
|
136
|
+
# returns 'max-min' records
|
137
|
+
named_scope :limit, lambda { |max, min| { :limit => (max - min) } }
|
138
|
+
end
|
139
|
+
|
140
|
+
BlogPost.rss_options[:finder] = :limit
|
141
|
+
BlogPost.rss_options[:finder_options] = [10,5]
|
142
|
+
BlogPost.to_rss # => Creates a feed with only 5 items.
|
143
|
+
|
144
|
+
### GUIDs
|
145
|
+
|
146
|
+
Every RSS item needs to have an unique identifier. The current format used by ZOMGRSS follows the
|
147
|
+
Movable Type convention: "id@http://example.com" (as in _342@http://blog.hipsterbrian.com_). If you
|
148
|
+
need to change this you can set a custom GUID format:
|
149
|
+
|
150
|
+
BlogPost.rss_options[:guid_format] = "http://blog.hipsterbrian.com/unique/:id"
|
151
|
+
|
152
|
+
ZOMGRSS will replace the `:id` in the format for the object's ID.
|
153
|
+
|
154
|
+
|
155
|
+
TODO
|
156
|
+
----
|
157
|
+
* Allow the user to set global default options. Right now you'll have to set the default options for
|
158
|
+
each new RSS feed you want to create.
|
159
|
+
* Support for Atom?
|
160
|
+
* Allow lambdas instead of methods in rss_options (useful to return a text snippet of a field).
|
161
|
+
* Create Rubygem (iknorite?)
|
162
|
+
* Generate static .xml files.
|
163
|
+
|
164
|
+
Most of these can be easily implemented but I haven't needed them so far. If you'd like to see them
|
165
|
+
included please let me know through an Issue in the [Github Tracker](http://github.com/febuiles/zomgrss/issues).
|
166
|
+
|
167
|
+
Contact
|
168
|
+
--------
|
169
|
+
* **Email**: federico@mheroin.com
|
170
|
+
* **Issues**: [Github Tracker](http://github.com/febuiles/zomgrss/issues)
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "zomgrss"
|
8
|
+
gem.summary = "Create RSS feeds from Ruby collections."
|
9
|
+
gem.description = "Create RSS feeds from Ruby collections."
|
10
|
+
gem.email = "federico@mheroin.com"
|
11
|
+
gem.homepage = "http://github.com/febuiles/zomgrss"
|
12
|
+
gem.authors = ["Federico Builes"]
|
13
|
+
gem.add_development_dependency "builder"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
21
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Default: run specs.'
|
25
|
+
task :default => :spec
|
26
|
+
|
27
|
+
require 'rake/rdoctask'
|
28
|
+
Rake::RDocTask.new do |rdoc|
|
29
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
30
|
+
|
31
|
+
rdoc.rdoc_dir = 'rdoc'
|
32
|
+
rdoc.title = "zomgrss #{version}"
|
33
|
+
rdoc.rdoc_files.include('README*')
|
34
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
35
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', '/lib/zomgrss.rb')
|
3
|
+
|
4
|
+
# Run the do.rb example first to create the samples database.
|
5
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => "sample.db")
|
6
|
+
|
7
|
+
class BlogPost < ActiveRecord::Base
|
8
|
+
rss_me
|
9
|
+
named_scope :limit, lambda { |max, min| { :limit => (max - min) } }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set options for the RSS generator.
|
13
|
+
BlogPost.rss_options[:title] = "My new not emo blog"
|
14
|
+
BlogPost.rss_options[:description] = "Emo no more, I'm HipsterBrian now"
|
15
|
+
BlogPost.rss_options[:base_url] = "http://blog.hipsterbrian.com/"
|
16
|
+
BlogPost.rss_options[:link_format] = "http://blog.hipsterbrian.com/:id"
|
17
|
+
|
18
|
+
# Use a custom finder for items
|
19
|
+
BlogPost.rss_options[:finder] = :limit
|
20
|
+
BlogPost.rss_options[:finder_options] = [10, 9]
|
21
|
+
|
22
|
+
|
23
|
+
print BlogPost.to_rss
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-timestamps'
|
3
|
+
require File.join(File.dirname(__FILE__), '..', '/lib/zomgrss.rb')
|
4
|
+
|
5
|
+
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/sample.db")
|
6
|
+
|
7
|
+
class BlogPost
|
8
|
+
include DataMapper::Resource
|
9
|
+
rss_me
|
10
|
+
|
11
|
+
property :id, Serial
|
12
|
+
property :title, String, :required => true
|
13
|
+
property :body, Text, :required => true
|
14
|
+
property :created_at, DateTime
|
15
|
+
end
|
16
|
+
|
17
|
+
DataMapper.auto_upgrade!
|
18
|
+
|
19
|
+
# Create some sample posts...
|
20
|
+
BlogPost.create(:title => "My first post", :body => "Isnt this super interesting?")
|
21
|
+
BlogPost.create(:title => "My second post", :body => "I wish my lawn was emo so I could stop doing silly jokes")
|
22
|
+
|
23
|
+
# Set default options for the RSS generator.
|
24
|
+
BlogPost.rss_options[:title] = "My new not emo blog"
|
25
|
+
BlogPost.rss_options[:description] = "Emo no more, I'm HipsterBrian now"
|
26
|
+
BlogPost.rss_options[:base_url] = "http://blog.hipsterbrian.com/"
|
27
|
+
BlogPost.rss_options[:link_format] => "http://blog.hipsterbrian.com/:id"
|
28
|
+
|
29
|
+
# This is the resulting RSS.
|
30
|
+
print BlogPost.to_rss
|
31
|
+
|
32
|
+
|
33
|
+
|
data/lib/zomgrss.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'builder'
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
def rss_me
|
5
|
+
self.extend ZOMGRSS
|
6
|
+
end
|
7
|
+
|
8
|
+
module ZOMGRSS
|
9
|
+
def to_rss
|
10
|
+
finder = rss_options[:finder]
|
11
|
+
finder_options = rss_options[:finder_options]
|
12
|
+
|
13
|
+
if finder_options
|
14
|
+
items = self.send(finder, *finder_options)
|
15
|
+
else
|
16
|
+
items = self.send(finder)
|
17
|
+
end
|
18
|
+
|
19
|
+
xml = Builder::XmlMarkup.new
|
20
|
+
|
21
|
+
xml.instruct! :xml, :version => '1.0'
|
22
|
+
xml.rss :version => "2.0" do
|
23
|
+
xml.channel do
|
24
|
+
xml.title rss_options[:title]
|
25
|
+
xml.description rss_options[:description]
|
26
|
+
xml.link rss_options[:base_url]
|
27
|
+
|
28
|
+
items.each do |item|
|
29
|
+
xml.item do
|
30
|
+
xml.title item.send(rss_options[:title_method])
|
31
|
+
xml.link(rss_options[:link_format].gsub(":id", item.id.to_s), :isPermaLink => false)
|
32
|
+
xml.description item.send(rss_options[:body_method])
|
33
|
+
xml.pubDate Time.parse(item.send(rss_options[:date_method]).to_s).rfc822()
|
34
|
+
xml.guid rss_options[:guid_format].gsub(":id", item.id.to_s)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def rss_options(rss_options={ })
|
42
|
+
@rss_opts = (@rss_opts || self.default_rss_options).merge(rss_options)
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def default_rss_options
|
47
|
+
{
|
48
|
+
:title => "Your blog!",
|
49
|
+
:description => "A nice description of your emo posts",
|
50
|
+
:base_url => "http://example.com/blog",
|
51
|
+
:body_method => :body,
|
52
|
+
:title_method => :title,
|
53
|
+
:link_format => "http://example.com/blog/:id",
|
54
|
+
:date_method => :created_at,
|
55
|
+
:guid_format => ":id@http://example.com/blog/", # works nicely when switching domains.
|
56
|
+
:finder => :all,
|
57
|
+
:finder_options => nil
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '/lib/zomgrss.rb')
|
2
|
+
require 'spec'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class SuperSomething
|
6
|
+
attr_reader :id, :title, :body, :created_at
|
7
|
+
|
8
|
+
rss_me
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
self.some(3)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(date)
|
15
|
+
@id = 4 # chosen by a fair dice roll, guaranteed to be random.
|
16
|
+
@title = "SuperTitle!"
|
17
|
+
@body = '<p><img src="http://mheroin.com/img.jpg" />SuperBody!!</p>'
|
18
|
+
@created_at = date
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.some(lim=1, date=Time.utc(1987, "apr", 4, 2, 0, 0))
|
22
|
+
Array.new(lim, SuperSomething.new(date))
|
23
|
+
end
|
24
|
+
|
25
|
+
def fecha; @created_at; end
|
26
|
+
def titulo; @title; end
|
27
|
+
def cuerpo; @body; end
|
28
|
+
end
|
29
|
+
|
30
|
+
def base_url
|
31
|
+
"http://mheroin.com"
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_options
|
35
|
+
SuperSomething.send(:default_rss_options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_feed
|
39
|
+
@feed = Nokogiri::XML(SuperSomething.to_rss)
|
40
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Installation" do
|
4
|
+
it "is done by calling 'rss_me'" do
|
5
|
+
lambda { class Throwaway; rss_me; end }.should_not raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
it "provides .to_rss to the class" do
|
9
|
+
c = class Throwaway; rss_me; end
|
10
|
+
c.should respond_to(:to_rss)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Options" do
|
15
|
+
it "provides default options if there are none set" do
|
16
|
+
SuperSomething.rss_options.should == default_options
|
17
|
+
end
|
18
|
+
|
19
|
+
it "adds options to the current options if they exist" do
|
20
|
+
SuperSomething.rss_options(:title => "My new title")
|
21
|
+
SuperSomething.rss_options.should == default_options.merge(:title => "My new title")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "includes a feed title" do
|
25
|
+
SuperSomething.rss_options[:title].should_not be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "includes a feed description" do
|
29
|
+
SuperSomething.rss_options[:description].should_not be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes a feed base URL" do
|
33
|
+
SuperSomething.rss_options[:base_url].should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "includes a custom title method, defaulted to :title" do
|
37
|
+
SuperSomething.rss_options[:title_method].should == :title
|
38
|
+
end
|
39
|
+
|
40
|
+
it "includes a custom body method, defaulted to :body" do
|
41
|
+
SuperSomething.rss_options[:body_method].should == :body
|
42
|
+
end
|
43
|
+
|
44
|
+
it "includes a link format for the feed items" do
|
45
|
+
SuperSomething.rss_options[:link_format].should_not be_nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "includes a date field for the feed items, defaulted to :created_at" do
|
49
|
+
SuperSomething.rss_options[:date_method].should == :created_at
|
50
|
+
end
|
51
|
+
|
52
|
+
it "includes a GUID format for the feed items" do
|
53
|
+
SuperSomething.rss_options[:guid_format].should_not be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it "includes a custom finder method, defaulted to :all" do
|
57
|
+
SuperSomething.rss_options[:finder].should == :all
|
58
|
+
end
|
59
|
+
|
60
|
+
it "includes the options for the custom finder method, defaulted to nil" do
|
61
|
+
SuperSomething.rss_options[:finder_options].should be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "ZOMGRSS.to_rss" do
|
66
|
+
before :each do
|
67
|
+
parse_feed
|
68
|
+
end
|
69
|
+
|
70
|
+
after :each do
|
71
|
+
SuperSomething.rss_options(default_options)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns a a well formed RSS feed" do
|
75
|
+
@feed.errors.should be_empty
|
76
|
+
end
|
77
|
+
|
78
|
+
it "uses the correct feed base data" do
|
79
|
+
@feed.at_css("channel title").text.should == default_options[:title]
|
80
|
+
@feed.at_css("channel description").text.should == default_options[:description]
|
81
|
+
@feed.at_css("channel link").text.should == default_options[:base_url]
|
82
|
+
end
|
83
|
+
|
84
|
+
it "replaces :link_format with the actual item link" do
|
85
|
+
expected = default_options[:link_format].gsub(":id", "4")
|
86
|
+
@feed.at_css("channel item link").text.should == expected
|
87
|
+
end
|
88
|
+
|
89
|
+
it "uses :created_at or a custom field for the item's date" do
|
90
|
+
expected = "Sat, 04 Apr 1987 02:00:00 -0000"
|
91
|
+
@feed.at_css("channel item pubDate").text.should == expected
|
92
|
+
|
93
|
+
SuperSomething.rss_options(:date_method => :fecha)
|
94
|
+
@feed.at_css("channel item pubDate").text.should == expected
|
95
|
+
end
|
96
|
+
|
97
|
+
it "generates a MovableType-like GUID from the items " do
|
98
|
+
expected = default_options[:guid_format].gsub(":id", "4")
|
99
|
+
@feed.at_css("channel item guid").text.should == expected
|
100
|
+
end
|
101
|
+
|
102
|
+
it "can use a custom GUID format" do
|
103
|
+
expected = "http://something.com/4"
|
104
|
+
|
105
|
+
SuperSomething.rss_options[:guid_format] = "http://something.com/:id"
|
106
|
+
parse_feed
|
107
|
+
@feed.at_css("channel item guid").text.should == expected
|
108
|
+
end
|
109
|
+
|
110
|
+
it "can use a custom finder to fetch the objects" do
|
111
|
+
@feed.css("channel item").length.should == 3
|
112
|
+
|
113
|
+
SuperSomething.rss_options[:finder] = :some
|
114
|
+
parse_feed
|
115
|
+
@feed.css("channel item").length.should == 1
|
116
|
+
end
|
117
|
+
|
118
|
+
it "can pass custom options to the finder" do
|
119
|
+
@feed.css("channel item").length.should == 3
|
120
|
+
|
121
|
+
SuperSomething.rss_options[:finder] = :some
|
122
|
+
SuperSomething.rss_options[:finder_options] = 2
|
123
|
+
parse_feed
|
124
|
+
@feed.css("channel item").length.should == 2
|
125
|
+
end
|
126
|
+
|
127
|
+
it "explodes custom finder options" do
|
128
|
+
@feed.css("channel item").length.should == 3
|
129
|
+
|
130
|
+
SuperSomething.rss_options[:finder] = :some
|
131
|
+
SuperSomething.rss_options[:finder_options] = [2, Time.utc(1987, "may", 4, 2, 0, 0)]
|
132
|
+
parse_feed
|
133
|
+
@feed.css("channel item").length.should == 2
|
134
|
+
@feed.at_css("channel item pubDate").text.should == "Mon, 04 May 1987 02:00:00 -0000"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "supports custom title methods" do
|
138
|
+
@feed.at_css("channel item title").text.should == "SuperTitle!"
|
139
|
+
|
140
|
+
SuperSomething.rss_options[:title_method] = :titulo
|
141
|
+
parse_feed
|
142
|
+
@feed.at_css("channel item title").text.should == "SuperTitle!"
|
143
|
+
end
|
144
|
+
|
145
|
+
it "supports custom body methods" do
|
146
|
+
@feed.at_css("channel item description").text.should == '<p><img src="http://mheroin.com/img.jpg" />SuperBody!!</p>'
|
147
|
+
|
148
|
+
SuperSomething.rss_options[:body_method] = :cuerpo
|
149
|
+
parse_feed
|
150
|
+
@feed.at_css("channel item description").text.should == '<p><img src="http://mheroin.com/img.jpg" />SuperBody!!</p>'
|
151
|
+
end
|
152
|
+
|
153
|
+
it "uses a GUID with isPermaLink=false" do
|
154
|
+
@feed.at_css("channel item link").attributes["isPermaLink"].text.should == "false"
|
155
|
+
end
|
156
|
+
end
|
data/zomgrss.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{zomgrss}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Federico Builes"]
|
12
|
+
s.date = %q{2010-05-22}
|
13
|
+
s.description = %q{Create RSS feeds from Ruby collections.}
|
14
|
+
s.email = %q{federico@mheroin.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"examples/active_record_sample.rb",
|
27
|
+
"examples/datamapper_sample.rb",
|
28
|
+
"lib/zomgrss.rb",
|
29
|
+
"spec/spec.opts",
|
30
|
+
"spec/spec_helper.rb",
|
31
|
+
"spec/zomgrss_spec.rb",
|
32
|
+
"zomgrss.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/febuiles/zomgrss}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Create RSS feeds from Ruby collections.}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/spec_helper.rb",
|
41
|
+
"spec/zomgrss_spec.rb",
|
42
|
+
"examples/active_record_sample.rb",
|
43
|
+
"examples/datamapper_sample.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<builder>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<builder>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<builder>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zomgrss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Federico Builes
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-05-22 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: builder
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Create RSS feeds from Ruby collections.
|
36
|
+
email: federico@mheroin.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.markdown
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.markdown
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- examples/active_record_sample.rb
|
52
|
+
- examples/datamapper_sample.rb
|
53
|
+
- lib/zomgrss.rb
|
54
|
+
- spec/spec.opts
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- spec/zomgrss_spec.rb
|
57
|
+
- zomgrss.gemspec
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/febuiles/zomgrss
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 3
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Create RSS feeds from Ruby collections.
|
92
|
+
test_files:
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/zomgrss_spec.rb
|
95
|
+
- examples/active_record_sample.rb
|
96
|
+
- examples/datamapper_sample.rb
|