hanami-view 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -6
- data/lib/hanami/layout.rb +20 -2
- data/lib/hanami/view/rendering.rb +1 -1
- data/lib/hanami/view/rendering/null_view.rb +26 -0
- data/lib/hanami/view/rendering/options.rb +3 -2
- data/lib/hanami/view/template.rb +15 -3
- data/lib/hanami/view/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bd8111fc0f2c00a03f7a4020932a2f35f672e8fd93a7db28865fb8c4116053b
|
4
|
+
data.tar.gz: 4b3b34acf3bc9dd63f58866d5c023063c94826add5d8ad54baa522030ee5185b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a66c97948ce7e2838e5a9772157ac9850c81f382caf278dc62a1e2123ca186d802111ee6699199a0d659433caeed868379be4a63626fd9bf3ed1c8c6a74264de
|
7
|
+
data.tar.gz: 774d9cb89c4300314420042be8873cfc463e9fc2858ae2d7fcc2676ac6e5176d6fc53883b77ddd565bbc5c17a880982b76af6820e5aecfa254fa43c4a379da7d
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Hanami::View
|
2
2
|
View layer for Hanami
|
3
3
|
|
4
|
+
## v1.2.1 - 2018-10-16
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduced new, backward compatible, signature to render a layout for testing purposes (eg. `ApplicationLayout.new({ format: :html }, "contents").render`)
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [Luca Guidi] Ensure layout to be rendered when using HAML 5
|
10
|
+
- [Luca Guidi] Ensure to raise `NoMethodError` when an unknown method is invoked by a view/template
|
11
|
+
|
4
12
|
## v1.2.0 - 2018-04-06
|
5
13
|
|
6
14
|
## v1.2.0.rc2 - 2018-04-06
|
data/README.md
CHANGED
@@ -16,12 +16,12 @@ Like all the other Hanami components, it can be used as a standalone framework o
|
|
16
16
|
|
17
17
|
## Status
|
18
18
|
|
19
|
-
[![Gem Version](
|
20
|
-
[![
|
21
|
-
[![
|
22
|
-
[![
|
23
|
-
[![
|
24
|
-
[![Inline
|
19
|
+
[![Gem Version](https://badge.fury.io/rb/hanami-view.svg)](https://badge.fury.io/rb/hanami-view)
|
20
|
+
[![TravisCI](https://travis-ci.org/hanami/view.svg?branch=master)](https://travis-ci.org/hanami/view)
|
21
|
+
[![CircleCI](https://circleci.com/gh/hanami/view/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/view/tree/master)
|
22
|
+
[![Test Coverage](https://codecov.io/gh/hanami/view/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/view)
|
23
|
+
[![Depfu](https://badges.depfu.com/badges/4f5c8868d047d206f33893bc9194812d/overview.svg)](https://depfu.com/github/hanami/view?project=Bundler)
|
24
|
+
[![Inline Docs](http://inch-ci.org/github/hanami/view.svg)](http://inch-ci.org/github/hanami/view)
|
25
25
|
|
26
26
|
## Contact
|
27
27
|
|
data/lib/hanami/layout.rb
CHANGED
@@ -2,6 +2,7 @@ require 'hanami/utils/class_attribute'
|
|
2
2
|
require 'hanami/view/rendering/layout_registry'
|
3
3
|
require 'hanami/view/rendering/layout_scope'
|
4
4
|
require 'hanami/view/rendering/null_layout'
|
5
|
+
require 'hanami/view/rendering/null_view'
|
5
6
|
|
6
7
|
module Hanami
|
7
8
|
# Layout
|
@@ -116,7 +117,12 @@ module Hanami
|
|
116
117
|
|
117
118
|
# Initialize a layout
|
118
119
|
#
|
119
|
-
# @param scope [Hanami::View::Rendering::Scope] view rendering scope
|
120
|
+
# @param scope [Hanami::View::Rendering::Scope,::Hash] view rendering scope.
|
121
|
+
# Optionally a scope can be expressed as a Ruby `::Hash`, but it MUST contain
|
122
|
+
# the `:format` key, to specify which template to render.
|
123
|
+
# @option scope [Symbol] :format the format to render (e.g. `:html`, `:xml`, `:json`)
|
124
|
+
# This is mandatory only if a `:Hash` is passed as `scope`.
|
125
|
+
#
|
120
126
|
# @param rendered [String] the output of the view rendering process
|
121
127
|
#
|
122
128
|
# @api private
|
@@ -124,7 +130,19 @@ module Hanami
|
|
124
130
|
#
|
125
131
|
# @see Hanami::View::Rendering#render
|
126
132
|
def initialize(scope, rendered)
|
127
|
-
|
133
|
+
# NOTE: This complex data transformation is due to a combination of a bug and the intent of maintaing backward compat (SemVer).
|
134
|
+
# See https://github.com/hanami/view/pull/156
|
135
|
+
s, r = *case scope
|
136
|
+
when ::Hash
|
137
|
+
[Hanami::View::Rendering::Scope.new(Hanami::View::Rendering::NullView, scope), rendered]
|
138
|
+
when Hanami::View::Template
|
139
|
+
[Hanami::View::Rendering::Scope.new(Hanami::View::Rendering::NullView, rendered.merge(format: scope.format)), ""]
|
140
|
+
else
|
141
|
+
[scope, rendered]
|
142
|
+
end
|
143
|
+
|
144
|
+
@scope = View::Rendering::LayoutScope.new(self, s)
|
145
|
+
@rendered = r
|
128
146
|
end
|
129
147
|
|
130
148
|
# Render the layout
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Hanami
|
2
|
+
module View
|
3
|
+
module Rendering
|
4
|
+
# Null Object pattern for view
|
5
|
+
#
|
6
|
+
# It's used when a layout is rendered direcly for testing purposes
|
7
|
+
#
|
8
|
+
# @api private
|
9
|
+
# @since 1.2.1
|
10
|
+
class NullView
|
11
|
+
# Render the layout template
|
12
|
+
#
|
13
|
+
# @return [String] an empty string
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
# @since 1.2.1
|
17
|
+
#
|
18
|
+
# @see Hanami::Layout#render
|
19
|
+
# @see Hanami::View::Rendering#render
|
20
|
+
def render
|
21
|
+
""
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -12,9 +12,10 @@ module Hanami
|
|
12
12
|
# @api private
|
13
13
|
def self.build(options, locals, format)
|
14
14
|
options.dup.tap do |opts|
|
15
|
-
opts[:format]
|
15
|
+
opts[:format] ||= format
|
16
16
|
opts[:locals] = locals
|
17
|
-
opts[:locals].merge!(options.fetch(:locals) { ::Hash.new })
|
17
|
+
opts[:locals].merge!(options.fetch(:locals) { ::Hash.new })
|
18
|
+
opts[:locals].merge!(format: opts.fetch(:format, format))
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/lib/hanami/view/template.rb
CHANGED
@@ -7,9 +7,15 @@ module Hanami
|
|
7
7
|
# @since 0.1.0
|
8
8
|
class Template
|
9
9
|
def initialize(template, encoding = Encoding::UTF_8)
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
options = { default_encoding: encoding }
|
11
|
+
|
12
|
+
if slim?(template)
|
13
|
+
# NOTE disable_escape: true is for Slim compatibility
|
14
|
+
# See https://github.com/hanami/assets/issues/36
|
15
|
+
options[:disable_escape] = true
|
16
|
+
end
|
17
|
+
|
18
|
+
@_template = Tilt.new(template, nil, options)
|
13
19
|
end
|
14
20
|
|
15
21
|
# Returns the format that the template handles.
|
@@ -40,6 +46,12 @@ module Hanami
|
|
40
46
|
def render(scope, &blk)
|
41
47
|
@_template.render(scope, {}, &blk)
|
42
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def slim?(template)
|
53
|
+
File.extname(template) == ".slim".freeze
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
data/lib/hanami/view/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.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: 2018-
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/hanami/view/rendering/null_layout.rb
|
114
114
|
- lib/hanami/view/rendering/null_local.rb
|
115
115
|
- lib/hanami/view/rendering/null_template.rb
|
116
|
+
- lib/hanami/view/rendering/null_view.rb
|
116
117
|
- lib/hanami/view/rendering/options.rb
|
117
118
|
- lib/hanami/view/rendering/partial.rb
|
118
119
|
- lib/hanami/view/rendering/partial_file.rb
|
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
149
|
version: '0'
|
149
150
|
requirements: []
|
150
151
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.7.
|
152
|
+
rubygems_version: 2.7.7
|
152
153
|
signing_key:
|
153
154
|
specification_version: 4
|
154
155
|
summary: View layer for Hanami, with a separation between views and templates
|