diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-02-23 13:08:01 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-02-23 13:08:01 +0100 |
commit | 3b0bc18db928c455186273d9b9aa5b96d91e035e (patch) | |
tree | a372d4506ace34debd9cf500a597bc27ecb74705 /app/helpers | |
parent | 2bc48e9064c56101d1761a10d8c5badba60d2bbe (diff) |
Improved Atom rendering templates, added README
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/atom_helper.rb | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/app/helpers/atom_helper.rb b/app/helpers/atom_helper.rb index a42a49946..7c8f5ed1a 100644 --- a/app/helpers/atom_helper.rb +++ b/app/helpers/atom_helper.rb @@ -1,5 +1,101 @@ module AtomHelper def stream_updated_at - @account.stream_entries.last ? @account.stream_entries.last.created_at.iso8601 : @account.updated_at.iso8601 + @account.stream_entries.last ? @account.stream_entries.last.created_at : @account.updated_at + end + + def entry(xml, is_root, &block) + if is_root + root_tag(xml, :entry, &block) + else + xml.entry &block + end + end + + def feed(xml, &block) + root_tag(xml, :feed, &block) + end + + def unique_id(xml, date, id, type) + xml.id_ unique_tag(date, id, type) + end + + def simple_id(xml, id) + xml.id_ id + end + + def published_at(xml, date) + xml.published date.iso8601 + end + + def updated_at(xml, date) + xml.updated date.iso8601 + end + + def verb(xml, verb) + xml['activity'].send('verb', "http://activitystrea.ms/schema/1.0/#{verb}") + end + + def content(xml, content) + xml.content({ type: 'html' }, content) + end + + def title(xml, title) + xml.title title + end + + def author(xml, &block) + xml.author &block + end + + def target(xml, &block) + xml['activity'].object &block + end + + def object_type(xml, type) + xml['activity'].send('object-type', "http://activitystrea.ms/schema/1.0/#{type}") + end + + def uri(xml, uri) + xml.uri uri + end + + def name(xml, name) + xml.name name + end + + def summary(xml, summary) + xml.summary summary + end + + def subtitle(xml, subtitle) + xml.subtitle subtitle + end + + def link_alternate(xml, url) + xml.link(rel: 'alternate', type: 'text/html', href: url) + end + + def link_self(xml, url) + xml.link(rel: 'self', type: 'application/atom+xml', href: url) + end + + def link_hub(xml, url) + xml.link(rel: 'hub', href: url) + end + + def link_salmon(xml, url) + xml.link(rel: 'salmon', href: url) + end + + def portable_contact(xml, account) + xml['poco'].preferredUsername account.username + xml['poco'].displayName account.display_name + xml['poco'].note account.note + end + + private + + def root_tag(xml, tag, &block) + xml.send(tag, {xmlns: 'http://www.w3.org/2005/Atom', 'xmlns:thr': 'http://purl.org/syndication/thread/1.0', 'xmlns:activity': 'http://activitystrea.ms/spec/1.0/', 'xmlns:poco': 'http://portablecontacts.net/spec/1.0'}, &block) end end |