lotus-view 0.4.0 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +40 -0
- data/lib/lotus/view/rendering/layout_scope.rb +47 -0
- data/lib/lotus/view/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b321d4151a1e0e2117595364a5ced056dd1e392f
|
4
|
+
data.tar.gz: 3632ba288305a3e5c872bab66bef57be6bf24dd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f28b9f392d7a31f577fdd5cc8a9ee3afaedf3aef95db0525768aad3d4dd3505d4719a5ed46ba9483e267c7c57ab9f0730956c6a98ec95c7c8946c6f98d5773d
|
7
|
+
data.tar.gz: 5c82053e74076b8ab8e159efdd5ee51702a23f6fb37fd422ca29f7c0bb2ec4f23620af53279ea7d1cfbbb9b9b0312686286501fe7e2e2954828db35abd58b1e0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Lotus::View
|
2
2
|
View layer for Lotus
|
3
3
|
|
4
|
+
## v0.4.1 - 2015-05-22
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduced `#content` to render optional contents in a different context (eg. a view sets a page specific javascript in the application template footer).
|
7
|
+
|
4
8
|
## v0.4.0 - 2015-03-23
|
5
9
|
### Changed
|
6
10
|
- [Luca Guidi] Autoescape concrete and virtual methods from presenters
|
data/README.md
CHANGED
@@ -470,6 +470,46 @@ Articles::Index.render(format: :rss) # => Will use nothing
|
|
470
470
|
|
471
471
|
As per convention, layout templates are located under `Lotus::View.root` or `ApplicationLayout.root` and use the underscored name (eg. `ApplicationLayout => application.html.erb`).
|
472
472
|
|
473
|
+
### Optional Content
|
474
|
+
|
475
|
+
If we want to render optional contents such as sidebar links or page specific javascripts, we can use `#content`
|
476
|
+
It accepts a key that represents a method that should be available within the rendering context.
|
477
|
+
That context is made of the locals, and the methods that view and layout respond to.
|
478
|
+
If the context can't dispatch that method, it returns `nil`.
|
479
|
+
|
480
|
+
Given the following layout template.
|
481
|
+
|
482
|
+
```erb
|
483
|
+
<!doctype HTML>
|
484
|
+
<html>
|
485
|
+
<!-- ... -->
|
486
|
+
<body>
|
487
|
+
<!-- ... -->
|
488
|
+
<%= content :footer %>
|
489
|
+
</body>
|
490
|
+
</html>
|
491
|
+
```
|
492
|
+
|
493
|
+
We have two views, one responds to `#footer` (`Products::Show`) and the other doesn't (`Products::Index`).
|
494
|
+
When the first is rendered, `content` gives back the returning value of `#footer`.
|
495
|
+
In the other case, `content` returns `nil`.
|
496
|
+
|
497
|
+
```ruby
|
498
|
+
module Products
|
499
|
+
class Index
|
500
|
+
include Lotus::View
|
501
|
+
end
|
502
|
+
|
503
|
+
class Show
|
504
|
+
include Lotus::View
|
505
|
+
|
506
|
+
def footer
|
507
|
+
"contents for footer"
|
508
|
+
end
|
509
|
+
end
|
510
|
+
end
|
511
|
+
```
|
512
|
+
|
473
513
|
### Presenters
|
474
514
|
|
475
515
|
The goal of a presenter is to wrap and reuse presentational logic for an object.
|
@@ -111,6 +111,53 @@ module Lotus
|
|
111
111
|
@locals || @scope.locals
|
112
112
|
end
|
113
113
|
|
114
|
+
# Returns a content for the given key, by trying to invoke on the current
|
115
|
+
# scope, a method with the same name.
|
116
|
+
#
|
117
|
+
# The scope is made of locals and concrete methods from view and layout.
|
118
|
+
#
|
119
|
+
# @param key [Symbol] a method to invoke within current scope
|
120
|
+
# @return [String,NilClass] returning content if scope respond to the
|
121
|
+
# requested method
|
122
|
+
#
|
123
|
+
# @since 0.4.1
|
124
|
+
#
|
125
|
+
# @example
|
126
|
+
# # Given the following layout template
|
127
|
+
#
|
128
|
+
# <!doctype HTML>
|
129
|
+
# <html>
|
130
|
+
# <!-- ... -->
|
131
|
+
# <body>
|
132
|
+
# <!-- ... -->
|
133
|
+
# <%= content :footer %>
|
134
|
+
# </body>
|
135
|
+
# </html>
|
136
|
+
#
|
137
|
+
# # Case 1:
|
138
|
+
# # Products::Index doesn't respond to #footer, content will return nil
|
139
|
+
# #
|
140
|
+
# # Case 2:
|
141
|
+
# # Products::Show responds to #footer, content will send back
|
142
|
+
# # #footer returning value
|
143
|
+
#
|
144
|
+
# module Products
|
145
|
+
# class Index
|
146
|
+
# include Lotus::View
|
147
|
+
# end
|
148
|
+
#
|
149
|
+
# class Show
|
150
|
+
# include Lotus::View
|
151
|
+
#
|
152
|
+
# def footer
|
153
|
+
# "contents for footer"
|
154
|
+
# end
|
155
|
+
# end
|
156
|
+
# end
|
157
|
+
def content(key)
|
158
|
+
__send__(key) if respond_to?(key)
|
159
|
+
end
|
160
|
+
|
114
161
|
# Implements "respond to" logic
|
115
162
|
#
|
116
163
|
# @return [TrueClass,FalseClass]
|
data/lib/lotus/view/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|