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 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

The following with_orthor_* helper methods are defined in the OrthorHelper module. This is automatically included in ActionView::Base if you're in a Rails app.

Content

with_orthor_content("id") do 
  <h2>{{title}}</h2>
  <span>{{published_on}}</span>
  <div class="content">{{article_content}}</div>
end

OR

Orthor.content("id", :template_name)

Queries

with_orthor_query("id") do 
  <h2>{{title}}</h2>
  <span>{{published_on}}</span>
  <div class="content">{{article_content}}</div>
end

OR

Orthor.query("id", :template_name)

Categories

with_orthor_category("id") do 
  <h2>{{title}}</h2>
  <span>{{published_on}}</span>
  <div class="content">{{article_content}}</div>
end

OR

Orthor.category("id", :template_name)

Feeds

Orthor.feed("id")

The second argument in the Orthor class methods is a symbol to indicate 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

If you don't want to use the with_orthor_* helpers you can use named templates:

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="{{orthor_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 (or template mapping) as a symbol 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
{{orthor_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?

[email protected]

Examples

Orthor demo site

Copyright (c) 2010 Robotic Foo, released under the MIT license