Class: Orthor
- Inherits:
-
Object
- Object
- Orthor
- Defined in:
- lib/orthor.rb,
lib/orthor/templates.rb
Defined Under Namespace
Classes: Templates
Class Attribute Summary collapse
-
.cache ⇒ Object
Returns the value of attribute cache.
-
.cache_expiry ⇒ Object
Returns the value of attribute cache_expiry.
-
.site_id ⇒ Object
Returns the value of attribute site_id.
Class Method Summary collapse
- .caching(file, expiry = nil, options = {}) ⇒ Object
- .category(id, options = {}) ⇒ Object
- .content(id, options = {}) ⇒ Object
- .feed(id) ⇒ Object
- .load_content ⇒ Object
- .query(id, options = {}) ⇒ Object
- .render(items, template) ⇒ Object
- .setup(&block) ⇒ Object
- .site(id) ⇒ Object
Class Attribute Details
.cache ⇒ Object
Returns the value of attribute cache.
13 14 15 |
# File 'lib/orthor.rb', line 13 def cache @cache end |
.cache_expiry ⇒ Object
Returns the value of attribute cache_expiry.
13 14 15 |
# File 'lib/orthor.rb', line 13 def cache_expiry @cache_expiry end |
.site_id ⇒ Object
Returns the value of attribute site_id.
13 14 15 |
# File 'lib/orthor.rb', line 13 def site_id @site_id end |
Class Method Details
.caching(file, expiry = nil, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/orthor.rb', line 55 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, options = {}) ⇒ Object
24 25 26 27 |
# File 'lib/orthor.rb', line 24 def self.category(id, = {}) id = [:page] && [:page].to_i > 1 ? "#{id}-#{[:page]}" : id Templates.render(get(:categories, id), [:template]) end |
.content(id, options = {}) ⇒ Object
16 17 18 |
# File 'lib/orthor.rb', line 16 def self.content(id, = {}) Templates.render(get(:content_items, id), [:template]) end |
.feed(id) ⇒ Object
29 30 31 |
# File 'lib/orthor.rb', line 29 def self.feed(id) get(:feeds, id) end |
.load_content ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/orthor.rb', line 33 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("/#{site_id}.json")).each do |item| if item["type"] == "category" load_category[item["id"]] else content(item["id"]) end end end |
.query(id, options = {}) ⇒ Object
20 21 22 |
# File 'lib/orthor.rb', line 20 def self.query(id, = {}) Templates.render(get(:queries, id), [:template]) end |
.render(items, template) ⇒ Object
51 52 53 |
# File 'lib/orthor.rb', line 51 def self.render(items, template) Templates.render(items, template) end |
.setup(&block) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/orthor.rb', line 68 def self.setup(&block) raise ArgumentError, "Block required" unless block_given? self.cache = false # default class_eval &block end |
.site(id) ⇒ Object
64 65 66 |
# File 'lib/orthor.rb', line 64 def self.site(id) self.site_id = id end |