-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c2ba1c
commit 6aab837
Showing
11 changed files
with
181 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
--title=Xommelier | ||
--markup=markdown | ||
--files=example/building_an_atom_feed.rb | ||
--files=example/building_an_atom_feed_using_hash.rb | ||
--files=example/reading_an_atom_feed.rb | ||
--readme=README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,170 +17,13 @@ Look into {Xommelier::Atom}, {Xommelier::Atom::Threading}, and {Xommelier::Atom: | |
* [](http://travis-ci.org/alsemyonov/xommelier) | ||
* [](https://gemnasium.com/alsemyonov/xommelier) | ||
|
||
## Examples with Atom | ||
|
||
```ruby | ||
require 'xommelier/atom/full' | ||
``` | ||
|
||
### Reading a feed | ||
|
||
```ruby | ||
feed = Xommelier::Atom::Feed.parse(open('spec/fixtures/feed.atom.xml')) | ||
puts feed.id, feed.title, feed.updated | ||
|
||
feed.entries do |entry| | ||
puts entry.id, entry.title, entry.published, entry.updated | ||
puts entry.content || entry.summary | ||
end | ||
``` | ||
|
||
### Building a feed | ||
|
||
```ruby | ||
feed = Xommelier::Atom::Feed.new | ||
feed.id = 'http://example.com/blog' | ||
feed.title = 'Example.com blog' | ||
feed.complete = Xommelier::Atom::History::Complete.new | ||
|
||
entry = feed.entry = Xommelier::Atom::Entry.new( | ||
id: 'http://example.com/blog/2012/03/05', | ||
title: "Happy Xommelier's day!", | ||
updated: 5.days.ago | ||
).tap do |entry| | ||
entry.link = Xommelier::Atom::Link.new( | ||
href: entry.id, | ||
rel: 'alternate', | ||
type: 'text/html' | ||
) | ||
entry.links << Xommelier::Atom::Link.new( | ||
href: "#{entry.id}/comments.atom", | ||
rel: 'replies', | ||
type: 'application/atom+xml', | ||
count: 5 | ||
) | ||
end | ||
|
||
# Add Comments | ||
3.times do |i| | ||
feed.entries << Xommelier::Atom::Entry.new( | ||
id: "http://example.com/blog/2012/03/05#comment_#{i}", | ||
title: ('Hooray! ' * (i + 1)).strip, | ||
updated: (5 - i).days.ago | ||
).tap do |comment| | ||
comment.in_reply_to = Xommelier::Atom::Threading::InReplyTo.new( | ||
ref: entry.id, | ||
href: entry.link.href | ||
) | ||
end | ||
end | ||
|
||
puts feed.to_xml | ||
``` | ||
|
||
will output: | ||
|
||
```xml | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<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"> | ||
<id>http://example.com/blog</id> | ||
<title>Example.com blog</title> | ||
<fh:complete/> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05</id> | ||
<title>Happy Xommelier's day!</title> | ||
<updated>2012-02-29T07:52:51+04:00</updated> | ||
<link href="http://example.com/blog/2012/03/05" rel="alternate" type="text/html"/> | ||
<link href="http://example.com/blog/2012/03/05/comments.atom" rel="replies" type="application/atom+xml" thr:count="5"/> | ||
</entry> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05#comment_0</id> | ||
<title>Hooray!</title> | ||
<updated>2012-02-29T07:52:51+04:00</updated> | ||
<thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/> | ||
</entry> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05#comment_1</id> | ||
<title>Hooray! Hooray!</title> | ||
<updated>2012-03-01T07:52:51+04:00</updated> | ||
<thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/> | ||
</entry> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05#comment_2</id> | ||
<title>Hooray! Hooray! Hooray!</title> | ||
<updated>2012-03-02T07:52:51+04:00</updated> | ||
<thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/> | ||
</entry> | ||
</feed> | ||
``` | ||
|
||
### Building from hash | ||
|
||
```ruby | ||
feed = Xommelier::Atom::Feed.new( | ||
{ | ||
title: 'Xommelier nest elements', | ||
subtitle: 'Xommelier is able to build complex objects from very nested hash', | ||
author: { name: 'Alex', email: '[email protected]' }, | ||
updated: Time.utc(2012, 04, 04, 04, 04), | ||
contributors: [ | ||
{ name: 'Ivan', email: '[email protected]' }, | ||
{ name: 'Pyotr', email: '[email protected]' }, | ||
{ name: 'Sidor', email: '[email protected]' }, | ||
], | ||
entries: [ | ||
{ title: 'First article', updated: Time.utc(2012, 01, 01, 01, 01) }, | ||
{ title: 'Second article', updated: Time.utc(2012, 02, 02, 02, 02) }, | ||
{ title: 'Third article', updated: Time.utc(2012, 03, 03, 03, 03) }, | ||
] | ||
} | ||
) | ||
|
||
Xommelier::Atom::Person === feed.author #=> true | ||
Xommelier::Atom::Person === feed.contributors[1] #=> true | ||
Xommelier::Atom::Entry === feed.entries[2] #=> true | ||
|
||
puts feed.to_xml | ||
``` | ||
|
||
will output | ||
|
||
```xml | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<feed xmlns="http://www.w3.org/2005/Atom"> | ||
<title>Xommelier nest elements</title> | ||
<subtitle>Xommelier is able to build complex objects from very nested hash</subtitle> | ||
<author> | ||
<name>Alex</name> | ||
<email>[email protected]</email> | ||
</author> | ||
<updated>2012-04-04T04:04:00Z</updated> | ||
<contributor> | ||
<name>Ivan</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<contributor> | ||
<name>Pyotr</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<contributor> | ||
<name>Sidor</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<entry> | ||
<title>First article</title> | ||
<updated>2012-01-01T01:01:00Z</updated> | ||
</entry> | ||
<entry> | ||
<title>Second article</title> | ||
<updated>2012-02-02T02:02:00Z</updated> | ||
</entry> | ||
<entry> | ||
<title>Third article</title> | ||
<updated>2012-03-03T03:03:00Z</updated> | ||
</entry> | ||
</feed> | ||
``` | ||
## Examples | ||
|
||
See `examples` dir for examples of: | ||
|
||
* reading an Atom feed; | ||
* building an Atom feed; | ||
* building an Atom feed from hash; | ||
|
||
## Built in XML namespaces: | ||
|
||
|
@@ -191,6 +34,7 @@ will output | |
|
||
## TODO | ||
|
||
* Rebuild on top of ROM | ||
* Validating built XML against RelaxNG | ||
* Converting XML Schema, RelaxNG, RelaxNG Compact and DTD into Xommelier Ruby DSL | ||
* ActiveRecord-like automatic loading of XML Schema, RelaxNG, RelaxNG Compact and DTD without needing to write it down into ruby code | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:fh="http://purl.org/syndication/history/1.0" xmlns:thr="http://purl.org/syndication/thread/1.0"> | ||
<id>http://example.com/blog</id> | ||
<title>Example.com blog</title> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05</id> | ||
<title>Happy Xommelier's day!</title> | ||
<updated>2017-04-02T00:34:38+03:00</updated> | ||
<link href="http://example.com/blog/2012/03/05" rel="alternate" type="text/html"/> | ||
<link href="http://example.com/blog/2012/03/05/comments.atom" rel="replies" type="application/atom+xml" thr:count="5"/> | ||
</entry> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05#comment_0</id> | ||
<title>Hooray!</title> | ||
<updated>2017-04-02T00:34:38+03:00</updated> | ||
<thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/> | ||
</entry> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05#comment_1</id> | ||
<title>Hooray! Hooray!</title> | ||
<updated>2017-04-03T00:34:38+03:00</updated> | ||
<thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/> | ||
</entry> | ||
<entry> | ||
<id>http://example.com/blog/2012/03/05#comment_2</id> | ||
<title>Hooray! Hooray! Hooray!</title> | ||
<updated>2017-04-04T00:34:38+03:00</updated> | ||
<thr:in-reply-to ref="http://example.com/blog/2012/03/05" href="http://example.com/blog/2012/03/05"/> | ||
</entry> | ||
<fh:complete/> | ||
</feed> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
# @title Building an Atom feed | ||
|
||
require 'xommelier/atom/full' | ||
require 'active_support/core_ext/numeric/time' | ||
|
||
feed = Xommelier::Atom::Feed.new | ||
feed.id = 'http://example.com/blog' | ||
feed.title = 'Example.com blog' | ||
feed.complete = Xommelier::Atom::History::Complete.new | ||
|
||
feed.entry = | ||
entry = Xommelier::Atom::Entry.new( | ||
id: 'http://example.com/blog/2012/03/05', | ||
title: "Happy Xommelier's day!", | ||
updated: 5.days.ago | ||
) | ||
|
||
# Adding the only one link | ||
entry.link = Xommelier::Atom::Link.new( | ||
href: entry.id, | ||
rel: 'alternate', | ||
type: 'text/html' | ||
) | ||
|
||
# Add more links later | ||
entry.links << Xommelier::Atom::Link.new( | ||
href: "#{entry.id}/comments.atom", | ||
rel: 'replies', | ||
type: 'application/atom+xml', | ||
count: 5 | ||
) | ||
|
||
# Add Comments | ||
3.times do |i| | ||
feed.entries << Xommelier::Atom::Entry.new( | ||
id: "http://example.com/blog/2012/03/05#comment_#{i}", | ||
title: ('Hooray! ' * (i + 1)).strip, | ||
updated: (5 - i).days.ago | ||
).tap do |comment| | ||
comment.in_reply_to = Xommelier::Atom::Threading::InReplyTo.new( | ||
ref: entry.id, | ||
href: entry.link.href | ||
) | ||
end | ||
end | ||
|
||
puts feed.to_xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<feed xmlns="http://www.w3.org/2005/Atom"> | ||
<title>Xommelier nest elements</title> | ||
<updated>2012-04-04T04:04:00Z</updated> | ||
<subtitle>Xommelier is able to build complex objects from very nested hash</subtitle> | ||
<author> | ||
<name>Alex</name> | ||
<email>[email protected]</email> | ||
</author> | ||
<contributor> | ||
<name>Ivan</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<contributor> | ||
<name>Pyotr</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<contributor> | ||
<name>Sidor</name> | ||
<email>[email protected]</email> | ||
</contributor> | ||
<entry> | ||
<title>First article</title> | ||
<updated>2012-01-01T01:01:00Z</updated> | ||
</entry> | ||
<entry> | ||
<title>Second article</title> | ||
<updated>2012-02-02T02:02:00Z</updated> | ||
</entry> | ||
<entry> | ||
<title>Third article</title> | ||
<updated>2012-03-03T03:03:00Z</updated> | ||
</entry> | ||
</feed> |
Oops, something went wrong.