orthor 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,7 +11,7 @@ The Orthor gem is used to fetch and display your content from orthor.com
11
11
  Add the below to a file and require it:
12
12
 
13
13
  Orthor.setup do
14
- site "orthor" # your orthor site/account id
14
+ site "orthor" # your orthor site id
15
15
  caching :basic_file, 300, :path => "tmp/" # cache content in tmp/ for 5 mins
16
16
  end
17
17
 
@@ -19,29 +19,53 @@ You can specify any Moneta cache store you like, e.g. basic_file, memory, memcac
19
19
 
20
20
  ## Usage
21
21
 
22
+ 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.
23
+
22
24
  #### Content
23
25
 
26
+ with_orthor_content("id") do
27
+ <h2>{{title}}</h2>
28
+ <span>{{published_on}}</span>
29
+ <div class="content">{{article_content}}</div>
30
+ end
31
+
32
+ OR
33
+
24
34
  Orthor.content("id", :template_name)
25
35
 
26
36
  #### Queries
27
37
 
38
+ with_orthor_query("id") do
39
+ <h2>{{title}}</h2>
40
+ <span>{{published_on}}</span>
41
+ <div class="content">{{article_content}}</div>
42
+ end
43
+
44
+ OR
45
+
28
46
  Orthor.query("id", :template_name)
29
47
 
30
48
  #### Categories
31
49
 
50
+ with_orthor_category("id") do
51
+ <h2>{{title}}</h2>
52
+ <span>{{published_on}}</span>
53
+ <div class="content">{{article_content}}</div>
54
+ end
55
+
56
+ OR
57
+
32
58
  Orthor.category("id", :template_name)
33
59
 
34
60
  #### Feeds
35
61
 
36
62
  Orthor.feed("id")
37
63
 
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.
64
+ 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.
41
65
 
42
66
  ## Templates
43
67
 
44
- Orthor returns all of your content in JSON so to make the job of translating JSON -> HTML easier, we provide some templating help:
68
+ If you don't want to use the with_orthor_* helpers you can use named templates:
45
69
 
46
70
  Orthor::Templates.define do
47
71
  template :basic_content, %(<div>{{content}}</div>)
@@ -71,7 +95,7 @@ Orthor returns all of your content in JSON so to make the job of translating JSO
71
95
  }
72
96
  end
73
97
 
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.
98
+ 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.
75
99
 
76
100
  ### Named template mappings
77
101
 
@@ -6,10 +6,11 @@ require 'json'
6
6
  require 'net/http'
7
7
 
8
8
  require 'orthor/templates'
9
+ require 'orthor_helper'
9
10
 
10
11
  class Orthor
11
12
  class << self
12
- attr_accessor :cache, :cache_expiry, :account_id
13
+ attr_accessor :cache, :cache_expiry, :site_id
13
14
  end
14
15
 
15
16
  def self.load_content
@@ -21,7 +22,7 @@ class Orthor
21
22
  cat["content"].each { |item| content(item["id"]) } if cat["content"]
22
23
  end
23
24
 
24
- JSON.parse(get_response("/#{account_id}.json")).each do |item|
25
+ JSON.parse(get_response("/#{site_id}.json")).each do |item|
25
26
  if item["type"] == "category"
26
27
  load_category[item["id"]]
27
28
  else
@@ -59,12 +60,8 @@ class Orthor
59
60
  self.cache_expiry = expiry
60
61
  end
61
62
 
62
- def self.account(id)
63
- self.account_id = id
64
- end
65
-
66
63
  def self.site(id)
67
- self.account_id = id
64
+ self.site_id = id
68
65
  end
69
66
 
70
67
  def self.setup(&block)
@@ -76,12 +73,12 @@ class Orthor
76
73
 
77
74
  private
78
75
  def self.get(type, id)
79
- raise "No orthor account given... Please add one to your Orthor setup block" unless account_id
76
+ raise "No orthor site given... Please add one to your Orthor setup block" unless site_id
80
77
 
