end_view 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -6
- data/lib/end_view.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5151d139cc8f21f972271d48b9c53ff58324ead
|
4
|
+
data.tar.gz: 46885e8deb17f9a1577bf4013d97905da7ee530b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db3b31e8d5b5e66e18847fa25e2b8b6a24227ecb2884db2ed41333574474bae525cba0fb41d51d300786675fa896c07e4c40cbd326b40149d991a520bebaa080
|
7
|
+
data.tar.gz: acce11b43d3e1d3ddfd03992a303fd23c673892e234f395f5a039db8b7026b7c18f87b90aa23d2eea8799af94aa503d5939c5721c5fcd86b494114794d782bd1
|
data/README.md
CHANGED
@@ -75,7 +75,7 @@ EndView.default_engine = Tilt::LiquidTemplate
|
|
75
75
|
|
76
76
|
### Layouts
|
77
77
|
|
78
|
-
For template engines that support it, view models can passed blocks:
|
78
|
+
For template engines that support it, view models can be passed blocks:
|
79
79
|
|
80
80
|
``` ruby
|
81
81
|
module MyLayout
|
@@ -95,22 +95,47 @@ These can then be used as layouts:
|
|
95
95
|
class Fizz
|
96
96
|
include EndView.new(__FILE__)
|
97
97
|
self.layout = MyLayout
|
98
|
+
end
|
98
99
|
|
99
|
-
|
100
|
-
|
100
|
+
Fizz.new.render # <html>Goodbye</html>
|
101
|
+
|
102
|
+
__END__
|
103
|
+
|
104
|
+
Goodbye
|
105
|
+
```
|
106
|
+
|
107
|
+
For layouts that need to be dynamically initialized, `self.layout` can be passed a lambda:
|
108
|
+
|
109
|
+
``` ruby
|
110
|
+
class MyDynamicLayout
|
111
|
+
include EndView.new(__FILE__)
|
112
|
+
|
113
|
+
def initialize(title)
|
114
|
+
@title = title
|
101
115
|
end
|
102
116
|
end
|
103
117
|
|
104
|
-
|
118
|
+
__END__
|
119
|
+
|
120
|
+
<html><%= @title %><%= yield %></html>
|
121
|
+
```
|
122
|
+
|
123
|
+
``` ruby
|
124
|
+
class Whizz
|
125
|
+
include EndView.new(__FILE__)
|
126
|
+
self.layout = -> { MyDynamicLayout.new('Hallo') }
|
127
|
+
end
|
128
|
+
|
129
|
+
Whizz.new.render # <html>Hallo Bonjour</html>
|
105
130
|
|
106
131
|
__END__
|
107
132
|
|
108
|
-
|
133
|
+
Bonjour
|
109
134
|
```
|
110
135
|
|
111
136
|
### Inheritance
|
112
137
|
|
113
|
-
Templates are inherited:
|
138
|
+
Templates are inherited from parent view models:
|
114
139
|
|
115
140
|
``` ruby
|
116
141
|
class Bar < Foo
|
data/lib/end_view.rb
CHANGED
@@ -34,7 +34,12 @@ class EndView < Module
|
|
34
34
|
@template = template_engine.new { data(file) }
|
35
35
|
end
|
36
36
|
|
37
|
-
attr_accessor :
|
37
|
+
attr_accessor :template
|
38
|
+
attr_writer :layout
|
39
|
+
|
40
|
+
def layout
|
41
|
+
@layout.respond_to?(:call) ? @layout.call : @layout
|
42
|
+
end
|
38
43
|
|
39
44
|
private
|
40
45
|
|