Top Level Namespace

Defined Under Namespace

Classes: Hash, KodaApp, MongoCollection, MongoConfig, MongoDatabase, MongoDocument, MongoGrid, MongoMedia, UserAccessProvider, UserContext

Instance Method Summary collapse

Instance Method Details

#create_contentObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/helpers/view_helper.rb', line 62

def create_content

  content = @db_wrapper.flat_file
  
  if(content)

    content.each do |collection|

      collection_obj = {}

      collection['docs'].each do |doc|
        k = doc['alias'].gsub(/-/,'_')
        v = doc.to_obj

        collection_obj.instance_variable_set("@#{k}", v)
        collection_obj.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
      end
    
      collection_obj.class.send(:define_method, "all", proc{self.instance_variables.map {|name| instance_variable_get name }})
      collection_obj.class.send(:define_method, "where", proc{|&block| self.instance_variables.map {|name| instance_variable_get name }.select{ |o| block.call o}})
      collection_obj.class.send(:define_method, "single", proc{|&block| self.instance_variables.map {|name| instance_variable_get name }.select{ |o| block.call o}.first})
      collection_obj.class.send(:define_method, "by_ref", proc{|ref| self.instance_variables.map {|name| instance_variable_get name }.select{ |o| ref.include? o.alias}.first})
    
      collection_k = collection['collection']
      collection_v = collection_obj
    
      content.instance_variable_set("@#{collection_k}", collection_v)
      content.class.send(:define_method, collection_k, proc{self.instance_variable_get("@#{collection_k}")})
    
    end  
  
    return content
  
  end
  
  {}

end

#get_from_cache(time_to_live = settings.long_ttl) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/helpers/view_helper.rb', line 110

def get_from_cache(time_to_live=settings.long_ttl)

  key = "full_cache"

  if(!settings.enable_cache)
    return create_content
  end

  if(settings.cache.get(key) == nil)
    settings.cache.set(key, create_content, ttl=time_to_live+rand(100))
  end

  return settings.cache.get(key)

end

#modelObject



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

def model
  @content
end

#refresh_cache(time_to_live = settings.long_ttl) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/helpers/view_helper.rb', line 101

def refresh_cache(time_to_live=settings.long_ttl)
  key = "full_cache"

  if(settings.enable_cache)
    settings.cache.delete key
    settings.cache.set(key, create_content, ttl=time_to_live+rand(100))
  end
end

#render_doc(doc) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/helpers/view_helper.rb', line 33

def render_doc(doc)
  return "<p>No content has yet been added...</p>\n" if(doc == nil)
  result = "<dl id='#{doc.alias}'>\n" 
  doc.delete 'alias'

  doc.each do |k,v|
    if(v.to_s.include? '_koda_media')
      result += "<img src='#{v}' title='#{k}' \>\n"
    else
      result += "<dt>#{k}</dt><dd>#{v}</dd>\n"
    end
  end  
  
  result += "</dl>"
  result
end

#render_partial(template, locals = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/helpers/view_helper.rb', line 23

def render_partial(template, locals={})
  template = template_for "templates/#{template}.#{settings.view_format}"
  options = {:layout => false}.merge(settings.view_options)

  @content = get_from_cache

  content_type :html
  render(settings.view_format, template, settings.view_options, locals)
end

#safe(fallback = '') ⇒ Object



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

def safe(fallback='')
  begin
    return yield
  rescue
    fallback
  end
end

#show(template, locals = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/helpers/view_helper.rb', line 13

def show(template, locals={})
  content_type :html
  options = {:layout => true}.merge(settings.view_options)
  
  @content = get_from_cache
  
  template = template_for "templates/#{template}.#{settings.view_format}"
  render(settings.view_format, template, settings.view_options, locals)
end

#show_system(template, locals = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/helpers/view_helper.rb', line 6

def show_system(template, locals={})
  content_type :html
  options = {:layout => false}.merge(settings.view_options)
  template = system_view "#{template}.#{settings.view_format}"
  render(settings.view_format, template, options, locals)
end