81
78
  begin
82
79
  suffix = type == :feeds ? "rss" : "json"
83
80
  key = "#{id}-#{type}"
84
- path = "/#{account_id}/#{type}/#{id}.#{suffix}"
81
+ path = "/#{site_id}/#{type}/#{id}.#{suffix}"
85
82
 
86
83
  resp = cache ? get_cached_content(key, path) : get_response(path)
87
84
 
@@ -70,7 +70,9 @@ class Orthor
70
70
  end
71
71
 
72
72
  def self.template_for(item, template_name_or_mapping)
73
- if [String, Symbol].include?(template_name_or_mapping.class)
73
+ if template_name_or_mapping.is_a?(String)
74
+ return template_name_or_mapping
75
+ elsif template_name_or_mapping.is_a?(Symbol)
74
76
  markup = self[template_name_or_mapping]
75
77
 
76
78
  if !markup && self.mappings[template_name_or_mapping]
@@ -0,0 +1,26 @@
1
+ module OrthorHelper
2
+ def with_orthor_content(id, &blk)
3
+ return unless block_given?
4
+ render_orthor_result(:content, id, &blk)
5
+ end
6
+
7
+ def with_orthor_category(id, &blk)
8
+ return unless block_given?
9
+ render_orthor_result(:category, id, &blk)
10
+ end
11
+
12
+ def with_orthor_query(id, &blk)
13
+ return unless block_given?
14
+ render_orthor_result(:query, id, &blk)
15
+ end
16
+
17
+ private
18
+ def render_orthor_result(method, id, &blk)
19
+ html = defined?(capture) ? capture(&blk) : yield
20
+ parsed_html = Orthor.send(method, id, html)
21
+ defined?(concat) ? concat(parsed_html) : parsed_html
22
+ end
23
+ end
24
+
25
+ ActionView::Base.send(:include, OrthorHelper) if defined?(ActionView::Base)
26
+
@@ -18,7 +18,7 @@ describe Orthor::Templates do
18
18
  :body => "")
19
19
 
20
20
  Orthor.setup do
21
- account "orthor"
21
+ site "orthor"
22
22
  end
23
23
 
24
24
  Orthor::Templates.define do
@@ -29,11 +29,11 @@ describe Orthor do
29
29
  describe "setup" do
30
30
  before(:all) do
31
31
  Orthor.setup do
32
- account nil
32
+ site nil
33
33
  end
34
34
  end
35
35
 
36
- it "should raise an error if no account id is present" do
36
+ it "should raise an error if no site id is present" do
37
37
  lambda { Orthor.content("content") }.should raise_error
38
38
  end
39
39
  end
@@ -45,15 +45,15 @@ describe Orthor do
45
45
  end
46
46
  end
47
47
 
48
- it "should use the site id as the account id" do
49
- Orthor.account_id.should == "bob"
48
+ it "should set the site id" do
49
+ Orthor.site_id.should == "bob"
50
50
  end
51
51
  end
52
52
 
53
53
  describe "getting" do
54
54
  before(:all) do
55
55
  Orthor.setup do
56
- account "orthor"
56
+ site "orthor"
57
57
  end
58
58
  end
59
59
 
@@ -89,7 +89,7 @@ describe Orthor do
89
89
  describe "loading cache" do
90
90
  describe "without cache setting" do
91
91
  before do
92
- Orthor.setup { account "orthor" }
92
+ Orthor.setup { site "orthor" }
93
93
  end
94
94
 
95
95
  it "should raise an error" do
@@ -100,7 +100,7 @@ describe Orthor do
100
100
  describe "with cache setting" do
101
101
  before do
102
102
  Orthor.setup do
103
- account "orthor"
103
+ site "orthor"
104
104
  caching :memory, 20
105
105
  end
106
106
  end
