glog 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/glog/template.rb +12 -8
- metadata +2 -2
data/lib/glog/template.rb
CHANGED
@@ -12,8 +12,8 @@ module Glog
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def initialize(page, locals = nil)
|
15
|
-
@page
|
16
|
-
@locals
|
15
|
+
@page = page
|
16
|
+
@locals = locals
|
17
17
|
if page.template
|
18
18
|
@template = File.read(build_template_path(page.template))
|
19
19
|
else
|
@@ -21,15 +21,17 @@ module Glog
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def render(path = nil, locals = {})
|
24
|
+
def render(path = nil, locals = {}, &block)
|
25
25
|
template = path ? File.read("templates" + File::SEPARATOR + path + '.haml') : @template
|
26
|
-
|
26
|
+
inner_html = block_given? ? yield : ''
|
27
|
+
inner_html = inner_html == 0 ? '' : inner_html
|
28
|
+
render_string(template, locals, inner_html)
|
27
29
|
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def render_string(string, locals = {}, inner_html = '')
|
32
|
+
Engine.new(string).render(self, @locals.merge(locals)) do
|
33
|
+
render_string(inner_html)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def find_for(page_path)
|
@@ -37,6 +39,8 @@ module Glog
|
|
37
39
|
File.read template_path || 'templates/default.haml'
|
38
40
|
end
|
39
41
|
|
42
|
+
private
|
43
|
+
|
40
44
|
def possible_paths_for(page_path)
|
41
45
|
return [] if page_path.nil?
|
42
46
|
segments = page_path.split(File::SEPARATOR)
|