Class: Orthor

Inherits:
Object
  • Object
show all
Defined in:
lib/orthor.rb,
lib/orthor/templates.rb

Defined Under Namespace

Classes: Templates

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cacheObject

Returns the value of attribute cache.



13
14
15
# File 'lib/orthor.rb', line 13

def cache
  @cache
end

.cache_expiryObject

Returns the value of attribute cache_expiry.



13
14
15
# File 'lib/orthor.rb', line 13

def cache_expiry
  @cache_expiry
end

.site_idObject

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



54
55
56
57
58
59
60
61
# File 'lib/orthor.rb', line 54

def self.caching(file, expiry = nil, options = {})
  expiry, options = 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(options)
  self.cache_expiry = expiry
end

.category(id, template = nil) ⇒ Object



42
43
44
# File 'lib/orthor.rb', line 42

def self.category(id, template = nil)
  Templates.render(get(:categories, id), template)
end

.content(id, template = nil) ⇒ Object



34
35
36
# File 'lib/orthor.rb', line 34

def self.content(id, template = nil)
  Templates.render(get(:content_items, id), template)
end

.feed(id) ⇒ Object



46
47
48
# File 'lib/orthor.rb', line 46

def self.feed(id)
  get(:feeds, id)
end

.load_contentObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/orthor.rb', line 16

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, template = nil) ⇒ Object



38
39
40
# File 'lib/orthor.rb', line 38

def self.query(id, template = nil)
  Templates.render(get(:queries, id), template)
end

.render(items, template) ⇒ Object



50
51
52
# File 'lib/orthor.rb', line 50

def self.render(items, template)
  Templates.render(items, template)
end

.setup(&block) ⇒ Object

Raises:

  • (ArgumentError)


67
68
69
70
71
72
# File 'lib/orthor.rb', line 67

def self.setup(&block)
  raise ArgumentError unless block_given?
  self.cache = false # default

  class_eval &block
end

.site(id) ⇒ Object



63
64
65
# File 'lib/orthor.rb', line 63

def self.site(id)
  self.site_id = id
end