hanami-view 2.1.0.beta1 → 2.1.0.beta2

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: 547759271a98bf19bed148a823827ddb668f8034ce9673a0db01a989f10d8b4a
4
- data.tar.gz: 5fbab49653a3efd335a8b67ce8910a6a077023b57466b0f84f61a71ffc8cc328
3
+ metadata.gz: d15d51188db92065fac65432748c393654adc894fb1fbb41547eb3226af3736d
4
+ data.tar.gz: b4af5a77b310e6a32fd33f61359429c5dfe4ef269638f7aa0623db4171797784
5
5
  SHA512:
6
- metadata.gz: 2f218ce967455774e6b00340a791b17e30accdee496c88f79c2b12721a97e2008d40341b8981f3144caba2a7bacb0eff9aa0e0c51b8f0c25b1406b55c0a68d18
7
- data.tar.gz: 83cf8481266c6f0c8e4c76ec3c87b36b60e2e3035fc61db1ee9497675030008efde35fd5890e625a3560b9c6fc0b182956f55c9358e7752f5c6457ea5e4fb5a8
6
+ metadata.gz: 3792f9a42a835e7e3441d9cc5544689543f33d7575d8e1e872ba26bcae1b5c59a441499c4c1b334a4f40abc049aceb1c8725753f9e71185d788804281579069d
7
+ data.tar.gz: 280eb1a5752838d0ffab053ff7dac261ed5529a481caceda9a8dda54784009c49592caa7ec463087932d325cbcd98c8f15d942c7e0bff81dd13ee9ebed6223b1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  View layer for Hanami
4
4
 
5
+ ## v2.1.0.beta2 - 2023-10-04
6
+
7
+ ### Added
8
+ - [Luca Guidi] Add `Hanami::View::Rendered#match?`, `#match`, and `#include?` to make it more specs friendly.
9
+ - [Philip Arndt] Make `Hanami::View#call` to accept `layout:` keyword argument to specify the layout to use during the rendering.
10
+
5
11
  ## v2.1.0.beta1 - 2023-06-29
6
12
 
7
13
  ### Added
@@ -7,6 +7,7 @@ module Hanami
7
7
  # Output of a View rendering
8
8
  #
9
9
  # @api public
10
+ # @since 2.1.0
10
11
  class Rendered
11
12
  include Dry::Equalizer(:output, :locals)
12
13
 
@@ -15,6 +16,7 @@ module Hanami
15
16
  # @return [String]
16
17
  #
17
18
  # @api public
19
+ # @since 2.1.0
18
20
  attr_reader :output
19
21
 
20
22
  # Returns the hash of locals used to render the view
@@ -22,9 +24,11 @@ module Hanami
22
24
  # @return [Hash[<Symbol, Hanami::View::Part>] locals hash
23
25
  #
24
26
  # @api public
27
+ # @since 2.1.0
25
28
  attr_reader :locals
26
29
 
27
30
  # @api private
31
+ # @since 2.1.0
28
32
  def initialize(output:, locals:)
29
33
  @output = output
30
34
  @locals = locals
@@ -37,6 +41,7 @@ module Hanami
37
41
  # @return [Hanami::View::Part]
38
42
  #
39
43
  # @api public
44
+ # @since 2.1.0
40
45
  def [](name)
41
46
  locals[name]
42
47
  end
@@ -46,10 +51,36 @@ module Hanami
46
51
  # @return [String]
47
52
  #
48
53
  # @api public
54
+ # @since 2.1.0
49
55
  def to_s
50
56
  output
51
57
  end
52
58
  alias_method :to_str, :to_s
59
+
60
+ # Matches given input with the rendered view
61
+ #
62
+ # @param matcher [String, Regexp] matcher
63
+ #
64
+ # @return [TrueClass,FalseClass]
65
+ #
66
+ # @api public
67
+ # @since 2.1.0
68
+ def match?(matcher)
69
+ output.match?(matcher)
70
+ end
71
+ alias_method :match, :match?
72
+
73
+ # Checks if given string is included in the rendered view
74
+ #
75
+ # @param string [String] string
76
+ #
77
+ # @return [TrueClass,FalseClass]
78
+ #
79
+ # @api public
80
+ # @since 2.1.0
81
+ def include?(string)
82
+ output.include?(string)
83
+ end
53
84
  end
54
85
  end
55
86
  end
@@ -3,6 +3,6 @@
3
3
  module Hanami
4
4
  class View
5
5
  # @api private
6
- VERSION = "2.1.0.beta1"
6
+ VERSION = "2.1.0.beta2"
7
7
  end
8
8
  end
data/lib/hanami/view.rb CHANGED
@@ -477,8 +477,8 @@ module Hanami
477
477
  # @!endgroup
478
478
 
479
479
  # @api private
480
- def self.layout_path
481
- File.join(*[config.layouts_dir, config.layout].compact)
480
+ def self.layout_path(layout)
481
+ File.join(*[config.layouts_dir, layout].compact)
482
482
  end
483
483
 
484
484
  # @api private
@@ -520,24 +520,25 @@ module Hanami
520
520
  #
521
521
  # @param format [Symbol] template format to use
522
522
  # @param context [Context] context object to use
523
+ # @param layout [String, FalseClass, nil] layout name, or false to indicate no layout
523
524
  # @param input input data for preparing exposure values
524
525
  #
525
526
  # @return [Rendered] rendered view object
526
527
  # @api public
527
- def call(format: config.default_format, context: config.default_context, **input)
528
+ def call(format: config.default_format, context: config.default_context, layout: config.layout, **input)
528
529
  rendering = self.rendering(format: format, context: context)
529
530
 
530
531
  locals = locals(rendering, input)
531
532
  output = rendering.template(config.template, rendering.scope(config.scope, locals))
532
533
 
533
- if layout?
534
+ if layout
534
535
  begin
535
536
  output = rendering.template(
536
- self.class.layout_path,
537
+ self.class.layout_path(layout),
537
538
  rendering.scope(config.scope, layout_locals(locals))
538
539
  ) { output }
539
540
  rescue TemplateNotFoundError
540
- raise LayoutNotFoundError.new(config.layout, config.paths)
541
+ raise LayoutNotFoundError.new(layout, config.paths)
541
542
  end
542
543
  end
543
544
 
@@ -570,9 +571,5 @@ module Hanami
570
571
  layout_locals[key] = value if exposures[key].for_layout?
571
572
  end
572
573
  end
573
-
574
- def layout?
575
- !!config.layout # rubocop:disable Style/DoubleNegation
576
- end
577
574
  end
578
575
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta1
4
+ version: 2.1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Riley
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-06-29 00:00:00.000000000 Z
12
+ date: 2023-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby