Class: Orthor
- Inherits:
-
Object
- Object
- Orthor
- Defined in:
- lib/orthor.rb,
lib/orthor/templates.rb
Defined Under Namespace
Classes: Templates
Class Attribute Summary collapse
-
.account_id ⇒ Object
Returns the value of attribute account_id.
-
.cache ⇒ Object
Returns the value of attribute cache.
-
.cache_expiry ⇒ Object
Returns the value of attribute cache_expiry.
Class Method Summary collapse
- .account(id) ⇒ Object
- .caching(file, expiry = nil, options = {}) ⇒ Object
- .category(id, template = nil) ⇒ Object
- .content(id, template = nil) ⇒ Object
- .feed(id) ⇒ Object
- .load_content ⇒ Object
- .query(id, template = nil) ⇒ Object
- .render(items, template) ⇒ Object
- .setup(&block) ⇒ Object
Class Attribute Details
.account_id ⇒ Object
Returns the value of attribute account_id.
12 13 14 |
# File 'lib/orthor.rb', line 12 def account_id @account_id end |
.cache ⇒ Object
Returns the value of attribute cache.
12 13 14 |
# File 'lib/orthor.rb', line 12 def cache @cache end |
.cache_expiry ⇒ Object
Returns the value of attribute cache_expiry.
12 13 14 |
# File 'lib/orthor.rb', line 12 def cache_expiry @cache_expiry end |
Class Method Details
.account(id) ⇒ Object
62 63 64 |
# File 'lib/orthor.rb', line 62 def self.account(id) self.account_id = id end |
.caching(file, expiry = nil, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/orthor.rb', line 53 def self.caching(file, expiry = nil, = {}) expiry, = nil, expiry if expiry.is_a?(Hash) klass = file.to_s.split('_').collect { |e| e.capitalize }.join Moneta.autoload(klass.to_sym, "moneta/#{file}") self.cache = Moneta.const_get(klass).new() self.cache_expiry = expiry end |
.category(id, template = nil) ⇒ Object
41 42 43 |
# File 'lib/orthor.rb', line 41 def self.category(id, template = nil) Templates.render(get(:categories, id), template) end |
.content(id, template = nil) ⇒ Object
33 34 35 |
# File 'lib/orthor.rb', line 33 def self.content(id, template = nil) Templates.render(get(:content_items, id), template) end |
.feed(id) ⇒ Object
45 46 47 |
# File 'lib/orthor.rb', line 45 def self.feed(id) get(:feeds, id) end |
.load_content ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/orthor.rb', line 15 def self.load_content raise "No point loading content when you don't have a cache setup" unless cache load_category = lambda do |id| cat = category(id) cat["children"].each { |child| load_category[child["id"]] } if cat["children"] cat["content"].each { |item| content(item["id"]) } if cat["content"] end JSON.parse(get_response("/#{account_id}.json")).each do |item| if item["type"] == "category" load_category[item["id"]] else content(item["id"]) end end end |
.query(id, template = nil) ⇒ Object
37 38 39 |
# File 'lib/orthor.rb', line 37 def self.query(id, template = nil) Templates.render(get(:queries, id), template) end |
.render(items, template) ⇒ Object
49 50 51 |
# File 'lib/orthor.rb', line 49 def self.render(items, template) Templates.render(items, template) end |
.setup(&block) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/orthor.rb', line 66 def self.setup(&block) raise ArgumentError unless block_given? self.cache = false # default class_eval &block end |