orthor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,8 +4,6 @@ The Orthor gem is used to fetch and display your content from orthor.com
4
4
 
5
5
  ## Installation
6
6
 
7
- Is easy
8
-
9
7
  gem install orthor
10
8
 
11
9
  ## Configuration
@@ -14,41 +12,36 @@ Add the below to a file and require it:
14
12
 
15
13
  Orthor.setup do
16
14
  account "orthor" # your orthor account id
17
- caching :memory, 600 # cache content in memory for 10 minutes
15
+ caching :basic_file, 300, :path => "tmp/" # cache content in tmp/ for 5 mins
18
16
  end
19
17
 
20
- You can specify any Moneta cache store class name, e.g. basic_file, memcache etc. The (optional) second argument is cache expiry in seconds, you can provide any initialize options you want as the 3rd arg, e.g.:
21
-
22
- Orthor.setup do
23
- account "bob"
24
- caching :basic_file, 300, :path => "tmp/"
25
- end
18
+ You can specify any Moneta cache store you like, e.g. basic_file, 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.
26
19
 
27
20
  ## Usage
28
21
 
29
- 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.
30
-
31
- If you do not provide a template_name to render your content with, you will get the parsed JSON back.
32
-
33
- ### Content
22
+ #### Content
34
23
 
35
24
  Orthor.content("id", :template_name)
36
25
 
37
- ### Queries
26
+ #### Queries
38
27
 
39
28
  Orthor.query("id", :template_name)
40
29
 
41
- ### Categories
30
+ #### Categories
42
31
 
43
32
  Orthor.category("id", :template_name)
44
33
 
45
- ### Feeds
34
+ #### Feeds
46
35
 
47
36
  Orthor.feed("id")
48
37
 
38
+ 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.
39
+
40
+ If you do not provide a template_name to render your content with, you will get the parsed JSON back.
41
+
49
42
  ## Templates
50
43
 
51
- Orthor returns all of your content in JSON so to make the job of translating JSON -> HTML, we provide some templating help:
44
+ Orthor returns all of your content in JSON so to make the job of translating JSON -> HTML easier, we provide some templating help:
52
45
 
53
46
  Orthor::Templates.define do
54
47
  template :basic_content, %(<div>{{Content}}</div>)
@@ -71,10 +64,28 @@ Orthor returns all of your content in JSON so to make the job of translating JSO
71
64
  <p class="last-updated">Last updated: {{Updated on}}</p>
72
65
  <div class="content">{{Wysiwyg}}</div>
73
66
  </div>)
67
+
68
+ mapping :detail_templates, {
69
+ "Blog Post" => :blog_entry,
70
+ "User Manual" => :user_manual
71
+ }
74
72
  end
75
73
 
76
74
  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.
77
75
 
76
+ ### Named template mappings
77
+
78
+ 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.
79
+
80
+ As an example if this was your template mapping:
81
+
82
+ mapping :blog_types, {
83
+ "Bookmark" => :bookmark_detail,
84
+ "Quote" => :quote_detail
85
+ }
86
+
87
+ A call to Orthor.category("blog", :blog_types) means that any content item using the "Bookmark" template will render using the bookmark_detail template.
88
+
78
89
  ### Default template tags
79
90
 
80
91
  These tags are available to all content:
@@ -105,5 +116,5 @@ anthony@orthor.com
105
116
 
106
117
  [Orthor demo site](http://github.com/anthony/orthor-demo)
107
118
 
108
- Copyright (c) 2009 Robotic Foo, released under the MIT license
119
+ Copyright (c) 2010 Robotic Foo, released under the MIT license
109
120
 
@@ -1,3 +1,6 @@
1
+ # setup utf-8 support
2
+ $KCODE = 'u' if RUBY_VERSION < '1.9'
3
+
1
4
  require 'moneta'
2
5
  require 'json'
3
6
 
@@ -8,10 +8,12 @@ describe Orthor::Templates do
8
8
  :body => File.join(SPEC_DIR, 'resources', 'query.json'))
9
9
  FakeWeb.register_uri(:get, "http://content.orthor.com/orthor/categories/category.json",
10
10
  :body => File.join(SPEC_DIR, 'resources', 'category.json'))
