lookbook 2.2.2 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8bb30f67eba8a56b3e6638e5671e493580bee97045acaeeeaa25a9bc1d92801a
4
- data.tar.gz: 45ed40efdc4715461fa05217c5514103975182dca010fe754df54bd0572be450
3
+ metadata.gz: '0277029efee9bfc07832f5bc2ea7d1a57063a81e2e2986978c93abca8750fbe2'
4
+ data.tar.gz: c03b8c178645b7dba6572d37711cb4664ea4175fa56430acd595a369069d54c9
5
5
  SHA512:
6
- metadata.gz: e1cd96f2564bd3c4dbb3b4343f31505006403b5260ab47ede3dafb4514d40b406d6c25d6702323a69b36bd8af951b72918a55c04c1cb0c28473802cf169dd22f
7
- data.tar.gz: 99650923f94a8e6c9e1bce12c0f292adabcfc0ffde22cc0cf881689d6171aacb14c34f9bb16e6b05b63aa32240802e52809a79ccfd990c9875c8744d99daa18c
6
+ metadata.gz: c34fbd701d1f7818dea444b9ad899b7dce012968a0cc0038dd197bf0e70ea2af105c2d299e3ac21302f9276d0dde162b56cfebb8f45ba4e7eb9c1ab1455c4555
7
+ data.tar.gz: 50613e6f04c758f5c93fa4ff659a0a0a4c1a903e80d167a3c1aead2f6e5af7278549b260255405c077fe1f35ba920fc050fdfdb0dab4d37ce7df18658f6ace47
@@ -15,7 +15,7 @@ module Lookbook
15
15
  @next_page = @pages.next(@page)
16
16
  @previous_page = @pages.previous(@page)
17
17
 
18
- content = ActionViewAnnotationsHandler.call(disable_annotations: true) do
18
+ content = ActionViewConfigHandler.call do
19
19
  render_to_string inline: @page.content, locals: {
20
20
  page: @page,
21
21
  next_page: @next_page,
data/config/app.yml CHANGED
@@ -21,6 +21,7 @@ shared:
21
21
  display_option_controls: true
22
22
  preview_layout: ~
23
23
  preview_disable_action_view_annotations: true
24
+ preview_disable_action_view_partial_prefixes: true
24
25
  preview_type_default: view_component
25
26
  preview_sort_scenarios: false
26
27
  preview_disable_error_handling: false
@@ -21,24 +21,23 @@ module Lookbook
21
21
  opts[:assigns] = @render_args[:assigns] || {}
22
22
  opts[:locals] = locals if locals.present?
23
23
 
24
- rendered = render_to_string(template, **opts)
25
-
26
- if scenario.after_render_method.present?
27
- render_context = Store.new({
28
- preview: preview,
29
- scenario: scenario,
30
- params: user_request_parameters
31
- })
32
- rendered = @preview.after_render(method: scenario.after_render_method, html: rendered, context: render_context)
33
- end
24
+ with_action_view_settings do
25
+ rendered = render_to_string(template, **opts)
34
26
 
35
- with_optional_action_view_annotations do
27
+ if scenario.after_render_method.present?
28
+ render_context = Store.new({
29
+ preview: preview,
30
+ scenario: scenario,
31
+ params: user_request_parameters
32
+ })
33
+ rendered = @preview.after_render(method: scenario.after_render_method, html: rendered, context: render_context)
34
+ end
36
35
  render html: rendered
37
36
  end
38
37
  end
39
38
 
40
39
  def render_in_layout_to_string(template, locals, opts = {})
41
- with_optional_action_view_annotations do
40
+ with_action_view_settings do
42
41
  html = render_to_string(template, locals: locals, **determine_layout(opts[:layout]))
43
42
  if opts[:append_html].present?
44
43
  html += opts[:append_html]
@@ -49,9 +48,12 @@ module Lookbook
49
48
 
50
49
  protected
51
50
 
52
- def with_optional_action_view_annotations(&block)
53
- disable = Lookbook.config.preview_disable_action_view_annotations
54
- ActionViewAnnotationsHandler.call(disable_annotations: disable, &block)
51
+ def with_action_view_settings(&block)
52
+ ActionViewConfigHandler.call(
53
+ disable_annotations: Lookbook.config.preview_disable_action_view_annotations,
54
+ disable_partial_prefixes: Lookbook.config.preview_disable_action_view_partial_prefixes,
55
+ &block
56
+ )
55
57
  end
56
58
 
57
59
  def user_request_parameters
@@ -0,0 +1,50 @@
1
+ module Lookbook
2
+ class ActionViewConfigHandler < Service
3
+ attr_reader :disable_annotations, :disable_partial_prefixes
4
+
5
+ def initialize(disable_annotations: true, disable_partial_prefixes: true)
6
+ @disable_annotations = disable_annotations
7
+ @disable_partial_prefixes = disable_partial_prefixes
8
+ end
9
+
10
+ def call
11
+ handle_annotations
12
+ handle_partial_prefixes
13
+
14
+ yield
15
+ ensure
16
+ restore_annotations
17
+ restore_partial_prefixes
18
+ end
19
+
20
+ private
21
+
22
+ def handle_annotations
23
+ return unless disable_annotations && ActionView::Base.respond_to?(:annotate_rendered_view_with_filenames)
24
+
25
+ @original_annotations_value = ActionView::Base.annotate_rendered_view_with_filenames
26
+ ActionView::Base.annotate_rendered_view_with_filenames = false
27
+ end
28
+
29
+ def restore_annotations
30
+ return if @original_annotations_value.nil?
31
+
32
+ ActionView::Base.annotate_rendered_view_with_filenames = @original_annotations_value
33
+ @original_annotations_value = nil
34
+ end
35
+
36
+ def handle_partial_prefixes
37
+ return unless disable_partial_prefixes && ActionView::Base.respond_to?(:prefix_partial_path_with_controller_namespace)
38
+
39
+ @original_partial_prefix_value = ActionView::Base.prefix_partial_path_with_controller_namespace
40
+ ActionView::Base.prefix_partial_path_with_controller_namespace = false
41
+ end
42
+
43
+ def restore_partial_prefixes
44
+ return if @original_partial_prefix_value.nil?
45
+
46
+ ActionView::Base.prefix_partial_path_with_controller_namespace = @original_partial_prefix_value
47
+ @original_partial_prefix_value = nil
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "2.2.2"
2
+ VERSION = "2.3.0"
3
3
  end