Orthor Client
The Orthor gem is used to fetch and display your content from orthor.com
Installation
gem install orthor
Configuration
Add the below to a file and require it:
Orthor.setup do
site "orthor" # your orthor site/account id
caching :basic_file, 300, :path => "tmp/" # cache content in tmp/ for 5 mins
end
You can specify any Moneta cache store you like, e.g. basic_file, memory, memcache etc. The (optional) second argument is cache expiry in seconds, you can provide any initialize options required by your cache store as the 3rd arg.
Usage
Content
Orthor.content("id", :template_name)
Queries
Orthor.query("id", :template_name)
Categories
Orthor.category("id", :template_name)
Feeds
Orthor.feed("id")
The first argument to all these methods is the orthor-id of your piece of content/category etc. The second argument is the name of a template (see below) to use to render the returned content.
If you do not provide a template_name to render your content with, you will get the parsed JSON back.
Templates
Orthor returns all of your content in JSON so to make the job of translating JSON -> HTML easier, we provide some templating help:
Orthor::Templates.define do
template :basic_content, %(<div>{{content}}</div>)
template :blog_entry, %(
<div class="blog-entry">
<h2>{{title}}</h2>
<div class="blog-content">{{wysiwyg}}</div>
</div>)
template :blog_entry_brief, %(
<div class="blog-entry">
<h2><a href="{{url}}">{{title}}</a></h2>
<p>{{published_on}}</p>
<div class="blog-content">{{wysiwyg.blurb}}</div>
</div>)
template :user_manual, %(
<div class="user-manual-entry">
<h2>{{title}}</h2>
<p class="last-updated">Last updated: {{updated_on}}</p>
<div class="content">{{wysiwyg}}</div>
</div>)
mapping :detail_templates, {
"Blog Post" => :blog_entry,
"User Manual" => :user_manual
}
end
Now any call you make to Orthor.content/category/query can be given a 2nd argument of a template name and rather than receiving parsed JSON, you will be returned a HTML string.
Named template mappings
For the times when you have a category or query that returns multiple types of content (e.g. a tumblr like blog with bookmarks, quotes etc), you can provide a named template mapping.
As an example if this was your template mapping:
mapping :blog_types, {
"Bookmark" => :bookmark_detail,
"Quote" => :quote_detail
}
A call to Orthor.category("blog", :blog_types) means that any content item using the "Bookmark" template will render using the bookmark_detail template.
Default template tags
These tags are available to all content:
{{id}} - the orthor id of your content item
{{title}} - your content title
{{created_on}} - the date your content was created
{{updated_on}} - the date your content was last updated
{{author}} - a hash of the original authors details
{{updater}} - a hash of the updater details
{{published_on}} - the date your content was published
{{url}} - the URL for your content as defined in Orthor, or auto generated as /:template-prefix/category-id/content-id
{{template}} - the name of the template this content was created from
{{category}} - a hash of this items category details
Other attributes that will be present on a per item specific basis are are the names of your template elements, e.g.
{{content}} # Template field name in Orthor: Content
{{featured_news_item}} # Template field name in Orthor: Featured News Item
{{supporting_image}} # Template field name in Orthor: Supporting Image
{{markdown_body}} # Template field name in Orthor: Markdown Body
Questions? Comments?
Examples
Copyright (c) 2010 Robotic Foo, released under the MIT license