11
- FakeWeb.register_uri(:get, "http://content.orthor.com/orthor/categories/varied.json",
11
+ FakeWeb.register_uri(:get, "http://content.orthor.com/orthor/queries/varied.json",
12
12
  :body => File.join(SPEC_DIR, 'resources', 'varied_content.json'))
13
13
  FakeWeb.register_uri(:get, "http://content.orthor.com/orthor/feeds/feed.rss",
14
14
  :body => File.join(SPEC_DIR, 'resources', 'feed.rss'))
15
+ FakeWeb.register_uri(:get, "http://content.orthor.com/orthor/content_items/utf8.json",
16
+ :body => File.join(SPEC_DIR, 'resources', 'utf8.json'))
15
17
  FakeWeb.register_uri(:get, "http://content.orthor.com/orthor/content_items/missing.json",
16
18
  :body => "")
17
19
 
@@ -20,15 +22,21 @@ describe Orthor::Templates do
20
22
  end
21
23
 
22
24
  Orthor::Templates.define do
23
- template :basic, %!<h2>{{Title}}</h2><div class="content">{{Content}}</div>!
24
- template :brief, %!<h2>{{Title}}</h2>!
25
- template :blurb, %!<div>{{Content.blurb}}</div>!
26
- template :user, %!<div>{{Creator.Email}}</div><div>{{Creator.First name}} {{Creator.Last name}}</div>!
25
+ template :basic, %!<h2>{{title}}</h2><div class="content">{{content}}</div>!
26
+ template :brief, %!<h2>{{title}}</h2>!
27
+ template :blurb, %!<div>{{content.blurb}}</div>!
28
+ template :user, %!<div>{{author.email}}</div><div>{{author.first_name}} {{author.last_name}}</div>!
27
29
 
28
30
  mapping :listing, { "Text Block" => :brief }
29
31
  end
30
32
  end
31
33
 
34
+ describe "utf8" do
35
+ it "should be able to parse utf8" do
36
+ Orthor.content("utf8", :brief).should == "<h2>Q&A with Tobias Lütke of Shopify - (37signals)</h2>"
37
+ end
38
+ end
39
+
32
40
  describe "with no content returned" do
33
41
  it "should return an empty string" do
34
42
  Orthor.content("missing").should be_empty
@@ -41,7 +49,7 @@ describe Orthor::Templates do
41
49
  end
42
50
 
43
51
  it "should return templates by name" do
44
- Orthor::Templates[:basic].should == %!<h2>{{Title}}</h2><div class="content">{{Content}}</div>!
52
+ Orthor::Templates[:basic].should == %!<h2>{{title}}</h2><div class="content">{{content}}</div>!
45
53
  end
46
54
  end
47
55
 
@@ -101,11 +109,11 @@ describe Orthor::Templates do
101
109
 
102
110
  describe "template mapping" do
103
111
  before(:all) do
104
- @json = Orthor.category("varied")
112
+ @json = Orthor.query("varied")
105
113
  end
106
114
 
107
115
  it "should allow you to pass a hash of orthor template names" do
108
- Orthor.render(@json["content"], { "Brief News Item" => :basic, "Link" => :brief, "Bookmark" => :blurb }).should == "<h2>User Manual updated</h2><div class=\"content\">The User Manual has recently had a big overhaul with increased documentation for lots of Orthor's great features, including Content Queries, RSS Feeds, Custom CSS and more!</div><div>All accounts now have access to event tracking, use this to gain a snapshot of what everyone in your account has been doing, for example, what were the...</div><h2>Tutorials have been updated</h2><div class=\"content\">We've recently made the tutorials section of the site public, stay tuned for some more language examples + increased detail of the existing languages. </div><h2>Content Queries have landed in Orthor</h2>"
116
+ Orthor.render(@json, { "Brief News Item" => :basic, "Link" => :brief, "Bookmark" => :blurb }).should == "<div>The User Manual has recently had a big overhaul with increased documentation for lots of Orthor's great features, including Content Queries, RSS Feeds,...</div><h2>Account event tracking</h2><h2>Tutorials have been updated</h2><div class=\"content\">We've recently made the tutorials section of the site public, stay tuned for some more language examples + increased detail of the existing languages. </div><h2>Tutorials have been updated</h2><div class=\"content\">We've recently made the tutorials section of the site public, stay tuned for some more language examples + increased detail of the existing languages. </div>"
109
117
  end
110
118
 
111
119
  describe "with a named map" do
@@ -117,7 +125,7 @@ describe Orthor::Templates do
117
125
  describe "when a mapping is missing" do
118
126
  it "should raise an Unknown template exception" do
119
127
  lambda do
120
- Orthor.render(@json["content"], { "Brief News Item" => :basic, "Link" => :brief })
128
+ Orthor.render(@json, { "Brief News Item" => :basic, "Link" => :brief })
121
129
  end.should raise_error(Orthor::Templates::Unknown)
122
130
  end
123
131
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Anthony Langhorne