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_content ⇒ Object
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
100
101
102
103
104
105
106
|
# File 'lib/helpers/view_helper.rb', line 69
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/helpers/view_helper.rb', line 117
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
|
#model ⇒ Object
57
58
59
|
# File 'lib/helpers/view_helper.rb', line 57
def model
@content
end
|
#refresh_cache(time_to_live = settings.long_ttl) ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/helpers/view_helper.rb', line 108
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/helpers/view_helper.rb', line 40
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
30
31
32
33
34
35
36
37
38
|
# File 'lib/helpers/view_helper.rb', line 30
def render_partial(template, locals={})
template = template_for "views/#{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
61
62
63
64
65
66
67
|
# File 'lib/helpers/view_helper.rb', line 61
def safe(fallback='')
begin
return yield
rescue
fallback
end
end
|
#show(template, locals = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/helpers/view_helper.rb', line 20
def show(template, locals={})
content_type :html
options = {:layout => true}.merge(settings.view_options)
@content = get_from_cache
template = template_for "views/#{template}.#{settings.view_format}"
render(settings.view_format, template, settings.view_options, locals)
end
|
#show_koda(template, locals = {}) ⇒ Object
6
7
8
9
10
11
|
# File 'lib/helpers/view_helper.rb', line 6
def show_koda(template, locals={})
content_type :html
options = {:layout => false}.merge(settings.view_options)
template = template_for "koda/views/#{template}.#{settings.view_format}"
render(settings.view_format, template, options, locals)
end
|
#show_system(template, locals = {}) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/helpers/view_helper.rb', line 13
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
|