city-watch 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/city_watch/util/renderer.rb +13 -15
- data/lib/version.rb +1 -1
- data/views/server/summary.html.erb +1 -1
- metadata +1 -1
@@ -1,7 +1,14 @@
|
|
1
|
+
require 'erubis'
|
2
|
+
|
3
|
+
TemplateCache = {}
|
4
|
+
ViewPath = File.expand_path(File.dirname(__FILE__) + "/../../../views")
|
5
|
+
Layout = Proc.new {
|
6
|
+
file_path = "#{ViewPath}/layouts/default.html.erb"
|
7
|
+
Erubis::FastEruby.new(File.read(file_path), bufvar: '@output_buffer', filename: file_path)
|
8
|
+
}.call
|
9
|
+
|
1
10
|
module Renderer
|
2
11
|
|
3
|
-
require 'erubis'
|
4
|
-
|
5
12
|
def render(*tpl)
|
6
13
|
layout do
|
7
14
|
render_bare(*tpl)
|
@@ -15,11 +22,7 @@ module Renderer
|
|
15
22
|
private
|
16
23
|
|
17
24
|
def layout(&block)
|
18
|
-
|
19
|
-
file_path = "#{view_path}/layouts/default.html.erb"
|
20
|
-
Erubis::FastEruby.new(File.read(file_path), bufvar: '@output_buffer', filename: file_path)
|
21
|
-
}.call
|
22
|
-
@layout.result(binding)
|
25
|
+
Layout.result(binding)
|
23
26
|
end
|
24
27
|
|
25
28
|
def template_content(file_path)
|
@@ -27,24 +30,19 @@ module Renderer
|
|
27
30
|
File.read(file_path)
|
28
31
|
end
|
29
32
|
|
30
|
-
def template_key(*keys)
|
31
|
-
keys.inject("") {|a,k| a += k.to_s}
|
32
|
-
end
|
33
|
-
|
34
33
|
def template_path(*tpl)
|
35
34
|
tpl.map {|t| "#{view_path}/#{t}.html.erb" }.detect{|p| File.exists?(p) }
|
36
35
|
end
|
37
36
|
|
38
37
|
def template(*tpl)
|
39
|
-
return
|
38
|
+
return TemplateCache[tpl.join] if TemplateCache[tpl.join]
|
40
39
|
file_path = template_path(*tpl)
|
41
40
|
return template_content(file_path) if CityWatch.debug?
|
42
|
-
|
43
|
-
@templates[tpl.join] ||= template_content(file_path)
|
41
|
+
TemplateCache[tpl.join] ||= template_content(file_path)
|
44
42
|
end
|
45
43
|
|
46
44
|
def view_path
|
47
|
-
|
45
|
+
ViewPath
|
48
46
|
end
|
49
47
|
|
50
48
|
end
|
data/lib/version.rb
CHANGED
@@ -3,7 +3,7 @@ sum = summary
|
|
3
3
|
update_time = sum.delete("received_at")
|
4
4
|
%>
|
5
5
|
<div class="server">
|
6
|
-
<a href="/<%=@host%>"><%=@host%></a>
|
6
|
+
<a href="/<%=@host%>"><%=@host%></a> (Last update: <%=update_time%>)
|
7
7
|
<% sum.each do |watchman,dat| %>
|
8
8
|
<%= Reader::Watchman.new(@host,watchman).render_from_summary(dat) %>
|
9
9
|
<% end %>
|