xommelier 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
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::Thread} module for implementation of http://www.w3.org/2005/Atom namespace and Atom Threading extension
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: [![Build Status](https://secure.travis-ci.org/alsemyonov/xommelier.png?branch=master)](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::Thread::InReplyTo.new(
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/thread'
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::Thread::InReplyTo.new(ref: entry.id, href: entry.link.href)
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
 
@@ -3,6 +3,8 @@ require 'xommelier/atom'
3
3
  module Xommelier
4
4
  module Atom
5
5
  class Entry < Xml::Element
6
+ include LinksExtension
7
+
6
8
  root
7
9
 
8
10
  element :id, unique: true
@@ -3,6 +3,8 @@ require 'xommelier/atom'
3
3
  module Xommelier
4
4
  module Atom
5
5
  class Feed < Xml::Element
6
+ include LinksExtension
7
+
6
8
  root
7
9
 
8
10
  element :id, unique: true
@@ -0,0 +1,3 @@
1
+ require 'xommelier/atom'
2
+ require 'xommelier/atom/threading'
3
+ require 'xommelier/atom/history'
@@ -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 Thread
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: Thread::InReplyTo, as: Thread::InReplyTo.element_name
27
- element :total, type: Integer, ns: Thread.xmlns
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, type: Integer, ns: Thread.xmlns
34
- attribute :updated, type: Time, ns: Thread.xmlns
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
@@ -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 :Thread, 'xommelier/atom/thread'
23
+ autoload :Threading, 'xommelier/atom/threading'
24
+ autoload :History, 'xommelier/atom/history'
21
25
  end
22
26
  end
@@ -1,3 +1,3 @@
1
1
  module Xommelier
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -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 &lt;em&gt;lot&lt;/em&gt; 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/thread'
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(2).links }
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/thread'
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::Thread::InReplyTo.new(ref: 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a')
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
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Xommelier do
4
- it { Xommelier::VERSION.should == '0.1.2' }
4
+ it { Xommelier::VERSION.should == '0.1.3' }
5
5
  end
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.2
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: &70220266503160 !ruby/object:Gem::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: *70220266503160
24
+ version_requirements: *70163686772120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &70220266502660 !ruby/object:Gem::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: *70220266502660
35
+ version_requirements: *70163686771620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activemodel
38
- requirement: &70220266502200 !ruby/object:Gem::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: *70220266502200
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/thread.rb
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