dry-view 0.5.2 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d739724ab980eb210e9f651c78b3cbdf59e28c597e149b05d936f49a89f9d74f
4
- data.tar.gz: 23604cb777111c1711b09fd1da0b98f18840872d6c03f6867257eb42b3b3d755
3
+ metadata.gz: 9c234898af572e4ebd4b6717f0ba9519f2b4feda8a6d7b2133c00ee8cea2ac7a
4
+ data.tar.gz: 6f086379dad341a18fbf4f68b3b6edde81cdcdf30e38c859aa5ba86556c56ae7
5
5
  SHA512:
6
- metadata.gz: 5e66915108ff44c6e164459e30d3bcff67324b50dbd52bd853e1802bcbbefe824b440fc5e6e018033778f5d80717b8b61da1eaaf50071cad6ec9f3da154b15f8
7
- data.tar.gz: c587910c53a1d229533740204875a99b480e232b8a8fb397775dc234d33cdda60b42095800ba7c16d3c4d181a64d9f7bab909e202684f7d8e192222a7d9cb650
6
+ metadata.gz: 0af32817c536bd8beeb57d63e856aeb49400579ab084a586c7d8fcdad32052d91244cf4a450a5b10243915fa652140d3389fccbd2421a04d2479767d515e5bb5
7
+ data.tar.gz: e6dbf82b4d90b57751a74047ffa8d9cda75986bb468a42553ab150f8c9f12458662329f0be859bc1701ce6d39e3ee1ee523abcc23d0ce928ccba106e3b9593f3
@@ -1,3 +1,16 @@
1
+ # 0.5.3 / 2018-10-22
2
+
3
+ ### Added
4
+
5
+ - `renderer_options` setting for configuring tilt-based renderer (liseki in [#62][pr62])
6
+
7
+ ### Changed
8
+
9
+ - Part objects wrap values more transparently, via added `#respond_to_missing?` (liseki in [#63][pr63])
10
+
11
+ [pr62]: https://github.com/dry-rb/dry-view/pull/62
12
+ [pr63]: https://github.com/dry-rb/dry-view/pull/63
13
+
1
14
  # 0.5.2 / 2018-06-13
2
15
 
3
16
  ### Changed
@@ -14,6 +14,7 @@ module Dry
14
14
 
15
15
  DEFAULT_LAYOUTS_DIR = 'layouts'.freeze
16
16
  DEFAULT_CONTEXT = Object.new.freeze
17
+ DEFAULT_RENDERER_OPTIONS = {default_encoding: 'utf-8'.freeze}.freeze
17
18
  EMPTY_LOCALS = {}.freeze
18
19
 
19
20
  include Dry::Equalizer(:config)
@@ -24,6 +25,9 @@ module Dry
24
25
  setting :layout, false
25
26
  setting :template
26
27
  setting :default_format, :html
28
+ setting :renderer_options, DEFAULT_RENDERER_OPTIONS do |options|
29
+ DEFAULT_RENDERER_OPTIONS.merge(options.to_h).freeze
30
+ end
27
31
  setting :context, DEFAULT_CONTEXT
28
32
  setting :decorator, Decorator.new
29
33
 
@@ -49,7 +53,7 @@ module Dry
49
53
  # @api private
50
54
  def self.renderer(format)
51
55
  renderers.fetch(format) {
52
- renderers[format] = Renderer.new(paths, format: format)
56
+ renderers[format] = Renderer.new(paths, format: format, **config.renderer_options)
53
57
  }
54
58
  end
55
59
 
@@ -80,6 +80,12 @@ module Dry
80
80
  end
81
81
  end
82
82
 
83
+ def respond_to_missing?(name, include_private = false)
84
+ d = self.class.decorated_attributes
85
+ c = CONVENIENCE_METHODS
86
+ d.key?(name) || c.include?(name) || _value.respond_to?(name, include_private) || super
87
+ end
88
+
83
89
  def _render_scope(name, **locals)
84
90
  Scope.new(
85
91
  locals: locals.merge(name => self),
@@ -7,19 +7,20 @@ module Dry
7
7
  PARTIAL_PREFIX = "_".freeze
8
8
  PATH_DELIMITER = "/".freeze
9
9
 
10
- include Dry::Equalizer(:paths, :format)
10
+ include Dry::Equalizer(:paths, :format, :options)
11
11
 
12
12
  TemplateNotFoundError = Class.new(StandardError)
13
13
 
14
- attr_reader :paths, :format, :engine, :tilts
14
+ attr_reader :paths, :format, :options, :tilts
15
15
 
16
16
  def self.tilts
17
17
  @__engines__ ||= {}
18
18
  end
19
19
 
20
- def initialize(paths, format:)
20
+ def initialize(paths, format:, **options)
21
21
  @paths = paths
22
22
  @format = format
23
+ @options = options
23
24
  @tilts = self.class.tilts
24
25
  end
25
26
 
@@ -61,10 +62,9 @@ module Dry
61
62
  partial_name = name_segments[0..-2].push("#{PARTIAL_PREFIX}#{name_segments[-1]}").join(PATH_DELIMITER)
62
63
  end
63
64
 
64
- # TODO: make default_encoding configurable
65
65
  def tilt(path)
66
66
  tilts.fetch(path) {
67
- tilts[path] = Tilt.new(path, nil, default_encoding: "utf-8")
67
+ tilts[path] = Tilt.new(path, nil, **options)
68
68
  }
69
69
  end
70
70
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module View
3
- VERSION = '0.5.2'.freeze
3
+ VERSION = '0.5.3'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,3 @@
1
+ <% form action: '/people' do |f| %>
2
+ <%= f.text :name %>
3
+ <% end %>
@@ -34,4 +34,50 @@ RSpec.describe Dry::View::Controller do
34
34
  expect { controller.(options) }.to raise_error Dry::View::Controller::UndefinedTemplateError
35
35
  end
36
36
  end
37
+
38
+ describe 'renderer options' do
39
+ subject(:controller) {
40
+ Class.new(Dry::View::Controller) do
41
+ configure do |config|
42
+ config.paths = SPEC_ROOT.join('fixtures/templates')
43
+ config.template = 'controller_renderer_options'
44
+ config.renderer_options = {
45
+ outvar: '@__buf__'
46
+ }
47
+ end
48
+ end.new
49
+ }
50
+
51
+ subject(:context) {
52
+ Class.new do
53
+ def self.form(action:, &blk)
54
+ new(action, &blk)
55
+ end
56
+
57
+ def initialize(action, &blk)
58
+ @buf = eval('@__buf__', blk.binding)
59
+
60
+ @buf << "<form action=\"#{action}\" method=\"post\">"
61
+ blk.(self)
62
+ @buf << '</form>'
63
+ end
64
+
65
+ def text(name)
66
+ "<input type=\"text\" name=\"#{name}\" />"
67
+ end
68
+ end
69
+ }
70
+
71
+ it 'uses default encoding' do
72
+ klass = Class.new(Dry::View::Controller)
73
+ expect(klass.config.renderer_options).to be_a Hash
74
+ expect(klass.config.renderer_options[:default_encoding]).to eql 'utf-8'
75
+ end
76
+
77
+ it 'are passed to renderer' do
78
+ expect(controller.(context: context)).to eql(
79
+ '<form action="/people" method="post"><input type="text" name="name" /></form>'
80
+ )
81
+ end
82
+ end
37
83
  end
@@ -68,6 +68,20 @@ RSpec.describe Dry::View::Part do
68
68
  expect { part.farewell }.to raise_error(NoMethodError)
69
69
  end
70
70
  end
71
+
72
+ describe '#respond_to_missing?' do
73
+ let(:value) { double(greeting: 'hello from value') }
74
+
75
+ it 'handles convenience methods' do
76
+ expect(part).to respond_to(:context)
77
+ expect(part).to respond_to(:render)
78
+ expect(part).to respond_to(:value)
79
+ end
80
+
81
+ it 'handles value methods' do
82
+ expect(part).to respond_to(:greeting)
83
+ end
84
+ end
71
85
  end
72
86
 
73
87
  context 'without a renderer' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-06-12 00:00:00.000000000 Z
12
+ date: 2018-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -143,6 +143,7 @@ files:
143
143
  - lib/dry/view/scope.rb
144
144
  - lib/dry/view/version.rb
145
145
  - spec/fixtures/templates/_hello.html.slim
146
+ - spec/fixtures/templates/controller_renderer_options.html.erb
146
147
  - spec/fixtures/templates/decorated_parts.html.slim
147
148
  - spec/fixtures/templates/edit.html.slim
148
149
  - spec/fixtures/templates/empty.html.slim
@@ -196,12 +197,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  version: '0'
197
198
  requirements: []
198
199
  rubyforge_project:
199
- rubygems_version: 2.7.5
200
+ rubygems_version: 2.7.7
200
201
  signing_key:
201
202
  specification_version: 4
202
203
  summary: Functional view rendering system
203
204
  test_files:
204
205
  - spec/fixtures/templates/_hello.html.slim
206
+ - spec/fixtures/templates/controller_renderer_options.html.erb
205
207
  - spec/fixtures/templates/decorated_parts.html.slim
206
208
  - spec/fixtures/templates/edit.html.slim
207
209
  - spec/fixtures/templates/empty.html.slim