kontrol 0.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/kontrol/application.rb +4 -4
- data/lib/kontrol/template.rb +37 -20
- metadata +2 -2
data/lib/kontrol/application.rb
CHANGED
@@ -20,13 +20,13 @@ module Kontrol
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def load_template(file)
|
23
|
-
|
23
|
+
@templates[file] ||= Template.new(self, "#{self.path}/templates/#{file}")
|
24
24
|
end
|
25
25
|
|
26
26
|
# Render template with given variables.
|
27
|
-
def render_template(file,
|
28
|
-
template = load_template(file) or raise "not found: #{path}"
|
29
|
-
|
27
|
+
def render_template(file, variables)
|
28
|
+
template = load_template(file) or raise "template not found: #{path}"
|
29
|
+
template.render(variables)
|
30
30
|
end
|
31
31
|
|
32
32
|
# Render named template and insert into layout with given variables.
|
data/lib/kontrol/template.rb
CHANGED
@@ -1,27 +1,51 @@
|
|
1
1
|
module Kontrol
|
2
2
|
|
3
|
+
class View
|
4
|
+
|
5
|
+
def initialize(variables)
|
6
|
+
variables.each do |k, v|
|
7
|
+
instance_variable_set "@#{k}", v
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def __binding__
|
12
|
+
binding
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(id, *args, &block)
|
16
|
+
if @__app__.respond_to?(id)
|
17
|
+
@__app__.send(id, *args, &block)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
3
24
|
# This class renders an ERB template for a set of attributes, which
|
4
25
|
# are accessible as instance variables.
|
5
26
|
class Template
|
6
27
|
include Helpers
|
7
28
|
|
8
|
-
|
9
|
-
|
10
|
-
@
|
29
|
+
def initialize(app, file)
|
30
|
+
@app = app
|
31
|
+
@file = file
|
11
32
|
|
12
|
-
|
13
|
-
instance_variable_set "@#{k}", v
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def __binding__
|
18
|
-
binding
|
33
|
+
load
|
19
34
|
end
|
20
35
|
|
21
|
-
def
|
22
|
-
|
36
|
+
def load
|
37
|
+
@mtime = File.mtime(file)
|
38
|
+
@erb = ERB.new(File.read(file))
|
39
|
+
end
|
40
|
+
|
41
|
+
def changed?
|
42
|
+
File.mtime(@file) != @mtime
|
43
|
+
end
|
44
|
+
|
45
|
+
def render(variables)
|
46
|
+
load if ENV['RACK_ENV'] != 'production' and changed?
|
23
47
|
|
24
|
-
|
48
|
+
@erb.result(View.new(@app, variables).__binding__)
|
25
49
|
|
26
50
|
rescue => e
|
27
51
|
e.backtrace.each do |s|
|
@@ -30,13 +54,6 @@ module Kontrol
|
|
30
54
|
raise e
|
31
55
|
end
|
32
56
|
|
33
|
-
def method_missing(id, *args, &block)
|
34
|
-
if @__app__.respond_to?(id)
|
35
|
-
return @__app__.send(id, *args, &block)
|
36
|
-
end
|
37
|
-
super
|
38
|
-
end
|
39
|
-
|
40
57
|
end
|
41
58
|
|
42
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Georgi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-08 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|