@@ -117,7 +117,7 @@ describe Orthor do
117
117
  describe "no config" do
118
118
  before(:all) do
119
119
  Orthor.setup do
120
- account "orthor"
120
+ site "orthor"
121
121
  end
122
122
  end
123
123
 
@@ -130,7 +130,7 @@ describe Orthor do
130
130
  describe "memory" do
131
131
  before(:all) do
132
132
  Orthor.setup do
133
- account "orthor"
133
+ site "orthor"
134
134
  caching :memory, 600
135
135
  end
136
136
  end
@@ -156,7 +156,7 @@ describe Orthor do
156
156
  describe "basic file store" do
157
157
  before(:all) do
158
158
  Orthor.setup do
159
- account "orthor"
159
+ site "orthor"
160
160
  caching :basic_file, 300, :path => "tmp/"
161
161
  end
162
162
  end
@@ -169,7 +169,7 @@ describe Orthor do
169
169
  describe "optinal expiry time argument" do
170
170
  before(:all) do
171
171
  Orthor.setup do
172
- account "orthor"
172
+ site "orthor"
173
173
  caching :basic_file, :path => "tmp/"
174
174
  end
175
175
  end
@@ -184,7 +184,7 @@ describe Orthor do
184
184
  describe "failover" do
185
185
  before(:all) do
186
186
  Orthor.setup do
187
- account "orthor"
187
+ site "orthor"
188
188
  end
189
189
  end
190
190
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthor
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 3
9
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
10
11
  platform: ruby
11
12
  authors:
12
13
  - Anthony Langhorne
@@ -18,28 +19,32 @@ date: 2010-06-10 00:00:00 +10:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
22
+ prerelease: false
21
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
22
25
  requirements:
23
26
  - - ">="
24
27
  - !ruby/object:Gem::Version
28
+ hash: 3
25
29
  segments:
26
30
  - 0
27
31
  version: "0"
28
- name: moneta
29
- prerelease: false
30
32
  requirement: *id001
33
+ name: moneta
31
34
  type: :runtime
32
35
  - !ruby/object:Gem::Dependency
36
+ prerelease: false
33
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
34
39
  requirements:
35
40
  - - ">="
36
41
  - !ruby/object:Gem::Version
42
+ hash: 3
37
43
  segments:
38
44
  - 0
39
45
  version: "0"
40
- name: json
41
- prerelease: false
42
46
  requirement: *id002
47
+ name: json
43
48
  type: :runtime
44
49
  description:
45
50
  email: anthony@orthor.com
@@ -52,9 +57,13 @@ extra_rdoc_files:
52
57
  - README.md
53
58
  files:
54
59
  - lib/orthor.rb
60
+ - lib/orthor_helper.rb
55
61
  - lib/orthor/templates.rb
56
62
  - LICENSE
57
63
  - README.md
64
+ - spec/orthor/templates_spec.rb
65
+ - spec/orthor_spec.rb
66
+ - spec/spec_helper.rb
58
67
  has_rdoc: true
59
68
  homepage: http://github.com/anthony/orthor-client
60
69
  licenses: []
@@ -65,23 +74,27 @@ rdoc_options:
65
74
  require_paths:
66
75
  - lib
67
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
68
78
  requirements:
69
79
  - - ">="
70
80
  - !ruby/object:Gem::Version
81
+ hash: 3
71
82
  segments:
72
83
  - 0
73
84
  version: "0"
74
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
75
87
  requirements:
76
88
  - - ">="
77
89
  - !ruby/object:Gem::Version
90
+ hash: 3
78
91
  segments:
79
92
  - 0
80
93
  version: "0"
81
94
  requirements: []
82
95
 
83
96
  rubyforge_project:
84
- rubygems_version: 1.3.6
97
+ rubygems_version: 1.3.7
85
98
  signing_key:
86
99
  specification_version: 3
87
100
  summary: A gem for displaying content from orthor.com