xommelier 0.1.2 → 0.1.3
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.md +6 -5
- data/examples/atom.rb +3 -2
- data/lib/xommelier/atom/entry.rb +2 -0
- data/lib/xommelier/atom/feed.rb +2 -0
- data/lib/xommelier/atom/full.rb +3 -0
- data/lib/xommelier/atom/history.rb +31 -0
- data/lib/xommelier/atom/links_extension.rb +15 -0
- data/lib/xommelier/atom/{thread.rb → threading.rb} +9 -5
- data/lib/xommelier/atom.rb +5 -1
- data/lib/xommelier/version.rb +1 -1
- data/spec/fixtures/feed.atom.xml +3 -1
- data/spec/functional/atom_feed_parsing_spec.rb +12 -2
- data/spec/functional/atom_feed_thread_building_spec.rb +2 -2
- data/spec/lib/xommelier_spec.rb +1 -1
- metadata +11 -8
data/README.md
CHANGED
@@ -4,15 +4,14 @@
|
|
4
4
|
|
5
5
|
Xommelier is an XML Object Mapper. You could describe some namespace (e.g. Atom) in ruby DSL and use it for parsing XML to Ruby objects or for building XML from Ruby objects.
|
6
6
|
|
7
|
-
Look into {Xommelier::Atom} and {Xommelier::Atom::
|
7
|
+
Look into {Xommelier::Atom}, {Xommelier::Atom::Threading}, and {Xommelier::Atom::History} module for implementation of http://www.w3.org/2005/Atom namespace, Atom Threading, and Feed Paging and Archiving extensions
|
8
8
|
|
9
9
|
Xommelier is work in progress: [](http://travis-ci.org/alsemyonov/xommelier)
|
10
10
|
|
11
11
|
## Examples with Atom
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
require 'xommelier/atom'
|
15
|
-
require 'xommelier/atom/thread'
|
14
|
+
require 'xommelier/atom/full'
|
16
15
|
```
|
17
16
|
|
18
17
|
### Reading a feed
|
@@ -33,6 +32,7 @@ end
|
|
33
32
|
feed = Xommelier::Atom::Feed.new
|
34
33
|
feed.id = 'http://example.com/blog'
|
35
34
|
feed.title = 'Example.com blog'
|
35
|
+
feed.complete = Xommelier::Atom::History::Complete.new
|
36
36
|
|
37
37
|
entry = feed.entry = Xommelier::Atom::Entry.new(
|
38
38
|
id: 'http://example.com/blog/2012/03/05',
|
@@ -59,7 +59,7 @@ end
|
|
59
59
|
title: ('Hooray! ' * (i + 1)).strip,
|
60
60
|
updated: (5 - i).days.ago
|
61
61
|
).tap do |comment|
|
62
|
-
comment.in_reply_to = Xommelier::Atom::
|
62
|
+
comment.in_reply_to = Xommelier::Atom::Threading::InReplyTo.new(
|
63
63
|
ref: entry.id,
|
64
64
|
href: entry.link.href
|
65
65
|
)
|
@@ -73,9 +73,10 @@ will output:
|
|
73
73
|
|
74
74
|
```xml
|
75
75
|
<?xml version="1.0" encoding="utf-8"?>
|
76
|
-
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
|
76
|
+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:fh="http://purl.org/syndication/history/1.0">
|
77
77
|
<id>http://example.com/blog</id>
|
78
78
|
<title>Example.com blog</title>
|
79
|
+
<fh:complete/>
|
79
80
|
<entry>
|
80
81
|
<id>http://example.com/blog/2012/03/05</id>
|
81
82
|
<title>Happy Xommelier's day!</title>
|
data/examples/atom.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'xommelier/atom'
|
2
|
-
require 'xommelier/atom/
|
2
|
+
require 'xommelier/atom/threading'
|
3
3
|
require 'active_support/core_ext'
|
4
4
|
|
5
5
|
# Reading a feed
|
@@ -15,6 +15,7 @@ end
|
|
15
15
|
feed = Xommelier::Atom::Feed.new
|
16
16
|
feed.id = 'http://example.com/blog'
|
17
17
|
feed.title = 'Example.com blog'
|
18
|
+
feed.complete = Xommelier::Atom::History::Complete.new
|
18
19
|
|
19
20
|
entry = feed.entry = Xommelier::Atom::Entry.new(
|
20
21
|
id: 'http://example.com/blog/2012/03/05',
|
@@ -32,7 +33,7 @@ end
|
|
32
33
|
title: ('Hooray! ' * (i + 1)).strip,
|
33
34
|
updated: (5 - i).days.ago
|
34
35
|
).tap do |comment|
|
35
|
-
comment.in_reply_to = Xommelier::Atom::
|
36
|
+
comment.in_reply_to = Xommelier::Atom::Threading::InReplyTo.new(ref: entry.id, href: entry.link.href)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
data/lib/xommelier/atom/entry.rb
CHANGED
data/lib/xommelier/atom/feed.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'xommelier/atom'
|
2
|
+
|
3
|
+
module Xommelier
|
4
|
+
module Atom
|
5
|
+
module History
|
6
|
+
include Xommelier::Xml
|
7
|
+
|
8
|
+
xmlns 'http://purl.org/syndication/history/1.0', as: :fh
|
9
|
+
|
10
|
+
class Complete < Xml::Element; end
|
11
|
+
class Archive < Xml::Element; end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Feed
|
15
|
+
may do
|
16
|
+
element :complete, type: History::Complete
|
17
|
+
element :archive, type: History::Archive
|
18
|
+
end
|
19
|
+
|
20
|
+
alias complete? complete
|
21
|
+
alias archive? archive
|
22
|
+
|
23
|
+
%w(first last previous next
|
24
|
+
prev-archive next-archive current).each do |rel|
|
25
|
+
define_method(:"#{rel.underscore}_feed_url") do
|
26
|
+
links.find { |link| link.rel == rel && link.type == 'application/atom+xml' }.try(:href)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'xommelier/atom'
|
2
|
+
|
3
|
+
module Xommelier
|
4
|
+
module Atom
|
5
|
+
module LinksExtension
|
6
|
+
def feed_url
|
7
|
+
links.find { |link| link.rel == 'self' && link.type == 'application/atom+xml' }.try(:href)
|
8
|
+
end
|
9
|
+
|
10
|
+
def html_url
|
11
|
+
links.find { |link| link.rel == 'alternate' && link.type == 'text/html' }.try(:href)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -2,7 +2,7 @@ require 'xommelier/atom'
|
|
2
2
|
|
3
3
|
module Xommelier
|
4
4
|
module Atom
|
5
|
-
module
|
5
|
+
module Threading
|
6
6
|
include Xommelier::Xml
|
7
7
|
|
8
8
|
xmlns 'http://purl.org/syndication/thread/1.0', as: :thr
|
@@ -23,15 +23,19 @@ module Xommelier
|
|
23
23
|
# Extends Atom elements
|
24
24
|
class Entry
|
25
25
|
may do
|
26
|
-
element :in_reply_to, type:
|
27
|
-
element :total, type: Integer, ns:
|
26
|
+
element :in_reply_to, type: Threading::InReplyTo, as: Threading::InReplyTo.element_name
|
27
|
+
element :total, type: Integer, ns: Threading.xmlns
|
28
|
+
end
|
29
|
+
|
30
|
+
def replies_feed_url
|
31
|
+
links.find { |link| link.rel == 'replies' && link.type == 'application/atom+xml' }.try(:href)
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
class Link
|
32
36
|
may do
|
33
|
-
attribute :count,
|
34
|
-
attribute :updated, type: Time,
|
37
|
+
attribute :count, type: Integer, ns: Threading.xmlns
|
38
|
+
attribute :updated, type: Time, ns: Threading.xmlns
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
data/lib/xommelier/atom.rb
CHANGED
@@ -16,7 +16,11 @@ module Xommelier
|
|
16
16
|
autoload :Feed, 'xommelier/atom/feed'
|
17
17
|
autoload :Entry, 'xommelier/atom/entry'
|
18
18
|
|
19
|
+
# Common extensions
|
20
|
+
autoload :LinksExtension, 'xommelier/atom/links_extension'
|
21
|
+
|
19
22
|
# Extensions
|
20
|
-
autoload :
|
23
|
+
autoload :Threading, 'xommelier/atom/threading'
|
24
|
+
autoload :History, 'xommelier/atom/history'
|
21
25
|
end
|
22
26
|
end
|
data/lib/xommelier/version.rb
CHANGED
data/spec/fixtures/feed.atom.xml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
|
2
|
+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:fh="http://purl.org/syndication/history/1.0">
|
3
3
|
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
4
4
|
<title type="text">Example Feed</title>
|
5
5
|
<updated>2003-12-13T18:30:20Z</updated>
|
6
6
|
<subtitle type="html">A <em>lot</em> of effort went into making this effortless</subtitle>
|
7
7
|
<link rel="alternate" type="text/html" href="http://example.ru/" />
|
8
8
|
<link rel="self" type="application/atom+xml" href="http://example.ru/feed.atom" />
|
9
|
+
<link rel="next" type="application/atom+xml" href="http://example.ru/feed.atom?page=2" />
|
10
|
+
<fh:archive />
|
9
11
|
<rights>© Mark Pilgrim, 2003</rights>
|
10
12
|
<generator uri="http://example.com/" version="1.0">Example Toolkit</generator>
|
11
13
|
<author>
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'active_support/core_ext/numeric/time'
|
4
|
-
require 'xommelier/atom/
|
4
|
+
require 'xommelier/atom/threading'
|
5
|
+
require 'xommelier/atom/history'
|
5
6
|
|
6
7
|
describe 'Atom feed' do
|
7
8
|
describe 'parsing' do
|
@@ -11,13 +12,15 @@ describe 'Atom feed' do
|
|
11
12
|
subject { feed }
|
12
13
|
|
13
14
|
it { should be_kind_of(Xommelier::Atom::Feed) }
|
15
|
+
it { should respond_to(:complete?) }
|
16
|
+
it { should respond_to(:archive?) }
|
14
17
|
|
15
18
|
its(:id) { should == 'urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6' }
|
16
19
|
its(:title) { should == 'Example Feed' }
|
17
20
|
its(:updated) { should == Time.utc(2003, 12, 13, 18, 30, 20) }
|
18
21
|
its(:subtitle) { should == 'A <em>lot</em> of effort went into making this effortless' }
|
19
22
|
|
20
|
-
it { should have(
|
23
|
+
it { should have(3).links }
|
21
24
|
its(:link) { should be_instance_of(Xommelier::Atom::Link) }
|
22
25
|
it { feed.links[0].href.should == URI.parse('http://example.ru/') }
|
23
26
|
it { feed.links[0].rel.should == 'alternate' }
|
@@ -25,7 +28,12 @@ describe 'Atom feed' do
|
|
25
28
|
it { feed.links[1].href.should == URI.parse('http://example.ru/feed.atom') }
|
26
29
|
it { feed.links[1].rel.should == 'self' }
|
27
30
|
it { feed.links[1].type.should == 'application/atom+xml' }
|
31
|
+
its(:feed_url) { should == URI.parse('http://example.ru/feed.atom') }
|
32
|
+
its(:html_url) { should == URI.parse('http://example.ru/') }
|
33
|
+
its(:next_feed_url) { should == URI.parse('http://example.ru/feed.atom?page=2') }
|
28
34
|
|
35
|
+
its(:archive) { should be_true }
|
36
|
+
its(:complete) { should be_false }
|
29
37
|
its(:rights) { should == '© Mark Pilgrim, 2003' }
|
30
38
|
describe 'Generator' do
|
31
39
|
subject { feed.generator }
|
@@ -65,6 +73,8 @@ describe 'Atom feed' do
|
|
65
73
|
it { entry.links[2].type.should == 'application/atom+xml' }
|
66
74
|
it { entry.links[2].count.should == 1 }
|
67
75
|
it { entry.links[2].updated.should == Time.utc(2003, 12, 13, 18, 30, 20) }
|
76
|
+
its(:html_url) { should == URI.parse('http://example.ru/2003/12/13/atom03') }
|
77
|
+
its(:replies_feed_url) { should == URI.parse('http://example.ru/2003/12/13/atom03/comments.atom') }
|
68
78
|
|
69
79
|
it { should have(1).authors }
|
70
80
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'xommelier/atom/
|
2
|
+
require 'xommelier/atom/threading'
|
3
3
|
|
4
4
|
describe 'Atom feed building' do
|
5
5
|
let(:feed) do
|
@@ -23,7 +23,7 @@ describe 'Atom feed building' do
|
|
23
23
|
title: 'Comment',
|
24
24
|
updated: Time.utc(2003, 12, 13, 18, 30, 02)
|
25
25
|
).tap do |entry|
|
26
|
-
entry.in_reply_to = Xommelier::Atom::
|
26
|
+
entry.in_reply_to = Xommelier::Atom::Threading::InReplyTo.new(ref: 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a')
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/spec/lib/xommelier_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xommelier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &70163686772120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70163686772120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70163686771620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70163686771620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activemodel
|
38
|
-
requirement: &
|
38
|
+
requirement: &70163686771160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 3.2.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70163686771160
|
47
47
|
description: XML-Object Mapper with many built-in XML formats supported
|
48
48
|
email:
|
49
49
|
- al@semyonov.us
|
@@ -68,11 +68,14 @@ files:
|
|
68
68
|
- lib/xommelier/atom/category.rb
|
69
69
|
- lib/xommelier/atom/entry.rb
|
70
70
|
- lib/xommelier/atom/feed.rb
|
71
|
+
- lib/xommelier/atom/full.rb
|
71
72
|
- lib/xommelier/atom/generator.rb
|
73
|
+
- lib/xommelier/atom/history.rb
|
72
74
|
- lib/xommelier/atom/link.rb
|
75
|
+
- lib/xommelier/atom/links_extension.rb
|
73
76
|
- lib/xommelier/atom/person.rb
|
74
77
|
- lib/xommelier/atom/source.rb
|
75
|
-
- lib/xommelier/atom/
|
78
|
+
- lib/xommelier/atom/threading.rb
|
76
79
|
- lib/xommelier/collection.rb
|
77
80
|
- lib/xommelier/core_ext.rb
|
78
81
|
- lib/xommelier/core_ext/boolean.rb
|