tinyatom 0.1.1 → 0.2.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.textile CHANGED
@@ -1,26 +1,79 @@
1
1
  Aims to be the smallest, easiest to use ruby Atom feed generator.
2
2
 
3
- Example usage:
3
+ Currently supports only a subset of the most frequently used Atom fields. This
4
+ example shows everything it can do.
4
5
 
5
6
  <pre>
6
7
  <code>
7
- feed = TinyAtom::Feed.new('http://mysite.com/', 'My Site',
8
- 'http://mysite.com/atom.xml')
9
- feed.add_entry(1, 'entry 1', Time.now, 'http://mysite.com/1')
8
+ require 'tinyatom'
9
+
10
+ feed = TinyAtom::Feed.new(
11
+ 'http://mysite.com/blog/',
12
+ 'My Blog',
13
+ 'http://mysite.com/blog/atom.xml',
14
+
15
+ # optional
16
+
17
+ :author_name => 'me',
18
+ :author_email => 'me@mysite.com',
19
+ :author_uri => 'http://mysite.com/',
20
+
21
+ :hubs => ['http://pubsubhubbub.appspot.com/']
22
+ )
23
+
24
+ feed.add_entry(
25
+ 1,
26
+ 'post 1',
27
+ Time.now,
28
+ 'http://mysite.com/blog/1',
29
+
30
+ # optional
31
+
32
+ :author_name => 'me',
33
+ :author_email => 'me@mysite.com',
34
+ :author_uri => 'http://mysite.com/',
35
+
36
+ :enclosure_type => 'image/png',
37
+ :enclosure_href => 'http://mysite.com/image.png',
38
+ :enclosure_title => 'photo',
39
+ :enclosure_length => 6227, # optional within enclosure
40
+
41
+ :via_type => 'text/html',
42
+ :via_href => 'http://anotherblog.com/posts/999',
43
+ :via_title => 'Look at this photo'
44
+ )
45
+
10
46
  puts feed.make(:indent => 2)
47
+ # open('atom.xml', 'w') { |f| feed.make(:target => f) }
11
48
 
12
49
  <?xml version="1.0" encoding="UTF-8"?>
13
50
  <feed xmlns="http://www.w3.org/2005/Atom">
14
- <title>My Site</title>
15
- <link href="http://mysite.com/atom.xml" rel="self"/>
16
- <updated>2010-05-18T00:19:13-04:00</updated>
17
- <id>http://mysite.com/</id>
51
+ <title>My Blog</title>
52
+ <link rel="self" href="http://mysite.com/blog/atom.xml"/>
53
+ <updated>2010-10-06T20:34:49-04:00</updated>
54
+ <id>http://mysite.com/blog/</id>
55
+ <author>
56
+ <name>me</name>
57
+ <email>me@mysite.com</email>
58
+ <uri>http://mysite.com/</uri>
59
+ </author>
60
+ <link rel="hub" href="http://pubsubhubbub.appspot.com/"/>
18
61
  <entry>
19
- <title>entry 1</title>
20
- <link href="http://mysite.com/1"/>
21
- <id>tag:mysite.com,2010-05-18:1</id>
22
- <updated>Tue May 18 00:19:13 -0400 2010</updated>
62
+ <title>post 1</title>
63
+ <link href="http://mysite.com/blog/1"/>
64
+ <id>tag:mysite.com,2010-10-06:1</id>
65
+ <updated>2010-10-06T20:34:49-04:00</updated>
66
+ <author>
67
+ <name>me</name>
68
+ <email>me@mysite.com</email>
69
+ <uri>http://mysite.com/</uri>
70
+ </author>
71
+ <link type="image/png" rel="enclosure" length="6227" title="photo" href="http://mysite.com/image.png"/>
72
+ <link type="text/html" rel="via" title="Look at this photo" href="http://anotherblog.com/posts/999"/>
23
73
  </entry>
24
74
  </feed>
75
+
25
76
  </code>
26
77
  </pre>
78
+
79
+ Questions and comments: "matthewm@boedicker.org":mailto:matthewm@boedicker.org
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/tinyatom/feed.rb CHANGED
@@ -86,11 +86,24 @@ module TinyAtom
86
86
  end
87
87
  end
88
88
 
89
+ # param name => tag name
90
+ EnclosureOptionalAttrs = {
91
+ :enclosure_length => :length,
92
+ }
93
+
89
94
  # Add enclosure tags if present
90
95
  def enclosure(markup, h)
91
96
  if h[:enclosure_type] and h[:enclosure_href] and h[:enclosure_title]
97
+
98
+ options = {}
99
+ h.each do |k,v|
100
+ if EnclosureOptionalAttrs.include?(k)
101
+ options[EnclosureOptionalAttrs[k]] = v
102
+ end
103
+ end
104
+
92
105
  link(markup, 'enclosure', h[:enclosure_type], h[:enclosure_href],
93
- h[:enclosure_title])
106
+ h[:enclosure_title], options)
94
107
  end
95
108
  end
96
109
 
@@ -102,8 +115,13 @@ module TinyAtom
102
115
  end
103
116
 
104
117
  # Create link tag
105
- def link(markup, rel, type, href, title)
106
- markup.link(:rel => rel, :type => type, :href => href, :title => title)
118
+ def link(markup, rel, type, href, title, options={})
119
+ markup.link({
120
+ :rel => rel,
121
+ :type => type,
122
+ :href => href,
123
+ :title => title
124
+ }.merge(options))
107
125
  end
108
126
 
109
127
  end
data/tinyatom.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tinyatom}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew M. Boedicker"]
12
- s.date = %q{2010-05-18}
12
+ s.date = %q{2010-10-06}
13
13
  s.description = %q{Small and easy to use ruby Atom feed generator.}
14
14
  s.email = %q{matthewm@boedicker.org}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tinyatom
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew M. Boedicker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-18 00:00:00 -04:00
18
+ date: 2010-10-06 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency