lotus-view 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +105 -0
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +117 -28
- data/lib/lotus/layout.rb +11 -4
- data/lib/lotus/view/configuration.rb +298 -0
- data/lib/lotus/view/dsl.rb +89 -10
- data/lib/lotus/view/inheritable.rb +4 -0
- data/lib/lotus/view/rendering/layout_finder.rb +31 -7
- data/lib/lotus/view/rendering/layout_scope.rb +2 -2
- data/lib/lotus/view/rendering/registry.rb +0 -1
- data/lib/lotus/view/rendering/scope.rb +2 -2
- data/lib/lotus/view/rendering/template_name.rb +37 -0
- data/lib/lotus/view/rendering/templates_finder.rb +36 -5
- data/lib/lotus/view/version.rb +1 -1
- data/lib/lotus/view.rb +196 -88
- data/lotus-view.gemspec +2 -2
- metadata +9 -67
- data/.gitignore +0 -8
- data/.travis.yml +0 -6
- data/.yardopts +0 -3
- data/Gemfile +0 -15
- data/Rakefile +0 -17
- data/test/fixtures/templates/app/app_view.html.erb +0 -0
- data/test/fixtures/templates/app/view.html.erb +0 -0
- data/test/fixtures/templates/application.html.erb +0 -10
- data/test/fixtures/templates/articles/_form.html.erb +0 -4
- data/test/fixtures/templates/articles/alternative_new.html.erb +0 -1
- data/test/fixtures/templates/articles/index.atom.erb +0 -5
- data/test/fixtures/templates/articles/index.html.erb +0 -3
- data/test/fixtures/templates/articles/index.json.erb +0 -9
- data/test/fixtures/templates/articles/index.rss.erb +0 -0
- data/test/fixtures/templates/articles/new.html.erb +0 -7
- data/test/fixtures/templates/articles/show.html.erb +0 -1
- data/test/fixtures/templates/articles/show.json.erb +0 -5
- data/test/fixtures/templates/contacts/show.html.haml +0 -1
- data/test/fixtures/templates/dashboard/index.html.erb +0 -2
- data/test/fixtures/templates/hello_world_view.html.erb +0 -1
- data/test/fixtures/templates/index_view.html.erb +0 -1
- data/test/fixtures/templates/json_render_view.json.erb +0 -3
- data/test/fixtures/templates/render_view.html.erb +0 -1
- data/test/fixtures/templates/shared/_sidebar.html.erb +0 -1
- data/test/fixtures.rb +0 -187
- data/test/layout_test.rb +0 -10
- data/test/load_test.rb +0 -79
- data/test/presenter_test.rb +0 -31
- data/test/rendering_test.rb +0 -125
- data/test/root_test.rb +0 -38
- data/test/test_helper.rb +0 -24
- data/test/version_test.rb +0 -7
- data/test/view_test.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6054b04ffdb4d4b0bc17f0de1b4d239a45fa1062
|
4
|
+
data.tar.gz: 3fdec77bf94ab52bf27916b979661619cc053b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf1e5d0839acda038d449cb18b9c9b12f49d7de7ec8c6460f7b4c7cef84cf685364e5d3e6ccd0882536024cc47e91f18a05f7aa6afb0cdff08587761d5f2b2f
|
7
|
+
data.tar.gz: 73eecc96f67474d79ca0f21f4440d10aa0a510d3172966fe3939d811c1d2d623170328140097ed81f0b17f53bc3537baff7d8f9d5c8a6955cb95e8c0d0083a9c
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
## v0.2.0
|
2
|
+
### Jun 23, 2014
|
3
|
+
|
4
|
+
f053805 2014-06-20 **Luca Guidi** [breaking] Make Rendering::TemplatesFinder to look recursively for templates, starting from the root
|
5
|
+
|
6
|
+
5a5ed1b 2014-06-18 **Luca Guidi** Depend on lotus-utils ~> 0.2
|
7
|
+
|
8
|
+
d7858df 2014-06-18 **Luca Guidi** Ensure to handle correctly the namespace for views, when it's configured as nil
|
9
|
+
|
10
|
+
8f9e876 2014-06-18 **Luca Guidi** Renamed Lotus::View methods: .duplicate => .dupe, .generate => .duplicate
|
11
|
+
|
12
|
+
199c1d6 2014-06-11 **Luca Guidi** Introducing Lotus::View.generate as shortcut for .duplicate and .configure
|
13
|
+
|
14
|
+
d3e65d9 2014-06-11 **Luca Guidi** Ensure lazy loading and correct namespace of the layout class when using configuration's "layout" DSL
|
15
|
+
|
16
|
+
850c9b9 2014-06-11 **Luca Guidi** Specify different scenario for template name in a standalone application
|
17
|
+
|
18
|
+
6199419 2014-06-06 **Luca Guidi** Ensure to return the correct template name for namespaced views
|
19
|
+
|
20
|
+
71d502f 2014-06-06 **Luca Guidi** Ensure independent configurations between the framework, the views and its children. Lotus::View::Dsl.root now internally uses the configuration.
|
21
|
+
|
22
|
+
dd0ec4c 2014-06-06 **Luca Guidi** Lazily load layout for Configuration. This mechanism solves eventual race conditions between the loading of the framework and the application.
|
23
|
+
|
24
|
+
d2e0775 2014-06-05 **Luca Guidi** [breaking] Lotus::View can be safely duplicated. Moved views and layout registries into Configuration. Configuration is now able to duplicated and (un)load itself. Layouts can be looked up in a given Ruby namespace.
|
25
|
+
|
26
|
+
a619bd2 2014-06-05 **Luca Guidi** Implemented Lotus::View::Configuration#views and #layouts
|
27
|
+
|
28
|
+
e4e892e 2014-06-04 **Luca Guidi** [breaking] Removed Lotus::View's class accessor for root, in favor of the API of Lotus::View::Configuration
|
29
|
+
|
30
|
+
1aa68c6 2014-06-04 **Luca Guidi** [breaking] Removed Lotus::View's class accessor for layout, in favor of the API of Lotus::View::Configuration
|
31
|
+
|
32
|
+
da9bee4 2014-06-04 **Luca Guidi** Implemented Lotus::View::Configuration#layout
|
33
|
+
|
34
|
+
da31e3e 2014-06-04 **Luca Guidi** Implemented Lotus::View::Configuration#load_paths
|
35
|
+
|
36
|
+
1471cdd 2014-06-03 **Luca Guidi** Introduced Lotus::View::Configuration with a bare minimum behavior
|
37
|
+
|
38
|
+
425c79e 2014-05-21 **Grant Ammons** Support arguments for methods inside templates
|
39
|
+
|
40
|
+
d4d407b 2014-05-10 **Luca Guidi** Support Ruby 2.1.2
|
41
|
+
|
42
|
+
593f1a5 2014-04-07 **Luca Guidi** Ensure outermost locals to not shadow innermost inside templates/partials. Closes #3
|
43
|
+
|
44
|
+
## v0.1.0
|
45
|
+
### Mar 23, 2014
|
46
|
+
|
47
|
+
af70191 2014-03-22 **Luca Guidi** Introduced Lotus::View::MissingFormatError in order to force a rendering context to specify the requested format (mime type)
|
48
|
+
|
49
|
+
320f322 2014-03-22 **Luca Guidi** Changed signature of Lotus::View.render: it now accepts only a context for the view
|
50
|
+
|
51
|
+
9d5de63 2014-03-21 **Luca Guidi** Test with other engines than ERb, HAML in this case.
|
52
|
+
|
53
|
+
a5ade35 2014-03-21 **Luca Guidi** Erubis is no longer a dependency.
|
54
|
+
|
55
|
+
257e342 2014-03-21 **Luca Guidi** Performance: prefer `Hash#fetch(key) { default }`, over `#fetch(key, default)`.
|
56
|
+
|
57
|
+
426eaf7 2014-03-21 **Luca Guidi** Allow custom rendering policies. Views can override #render and decide how to return the output.
|
58
|
+
|
59
|
+
b2759f8 2014-03-18 **Luca Guidi** Lotus::View::Layout => Lotus::Layout
|
60
|
+
|
61
|
+
c0c04a8 2014-03-17 **Luca Guidi** Remove private method for Presenter: #object
|
62
|
+
|
63
|
+
74ca485 2014-03-13 **Luca Guidi** Introduced Lotus::Presenter
|
64
|
+
|
65
|
+
0ee9c10 2014-03-13 **Luca Guidi** Render partial from a layout
|
66
|
+
|
67
|
+
dc4a74f 2014-03-12 **Luca Guidi** Support for Tilt 2.0
|
68
|
+
|
69
|
+
728fe70 2014-02-20 **Luca Guidi** Added Lotus::View#locals
|
70
|
+
|
71
|
+
11c7e5a 2013-08-08 **Luca Guidi** Don't use global class vars.
|
72
|
+
|
73
|
+
570a20c 2013-08-07 **Luca Guidi** Scope templates discovery to registered engines
|
74
|
+
|
75
|
+
4b45b11 2013-08-06 **Luca Guidi** Added support for layouts.
|
76
|
+
|
77
|
+
96a2c66 2013-08-02 **Luca Guidi** Allow templates to be rendered from templates.
|
78
|
+
|
79
|
+
ba5acdc 2013-08-01 **Luca Guidi** Allow partials to be rendered from templates.
|
80
|
+
|
81
|
+
04474d4 2013-08-01 **Luca Guidi** Render template in the Lotus::View::Rendering::Scope context
|
82
|
+
|
83
|
+
d108767 2013-08-01 **Luca Guidi** Freeze at subclasses level too
|
84
|
+
|
85
|
+
04a3093 2013-08-01 **Luca Guidi** Let views to specify relative template filename
|
86
|
+
|
87
|
+
e7c832d 2013-08-01 **Luca Guidi** Lotus::View::Rendering::Template => Lotus::View::Template
|
88
|
+
|
89
|
+
f603ea9 2013-08-01 **Luca Guidi** Rework
|
90
|
+
|
91
|
+
5df49f1 2013-07-23 **Luca Guidi** Removed unnecessary indirection
|
92
|
+
|
93
|
+
683741c 2013-07-22 **Luca Guidi** Views can now transparently inheriths variables from locals, in order to reuse them.
|
94
|
+
|
95
|
+
3a31f63 2013-07-19 **Luca Guidi** Removed templates as class variable for views: introduced a registry for runtime resolution
|
96
|
+
|
97
|
+
f27e19f 2013-07-18 **Luca Guidi** WIP rendering resolver
|
98
|
+
|
99
|
+
05e1d8c 2013-07-18 **Luca Guidi** Allow views inheritance.
|
100
|
+
|
101
|
+
8236523 2013-07-18 **Luca Guidi** Refactoring: Engine is not relevant, let Tilt to deal with it. View has multiple templates. Intoduced DSL for format. Introduced resolver for runtime rendering. Dependency injection. :tophat:
|
102
|
+
|
103
|
+
f7f3d25 2013-07-17 **Luca Guidi** Extracted Lotus::View::Template::Finder
|
104
|
+
|
105
|
+
11d3c47 2013-07-15 **Luca Guidi** Initial mess
|
data/{LICENSE.txt → LICENSE.md}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -8,20 +8,20 @@ A _view_ is an object that encapsulates the presentation logic of a page.
|
|
8
8
|
A _template_ is a file that defines the semantic and visual elements of a page.
|
9
9
|
In order to show a result to an user, a template must be _rendered_ by a view.
|
10
10
|
|
11
|
-
Keeping things separated
|
12
|
-
Also, since views are objects they are easily testable.
|
11
|
+
Keeping things separated helps to declutter templates and models from presentation logic.
|
12
|
+
Also, since views are objects, they are easily testable.
|
13
13
|
If you ever used [Mustache](http://mustache.github.io/), you are already aware of the advantages.
|
14
14
|
|
15
|
-
Like all the other Lotus compontents it can be used as a standalone framework
|
15
|
+
Like all the other Lotus compontents, it can be used as a standalone framework or within a full Lotus application.
|
16
16
|
|
17
17
|
## Status
|
18
18
|
|
19
|
-
[![Gem Version](
|
20
|
-
[![Build Status](
|
21
|
-
[![Coverage](
|
22
|
-
[![Code Climate](
|
23
|
-
[![Dependencies](
|
24
|
-
[![Inline docs](http://inch-
|
19
|
+
[![Gem Version](http://img.shields.io/gem/v/lotus-view.svg)](https://badge.fury.io/rb/lotus-view)
|
20
|
+
[![Build Status](http://img.shields.io/travis/lotus/view/master.svg)](https://travis-ci.org/lotus/view?branch=master)
|
21
|
+
[![Coverage](http://img.shields.io/coveralls/lotus/view/master.svg)](https://coveralls.io/r/lotus/view)
|
22
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/lotus/view.svg)](https://codeclimate.com/github/lotus/view)
|
23
|
+
[![Dependencies](http://img.shields.io/gemnasium/lotus/view.svg)](https://gemnasium.com/lotus/view)
|
24
|
+
[![Inline docs](http://inch-ci.org/github/lotus/view.svg?branch=master)](http://inch-ci.org/github/lotus/view)
|
25
25
|
|
26
26
|
## Contact
|
27
27
|
|
@@ -30,6 +30,7 @@ Like all the other Lotus compontents it can be used as a standalone framework, o
|
|
30
30
|
* API Doc: http://rdoc.info/gems/lotus-view
|
31
31
|
* Bugs/Issues: https://github.com/lotus/view/issues
|
32
32
|
* Support: http://stackoverflow.com/questions/tagged/lotus-ruby
|
33
|
+
* Chat: https://gitter.im/lotus/chat
|
33
34
|
|
34
35
|
## Rubies
|
35
36
|
|
@@ -53,10 +54,10 @@ Or install it yourself as:
|
|
53
54
|
|
54
55
|
### Conventions
|
55
56
|
|
56
|
-
* Templates are searched under `Lotus::View.root`, set this value according to your app structure (eg. `"app/templates"`).
|
57
|
+
* Templates are searched under `Lotus::View.configuration.root`, set this value according to your app structure (eg. `"app/templates"`).
|
57
58
|
* A view will look for a template with a file name that is composed by its full class name (eg. `"articles/index"`).
|
58
59
|
* A template must have two concatenated extensions: one for the format one for the engine (eg. `".html.erb"`).
|
59
|
-
* The framework must be loaded before
|
60
|
+
* The framework must be loaded before rendering the first time: `Lotus::View.load!`.
|
60
61
|
|
61
62
|
### Views
|
62
63
|
|
@@ -83,10 +84,13 @@ module Articles
|
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
86
|
-
Lotus::View.
|
87
|
+
Lotus::View.configure do
|
88
|
+
root 'app/templates'
|
89
|
+
end
|
90
|
+
|
87
91
|
Lotus::View.load!
|
88
92
|
|
89
|
-
path = Lotus::View.root.join('articles/index.html.erb')
|
93
|
+
path = Lotus::View.configuration.root.join('articles/index.html.erb')
|
90
94
|
template = Lotus::View::Template.new(path)
|
91
95
|
articles = ArticleRepository.all
|
92
96
|
|
@@ -109,7 +113,10 @@ module Articles
|
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
112
|
-
Lotus::View.
|
116
|
+
Lotus::View.configure do
|
117
|
+
root 'app/templates'
|
118
|
+
end
|
119
|
+
|
113
120
|
Lotus::View.load!
|
114
121
|
|
115
122
|
articles = ArticleRepository.all
|
@@ -151,13 +158,13 @@ end
|
|
151
158
|
</article>
|
152
159
|
```
|
153
160
|
|
154
|
-
All the methods defined in the view are accessible
|
161
|
+
All the methods defined in the view are accessible from the template:
|
155
162
|
|
156
163
|
```erb
|
157
164
|
<h2><%= authors %></h2>
|
158
165
|
```
|
159
166
|
|
160
|
-
For convenience, they are also available as
|
167
|
+
For convenience, they are also available to the view as a Hash, accessed through the `locals` method.
|
161
168
|
|
162
169
|
```ruby
|
163
170
|
require 'lotus/view'
|
@@ -166,11 +173,11 @@ module Articles
|
|
166
173
|
class Show
|
167
174
|
include Lotus::View
|
168
175
|
|
169
|
-
# This view
|
176
|
+
# This view already responds to `#article` because there is an element in
|
170
177
|
# the locals with the same key.
|
171
178
|
#
|
172
179
|
# In order to allow developers to override those methods, and decorate a
|
173
|
-
# single locals object, a view has
|
180
|
+
# single locals object, a view has a Hash with the same values.
|
174
181
|
#
|
175
182
|
# If we had implemented this method like this:
|
176
183
|
#
|
@@ -232,7 +239,7 @@ Articles::Show.render({format: :custom, article: article})
|
|
232
239
|
|
233
240
|
The builtin rendering engine is [ERb](http://en.wikipedia.org/wiki/ERuby).
|
234
241
|
However, Lotus::View supports countless rendering engines out of the box.
|
235
|
-
Require your library of choice **before**
|
242
|
+
Require your library of choice **before** requiring `'lotus/view'`, and it will just work.
|
236
243
|
|
237
244
|
```ruby
|
238
245
|
require 'haml'
|
@@ -369,7 +376,7 @@ For instance, if [ERubis](http://www.kuwata-lab.com/erubis/) is loaded, it will
|
|
369
376
|
|
370
377
|
### Root
|
371
378
|
|
372
|
-
|
379
|
+
Template lookup is performed under the `Lotus::View.configuration.root` directory. You can specify a different path on a per view basis:
|
373
380
|
|
374
381
|
```ruby
|
375
382
|
class ViewWithDifferentRoot
|
@@ -384,8 +391,8 @@ end
|
|
384
391
|
The template file must be located under the relevant `root` and must match the class name:
|
385
392
|
|
386
393
|
```ruby
|
387
|
-
puts Lotus::View.root
|
388
|
-
Articles::Index.template
|
394
|
+
puts Lotus::View.configuration.root # => #<Pathname:app/templates>
|
395
|
+
Articles::Index.template # => "articles/index"
|
389
396
|
```
|
390
397
|
|
391
398
|
Each view can specify a different template:
|
@@ -410,7 +417,7 @@ Partials can be rendered within a template:
|
|
410
417
|
<%= render partial: 'articles/form', locals: { secret: 23 } %>
|
411
418
|
```
|
412
419
|
|
413
|
-
It will look for a template `articles/_form.html.erb` and
|
420
|
+
It will look for a template `articles/_form.html.erb` and make available both the view's and partial's locals (eg. `article` and `secret`).
|
414
421
|
|
415
422
|
### Templates
|
416
423
|
|
@@ -420,11 +427,11 @@ Templates can be rendered within another template:
|
|
420
427
|
<%= render template: 'articles/new', locals: { errors: {} } %>
|
421
428
|
```
|
422
429
|
|
423
|
-
It will render `articles/new.html.erb` and
|
430
|
+
It will render `articles/new.html.erb` and make available both the view's and templates's locals (eg. `article` and `errors`).
|
424
431
|
|
425
432
|
### Layouts
|
426
433
|
|
427
|
-
Layouts are wrappers for views
|
434
|
+
Layouts are wrappers for views. Layouts may serve to reuse common markup.
|
428
435
|
|
429
436
|
```ruby
|
430
437
|
class ApplicationLayout
|
@@ -455,11 +462,11 @@ Articles::Index.render(format: :html) # => Will use ApplicationLayout
|
|
455
462
|
Articles::Index.render(format: :rss) # => Will use nothing
|
456
463
|
```
|
457
464
|
|
458
|
-
As per convention,
|
465
|
+
As per convention, layout templates are located under `Lotus::View.root` or `ApplicationLayout.root` and use the underscored name (eg. `ApplicationLayout => application.html.erb`).
|
459
466
|
|
460
467
|
### Presenters
|
461
468
|
|
462
|
-
|
469
|
+
The goal of a presenter is to wrap and reuse presentational logic for an object.
|
463
470
|
|
464
471
|
```ruby
|
465
472
|
class Map
|
@@ -497,7 +504,7 @@ presenter = MapPresenter.new(map)
|
|
497
504
|
puts presenter.locations # => ['Rome', 'Boston']
|
498
505
|
|
499
506
|
# access presenter concrete methods
|
500
|
-
puts presenter.count # =>
|
507
|
+
puts presenter.count # => 2
|
501
508
|
|
502
509
|
# uses super to access original object implementation
|
503
510
|
puts presenter.location_names # => 'ROME, BOSTON'
|
@@ -506,6 +513,88 @@ puts presenter.location_names # => 'ROME, BOSTON'
|
|
506
513
|
puts presenter.inspect_object # => #<Map:0x007fdeada0b2f0 @locations=["Rome", "Boston"]>
|
507
514
|
```
|
508
515
|
|
516
|
+
### Configuration
|
517
|
+
|
518
|
+
Lotus::View can be configured with a DSL that determines its behavior.
|
519
|
+
It supports a few options:
|
520
|
+
|
521
|
+
```ruby
|
522
|
+
require 'lotus/view'
|
523
|
+
|
524
|
+
Lotus::View.configure do
|
525
|
+
# Set the root path where to search for templates
|
526
|
+
# Argument: String, Pathname, #to_pathname, defaults to the current directory
|
527
|
+
#
|
528
|
+
root '/path/to/root'
|
529
|
+
|
530
|
+
# Set the Ruby namespace where to lookup for views
|
531
|
+
# Argument: Class, Module, String, defaults to Object
|
532
|
+
#
|
533
|
+
namespace 'MyApp::Views'
|
534
|
+
|
535
|
+
# Set the global layout
|
536
|
+
# Argument: Symbol, defautls to nil
|
537
|
+
#
|
538
|
+
layout :application
|
539
|
+
end
|
540
|
+
```
|
541
|
+
|
542
|
+
All those global configurations can be overwritten at a finer grained level:
|
543
|
+
views. Each view and layout has its own copy of the global configuration, so
|
544
|
+
that changes are inherited from the top to the bottom, but not bubbled up in the
|
545
|
+
opposite direction.
|
546
|
+
|
547
|
+
```ruby
|
548
|
+
require 'lotus/view'
|
549
|
+
|
550
|
+
Lotus::View.configure do
|
551
|
+
root '/path/to/root'
|
552
|
+
end
|
553
|
+
|
554
|
+
class Show
|
555
|
+
include Lotus::View
|
556
|
+
root '/another/root'
|
557
|
+
end
|
558
|
+
|
559
|
+
Lotus::View.configuration.root # => #<Pathname:/path/to/root>
|
560
|
+
Show.root # => #<Pathname:/another/root>
|
561
|
+
```
|
562
|
+
|
563
|
+
### Reusability
|
564
|
+
|
565
|
+
Lotus::View can be used as a singleton framework as seen in this README.
|
566
|
+
The application code includes `Lotus::View` or `Lotus::Layout` directly
|
567
|
+
and the configuration is unique per Ruby process.
|
568
|
+
|
569
|
+
While this is convenient for tiny applications, it doesn't fit well for more
|
570
|
+
complex scenarios, where we want micro applications to coexist together.
|
571
|
+
|
572
|
+
```ruby
|
573
|
+
require 'lotus/view'
|
574
|
+
|
575
|
+
Lotus::View.configure do
|
576
|
+
root '/path/to/root'
|
577
|
+
end
|
578
|
+
|
579
|
+
module WebApp
|
580
|
+
View = Lotus::View.duplicate(self)
|
581
|
+
end
|
582
|
+
|
583
|
+
module ApiApp
|
584
|
+
View = Lotus::View.duplicate(self) do
|
585
|
+
root '/another/root'
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
Lotus::View.configuration.root # => #<Pathname:/path/to/root>
|
590
|
+
WebApp::View.configuration.root # => #<Pathname:/path/to/root>, inherited from Lotus::View
|
591
|
+
ApiApp::View.configuration.root # => #<Pathname:/another/root>
|
592
|
+
```
|
593
|
+
|
594
|
+
The code above defines `WebApp::View` and `WebApp::Layout`, to be used for
|
595
|
+
the `WebApp` views, while `ApiApp::View` and `ApiApp::Layout` have a different
|
596
|
+
configuration.
|
597
|
+
|
509
598
|
### Thread safety
|
510
599
|
|
511
600
|
**Lotus::View**'s is thread safe during the runtime, but it isn't during the loading process.
|
data/lib/lotus/layout.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'lotus/utils/class_attribute'
|
1
2
|
require 'lotus/view/rendering/layout_registry'
|
2
3
|
require 'lotus/view/rendering/layout_scope'
|
3
4
|
require 'lotus/view/rendering/null_layout'
|
@@ -21,12 +22,18 @@ module Lotus
|
|
21
22
|
# include Lotus::Layout
|
22
23
|
# end
|
23
24
|
def self.included(base)
|
25
|
+
conf = Lotus::View::Configuration.for(base)
|
26
|
+
conf.add_layout(base)
|
27
|
+
|
24
28
|
base.class_eval do
|
25
29
|
extend Lotus::View::Dsl.dup
|
26
30
|
extend ClassMethods
|
27
|
-
end
|
28
31
|
|
29
|
-
|
32
|
+
include Utils::ClassAttribute
|
33
|
+
class_attribute :configuration
|
34
|
+
|
35
|
+
self.configuration = conf.duplicate
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
# Class level API
|
@@ -49,7 +56,7 @@ module Lotus
|
|
49
56
|
#
|
50
57
|
# @see Lotus::View::Rendering::LayoutRegistry
|
51
58
|
def registry
|
52
|
-
|
59
|
+
@registry ||= View::Rendering::LayoutRegistry.new(self)
|
53
60
|
end
|
54
61
|
|
55
62
|
# Template name
|
@@ -91,7 +98,7 @@ module Lotus
|
|
91
98
|
#
|
92
99
|
# @see Lotus::View.load!
|
93
100
|
def load!
|
94
|
-
registry.freeze
|
101
|
+
# registry.freeze
|
95
102
|
end
|
96
103
|
end
|
97
104
|
|