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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -6
  3. data/lib/end_view.rb +6 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ca9c4f5f9b15471377b2a14e38769126f23a3b0
4
- data.tar.gz: 7a0b708d6d24fbc83254e43e1d720ad90bab9341
3
+ metadata.gz: a5151d139cc8f21f972271d48b9c53ff58324ead
4
+ data.tar.gz: 46885e8deb17f9a1577bf4013d97905da7ee530b
5
5
  SHA512:
6
- metadata.gz: 74c7f9dc759075b7c66fcb3b955eac6548d4127763a5fb26984fc2d14951d7bcf3ed917a33b99b514dc4067763f8ea75d0483468365a20e45b81dba3f7ac7917
7
- data.tar.gz: 5ecc6e8025ed52148f30a14a4f3bea3475ca36085693f6f798f81b888b928d0f1c34c48d2290427bb6226d9152737ebd99c219c34ae9f6bb7a3924983dbb1e75
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
- def my_method
100
- 'World'
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
- Fizz.new.render # <html>Goodbye World</html>
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
- Goodbye <%= my_method %>
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 :layout, :template
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: end_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max White