lotus-view 0.4.4 → 0.5.0
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 +12 -0
- data/LICENSE.md +1 -1
- data/README.md +6 -1
- data/lib/lotus/layout.rb +1 -1
- data/lib/lotus/view.rb +5 -34
- data/lib/lotus/view/configuration.rb +64 -6
- data/lib/lotus/view/dsl.rb +2 -2
- data/lib/lotus/view/errors.rb +47 -0
- data/lib/lotus/view/inheritable.rb +2 -2
- data/lib/lotus/view/rendering.rb +1 -1
- data/lib/lotus/view/rendering/layout_registry.rb +0 -10
- data/lib/lotus/view/rendering/layout_scope.rb +0 -2
- data/lib/lotus/view/rendering/partial_finder.rb +1 -1
- data/lib/lotus/view/rendering/template.rb +12 -1
- data/lib/lotus/view/rendering/templates_finder.rb +1 -1
- data/lib/lotus/view/template.rb +2 -2
- data/lib/lotus/view/version.rb +1 -1
- data/lotus-view.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4af30e053bd980adee58a5c31b34d1a47672a2c
|
4
|
+
data.tar.gz: 9215a2d92a5f5c8b76e4a77d13bfae59f996cde2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2933b16f795e1fcd6f62b0739b035ebe9a0798cb4a9debffb40a01b72f5d65d95b16bbf4e72a3e2a64993bc3c32aba09c2200b804a5ad40205b34ac404b9dfc2
|
7
|
+
data.tar.gz: b735e3c0352fdcc0e8a685b148caf332543d514a840765c54ff49df52972f38bccc18d2ec110e126dc76706de44dee04c9d97820e1a1804fc7417d2e7c0dc031
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# Lotus::View
|
2
2
|
View layer for Lotus
|
3
3
|
|
4
|
+
## v0.5.0 - 2016-01-12
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Added `Lotus::View::Configuration#default_encoding` to set the encoding for templates
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [Luca Guidi] Let exceptions to be raised as they occur in rendering context. This fixes misleading backtraces for exceptions.
|
10
|
+
- [Martin Rubi] Raise a `Lotus::View::MissingTemplateError` when rendering a missing partial from a template
|
11
|
+
- [Luca Guidi] Fix for `template.erb is not valid US-ASCII (Encoding::InvalidByteSequenceError)` when system encoding is not set
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- [Liam Dawson] Introduced `Lotus::View::Error` and let all the framework exceptions to inherit from it.
|
15
|
+
|
4
16
|
## v0.4.4 - 2015-09-30
|
5
17
|
### Added
|
6
18
|
- [Luca Guidi] Autoescape for layout helpers.
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -573,6 +573,11 @@ Lotus::View.configure do
|
|
573
573
|
#
|
574
574
|
root '/path/to/root'
|
575
575
|
|
576
|
+
# Default encoding for templates
|
577
|
+
# Argument: String, defaults to utf-8
|
578
|
+
#
|
579
|
+
default_encoding 'koi-8'
|
580
|
+
|
576
581
|
# Set the Ruby namespace where to lookup for views
|
577
582
|
# Argument: Class, Module, String, defaults to Object
|
578
583
|
#
|
@@ -845,4 +850,4 @@ __Lotus::View__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
845
850
|
|
846
851
|
## Copyright
|
847
852
|
|
848
|
-
Copyright 2014-
|
853
|
+
Copyright 2014-2016 Luca Guidi – Released under MIT License
|
data/lib/lotus/layout.rb
CHANGED
data/lib/lotus/view.rb
CHANGED
@@ -7,6 +7,7 @@ require 'lotus/view/inheritable'
|
|
7
7
|
require 'lotus/view/rendering'
|
8
8
|
require 'lotus/view/escape'
|
9
9
|
require 'lotus/view/dsl'
|
10
|
+
require 'lotus/view/errors'
|
10
11
|
require 'lotus/layout'
|
11
12
|
require 'lotus/presenter'
|
12
13
|
|
@@ -15,37 +16,7 @@ module Lotus
|
|
15
16
|
#
|
16
17
|
# @since 0.1.0
|
17
18
|
module View
|
18
|
-
# Missing template error
|
19
|
-
#
|
20
|
-
# This is raised at the runtime when Lotus::View cannot find a template for
|
21
|
-
# the requested format.
|
22
|
-
#
|
23
|
-
# We can't raise this error during the loading phase, because at that time
|
24
|
-
# we don't know if a view implements its own rendering policy.
|
25
|
-
# A view is allowed to override `#render`, and this scenario can make the
|
26
|
-
# presence of a template useless. One typical example is the usage of a
|
27
|
-
# serializer that returns the output string, without rendering a template.
|
28
|
-
#
|
29
|
-
# @since 0.1.0
|
30
|
-
class MissingTemplateError < ::StandardError
|
31
|
-
def initialize(template, format)
|
32
|
-
super("Can't find template '#{ template }' for '#{ format }' format.")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# Missing format error
|
37
|
-
#
|
38
|
-
# This is raised at the runtime when rendering context lacks of the :format
|
39
|
-
# key.
|
40
|
-
#
|
41
|
-
# @since 0.1.0
|
42
|
-
#
|
43
|
-
# @see Lotus::View::Rendering#render
|
44
|
-
class MissingFormatError < ::StandardError
|
45
|
-
end
|
46
|
-
|
47
19
|
include Utils::ClassAttribute
|
48
|
-
|
49
20
|
# Framework configuration
|
50
21
|
#
|
51
22
|
# @since 0.2.0
|
@@ -268,10 +239,10 @@ module Lotus
|
|
268
239
|
conf.add_view(base)
|
269
240
|
|
270
241
|
base.class_eval do
|
271
|
-
extend Inheritable
|
272
|
-
extend Dsl
|
273
|
-
extend Rendering
|
274
|
-
extend Escape
|
242
|
+
extend Inheritable
|
243
|
+
extend Dsl
|
244
|
+
extend Rendering
|
245
|
+
extend Escape
|
275
246
|
|
276
247
|
include Utils::ClassAttribute
|
277
248
|
class_attribute :configuration
|
@@ -29,6 +29,12 @@ module Lotus
|
|
29
29
|
# @api private
|
30
30
|
DEFAULT_ROOT = '.'.freeze
|
31
31
|
|
32
|
+
# Default encoding
|
33
|
+
#
|
34
|
+
# @since 0.5.0
|
35
|
+
# @api private
|
36
|
+
DEFAULT_ENCODING = Encoding::UTF_8
|
37
|
+
|
32
38
|
attr_reader :load_paths
|
33
39
|
attr_reader :views
|
34
40
|
attr_reader :layouts
|
@@ -237,6 +243,55 @@ module Lotus
|
|
237
243
|
end
|
238
244
|
end
|
239
245
|
|
246
|
+
# Default encoding for templates
|
247
|
+
#
|
248
|
+
# This is part of a DSL, for this reason when this method is called with
|
249
|
+
# an argument, it will set the corresponding instance variable. When
|
250
|
+
# called without, it will return the already set value, or the default.
|
251
|
+
#
|
252
|
+
# @overload default_encoding(value)
|
253
|
+
# Sets the given value
|
254
|
+
# @param value [String,Encoding] a string representation of the encoding,
|
255
|
+
# or an Encoding constant
|
256
|
+
#
|
257
|
+
# @raise [ArgumentError] if the given value isn't a supported encoding
|
258
|
+
#
|
259
|
+
# @overload default_encoding
|
260
|
+
# Gets the value
|
261
|
+
# @return [Encoding]
|
262
|
+
#
|
263
|
+
# @since 0.5.0
|
264
|
+
#
|
265
|
+
# @example Set UTF-8 As A String
|
266
|
+
# require 'lotus/view'
|
267
|
+
#
|
268
|
+
# Lotus::View.configure do
|
269
|
+
# default_encoding 'utf-8'
|
270
|
+
# end
|
271
|
+
#
|
272
|
+
# @example Set UTF-8 As An Encoding Constant
|
273
|
+
# require 'lotus/view'
|
274
|
+
#
|
275
|
+
# Lotus::View.configure do
|
276
|
+
# default_encoding Encoding::UTF_8
|
277
|
+
# end
|
278
|
+
#
|
279
|
+
# @example Raise An Error For Unknown Encoding
|
280
|
+
# require 'lotus/view'
|
281
|
+
#
|
282
|
+
# Lotus::View.configure do
|
283
|
+
# default_encoding 'foo'
|
284
|
+
# end
|
285
|
+
#
|
286
|
+
# # => ArgumentError
|
287
|
+
def default_encoding(value = nil)
|
288
|
+
if value.nil?
|
289
|
+
@default_encoding
|
290
|
+
else
|
291
|
+
@default_encoding = Encoding.find(value)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
240
295
|
# Prepare the views.
|
241
296
|
#
|
242
297
|
# The given block will be yielded when `Lotus::View` will be included by
|
@@ -347,11 +402,12 @@ module Lotus
|
|
347
402
|
# @api private
|
348
403
|
def duplicate
|
349
404
|
Configuration.new.tap do |c|
|
350
|
-
c.namespace
|
351
|
-
c.root
|
352
|
-
c.layout
|
353
|
-
c.
|
354
|
-
c.
|
405
|
+
c.namespace = namespace
|
406
|
+
c.root = root
|
407
|
+
c.layout = @layout # lazy loading of the class
|
408
|
+
c.default_encoding = default_encoding
|
409
|
+
c.load_paths = load_paths.dup
|
410
|
+
c.modules = modules.dup
|
355
411
|
end
|
356
412
|
end
|
357
413
|
|
@@ -370,7 +426,8 @@ module Lotus
|
|
370
426
|
# @since 0.2.0
|
371
427
|
# @api private
|
372
428
|
def reset!
|
373
|
-
root
|
429
|
+
root DEFAULT_ROOT
|
430
|
+
default_encoding DEFAULT_ENCODING
|
374
431
|
|
375
432
|
@views = Set.new
|
376
433
|
@layouts = Set.new
|
@@ -400,6 +457,7 @@ module Lotus
|
|
400
457
|
attr_writer :root
|
401
458
|
attr_writer :load_paths
|
402
459
|
attr_writer :layout
|
460
|
+
attr_writer :default_encoding
|
403
461
|
attr_writer :modules
|
404
462
|
end
|
405
463
|
end
|
data/lib/lotus/view/dsl.rb
CHANGED
@@ -205,9 +205,9 @@ module Lotus
|
|
205
205
|
# Bookshelf::Api::Views::Books::Index.template # => 'books/index'
|
206
206
|
def template(value = nil)
|
207
207
|
if value.nil?
|
208
|
-
|
208
|
+
@template ||= Rendering::TemplateName.new(name, configuration.namespace).to_s
|
209
209
|
else
|
210
|
-
|
210
|
+
@template = value
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lotus
|
2
|
+
module View
|
3
|
+
# @since 0.5.0
|
4
|
+
class Error < ::StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
# Missing template error
|
8
|
+
#
|
9
|
+
# This is raised at the runtime when Lotus::View cannot find a template for
|
10
|
+
# the requested format.
|
11
|
+
#
|
12
|
+
# We can't raise this error during the loading phase, because at that time
|
13
|
+
# we don't know if a view implements its own rendering policy.
|
14
|
+
# A view is allowed to override `#render`, and this scenario can make the
|
15
|
+
# presence of a template useless. One typical example is the usage of a
|
16
|
+
# serializer that returns the output string, without rendering a template.
|
17
|
+
#
|
18
|
+
# @since 0.1.0
|
19
|
+
class MissingTemplateError < Error
|
20
|
+
def initialize(template, format)
|
21
|
+
super("Can't find template '#{ template }' for '#{ format }' format.")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Missing format error
|
26
|
+
#
|
27
|
+
# This is raised at the runtime when rendering context lacks of the :format
|
28
|
+
# key.
|
29
|
+
#
|
30
|
+
# @since 0.1.0
|
31
|
+
#
|
32
|
+
# @see Lotus::View::Rendering#render
|
33
|
+
class MissingFormatError < Error
|
34
|
+
end
|
35
|
+
|
36
|
+
# Missing template layout error
|
37
|
+
#
|
38
|
+
# This is raised at the runtime when Lotus::Layout cannot find it's template.
|
39
|
+
#
|
40
|
+
# @since 0.5.0
|
41
|
+
class MissingTemplateLayoutError < Error
|
42
|
+
def initialize(template)
|
43
|
+
super("Can't find layout template '#{ template }'")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -27,7 +27,7 @@ module Lotus
|
|
27
27
|
# @api private
|
28
28
|
# @since 0.1.0
|
29
29
|
def subclasses
|
30
|
-
|
30
|
+
@subclasses ||= Set.new
|
31
31
|
end
|
32
32
|
|
33
33
|
protected
|
@@ -47,7 +47,7 @@ module Lotus
|
|
47
47
|
# @api private
|
48
48
|
# @since 0.1.0
|
49
49
|
def views
|
50
|
-
|
50
|
+
@views ||= [ self ] + subclasses.to_a
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/lib/lotus/view/rendering.rb
CHANGED
@@ -4,16 +4,6 @@ require 'lotus/view/rendering/templates_finder'
|
|
4
4
|
module Lotus
|
5
5
|
module View
|
6
6
|
module Rendering
|
7
|
-
# Missing template layout error
|
8
|
-
#
|
9
|
-
# This is raised at the runtime when Lotus::Layout cannot find it's template.
|
10
|
-
#
|
11
|
-
# @since 0.3.0
|
12
|
-
class MissingTemplateLayoutError < ::StandardError
|
13
|
-
def initialize(template)
|
14
|
-
super("Can't find layout template '#{ template }'")
|
15
|
-
end
|
16
|
-
end
|
17
7
|
# Holds the references of all the registered layouts.
|
18
8
|
# As now the registry is unique at the level of the framework.
|
19
9
|
#
|
@@ -36,10 +36,12 @@ module Lotus
|
|
36
36
|
#
|
37
37
|
# @return [String] the output of the rendering process.
|
38
38
|
#
|
39
|
+
# @raise [Lotus::View::MissingTemplateError] if template can't be found
|
40
|
+
#
|
39
41
|
# @api private
|
40
42
|
# @since 0.1.0
|
41
43
|
def render
|
42
|
-
template.render(scope)
|
44
|
+
(template or raise_missing_template_error).render(scope)
|
43
45
|
end
|
44
46
|
|
45
47
|
protected
|
@@ -50,6 +52,15 @@ module Lotus
|
|
50
52
|
def scope
|
51
53
|
Scope.new(@view, @options[:locals])
|
52
54
|
end
|
55
|
+
|
56
|
+
# @since 0.5.0
|
57
|
+
# @api private
|
58
|
+
def raise_missing_template_error
|
59
|
+
raise MissingTemplateError.new(
|
60
|
+
@options.fetch(:template) { @options.fetch(:partial, nil) },
|
61
|
+
@options[:format]
|
62
|
+
)
|
63
|
+
end
|
53
64
|
end
|
54
65
|
end
|
55
66
|
end
|
@@ -70,7 +70,7 @@ module Lotus
|
|
70
70
|
# # => [#<Lotus::View::Template:0x007f8a0a86a970 ... @file="/path/to/templates/articles/show.html.erb">]
|
71
71
|
def find
|
72
72
|
_find.map do |template|
|
73
|
-
View::Template.new(template)
|
73
|
+
View::Template.new(template, @view.configuration.default_encoding)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
data/lib/lotus/view/template.rb
CHANGED
@@ -6,8 +6,8 @@ module Lotus
|
|
6
6
|
#
|
7
7
|
# @since 0.1.0
|
8
8
|
class Template
|
9
|
-
def initialize(template)
|
10
|
-
@_template = Tilt.new(template)
|
9
|
+
def initialize(template, encoding = Encoding::UTF_8)
|
10
|
+
@_template = Tilt.new(template, nil, default_encoding: encoding)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Returns the format that the template handles.
|
data/lib/lotus/view/version.rb
CHANGED
data/lotus-view.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.required_ruby_version = '>= 2.0.0'
|
21
21
|
|
22
22
|
spec.add_runtime_dependency 'tilt', '~> 2.0', '>= 2.0.1'
|
23
|
-
spec.add_runtime_dependency 'lotus-utils', '~> 0.
|
23
|
+
spec.add_runtime_dependency 'lotus-utils', '~> 0.6'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
26
26
|
spec.add_development_dependency 'minitest', '~> 5'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-view
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: tilt
|
@@ -38,14 +38,14 @@ dependencies:
|
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0.
|
41
|
+
version: '0.6'
|
42
42
|
type: :runtime
|
43
43
|
prerelease: false
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0.
|
48
|
+
version: '0.6'
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: bundler
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/lotus/view.rb
|
107
107
|
- lib/lotus/view/configuration.rb
|
108
108
|
- lib/lotus/view/dsl.rb
|
109
|
+
- lib/lotus/view/errors.rb
|
109
110
|
- lib/lotus/view/escape.rb
|
110
111
|
- lib/lotus/view/inheritable.rb
|
111
112
|
- lib/lotus/view/rendering.rb
|
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
147
|
version: '0'
|
147
148
|
requirements: []
|
148
149
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.5.1
|
150
151
|
signing_key:
|
151
152
|
specification_version: 4
|
152
153
|
summary: View layer for Lotus, with a separation between views and templates
|