lookbook 2.2.2 → 2.3.1

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: 351a34443300be5a8f4a3f1125a915f6e831f1dfb32a3a24515a64d07ef7cbba
4
+ data.tar.gz: 6394415689d62a66ee39c4715471389a82cdc8116b84c2c0f971fba2813855a0
5
5
  SHA512:
6
- metadata.gz: e1cd96f2564bd3c4dbb3b4343f31505006403b5260ab47ede3dafb4514d40b406d6c25d6702323a69b36bd8af951b72918a55c04c1cb0c28473802cf169dd22f
7
- data.tar.gz: 99650923f94a8e6c9e1bce12c0f292adabcfc0ffde22cc0cf881689d6171aacb14c34f9bb16e6b05b63aa32240802e52809a79ccfd990c9875c8744d99daa18c
6
+ metadata.gz: 96cea87def8290537ecf96d5fee445e840e17c54800e1cbd1e9880abdbf6c44aa5c2f52f5e5f9911baec3e7c14c0b7480de89f0a0d3b7763baec5cb166e08225
7
+ data.tar.gz: 83cee3bec9ab9d4895c5da7ec8d82c5c674275964dbac2117c36d977403cdf70c86d9e0f53b2146ae73f1ca2bb8bf1e7368a9ac87157226d25439419e03ebb41
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <p><strong><a href="https://lookbook.build">Documentation</a> &nbsp;|&nbsp; <a href="http://demo.lookbook.build/lookbook">Demo site</a></strong></p>
8
8
 
9
9
  <p><a href="https://rubygems.org/gems/lookbook"><img src="https://img.shields.io/gem/v/lookbook" alt="Gem version"></a>
10
- <a href="https://github.com/ViewComponent/lookbook/actions/workflows/ci.yml"><img src="https://github.com/ViewComponent/lookbook/actions/workflows/ci.yml/badge.svg" alt="CI status"></a></p>
10
+ <a href="https://github.com/lookbook-hq/lookbook/actions/workflows/ci.yml"><img src="https://github.com/lookbook-hq/lookbook/actions/workflows/ci.yml/badge.svg" alt="CI status"></a></p>
11
11
 
12
12
  </div>
13
13
 
@@ -32,9 +32,9 @@ Lookbook is implemented as an isolated [Rails Engine](https://guides.rubyonrails
32
32
 
33
33
  This repository contains:
34
34
 
35
- * The Lookbook source code ([`/app`](https://github.com/ViewComponent/lookbook/tree/main/app), [`/lib`](https://github.com/ViewComponent/lookbook/tree/main/lib), [`/config`](https://github.com/ViewComponent/lookbook/tree/main/config), etc)
36
- * The Lookbook [documentation site](#docs-site) source code and content ([`/docs`](https://github.com/ViewComponent/lookbook/tree/main/docs)).
37
- * A [test suite](#testing) with a 'runable' dummy app ([`/spec`](https://github.com/ViewComponent/lookbook/tree/main/spec)).
35
+ * The Lookbook source code ([`/app`](https://github.com/lookbook-hq/lookbook/tree/main/app), [`/lib`](https://github.com/lookbook-hq/lookbook/tree/main/lib), [`/config`](https://github.com/lookbook-hq/lookbook/tree/main/config), etc)
36
+ * The Lookbook [documentation site](#docs-site) source code and content ([`/docs`](https://github.com/lookbook-hq/lookbook/tree/main/docs)).
37
+ * A [test suite](#testing) with a 'runable' dummy app ([`/spec`](https://github.com/lookbook-hq/lookbook/tree/main/spec)).
38
38
 
39
39
  ### Documentation site
40
40
 
@@ -61,22 +61,22 @@ Lookbook uses [Release It!](https://github.com/release-it/release-it) to automat
61
61
 
62
62
  Running `npm run release` will start the process of publishing a new release and walks though all the steps from picking a version number to publishing the updated gem.
63
63
 
64
- Publishing a release requires write permissions for this repository (ViewComponent/lookbook) and 2FA publish permissions for Lookbook on RubyGems.
64
+ Publishing a release requires write permissions for this repository (lookbook-hq/lookbook) and 2FA publish permissions for Lookbook on RubyGems.
65
65
 
66
66
  ## Contributing
67
67
 
68
68
  Lookbook is an un-funded open source project and contributions of all types and sizes are most welcome!
69
69
 
70
- Please take the time to read over the [Contributing](./CONTRIBUTING.md) guide before making your first contribution and if anything isn't clear then [start a discussion](https://github.com/ViewComponent/lookbook/discussions) and we will do our best to help you out.
70
+ Please take the time to read over the [Contributing](./CONTRIBUTING.md) guide before making your first contribution and if anything isn't clear then [start a discussion](https://github.com/lookbook-hq/lookbook/discussions) and we will do our best to help you out.
71
71
 
72
72
  ## Contributors
73
73
 
74
74
  Lookbook was created by [Mark Perkins](https://github.com/allmarkedup) and continues to grow
75
- &amp; improve thanks to the ideas, suggestions and hard work of all of [these excellent humans](https://github.com/ViewComponent/lookbook/graphs/contributors):
75
+ &amp; improve thanks to the ideas, suggestions and hard work of all of [these excellent humans](https://github.com/lookbook-hq/lookbook/graphs/contributors):
76
76
  <br>
77
77
  <br>
78
- <a href="https://github.com/ViewComponent/lookbook/graphs/contributors">
79
- <img src="https://contrib.rocks/image?repo=ViewComponent/lookbook&columns=14" width="800" />
78
+ <a href="https://github.com/lookbook-hq/lookbook/graphs/contributors">
79
+ <img src="https://contrib.rocks/image?repo=lookbook-hq/lookbook&columns=14" width="800" />
80
80
  </a>
81
81
 
82
82
  ## License
@@ -34,7 +34,7 @@
34
34
  <% menu = lookbook_render :debug_menu,
35
35
  version: Lookbook::VERSION,
36
36
  docs_url: "https://lookbook.build/guide",
37
- repo_url: "https://github.com/ViewComponent/lookbook" do %>
37
+ repo_url: "https://github.com/lookbook-hq/lookbook" do %>
38
38
  <%= debug_data %>
39
39
  <% end %>
40
40
  <% button.with_dropdown.with_content(menu) %>
@@ -1,3 +1,5 @@
1
1
  <%= render_component_tag :i, style: "height: #{size_rems}; width: #{size_rems}; #{@html_attrs[:style]}", class: "icon-stroke-#{stroke}" do %>
2
- <%= svg %>
3
- <% end %>
2
+ <svg>
3
+ <use href="/lookbook-assets/img/lucide-sprite.svg#<%= @icon_name %>"></use>
4
+ </svg>
5
+ <% end %>
@@ -14,21 +14,5 @@ module Lookbook
14
14
  def size_rems
15
15
  "#{@size * 0.25}rem"
16
16
  end
17
-
18
- def svg
19
- ICON_CACHE[@icon_name] ||= read_svg
20
- end
21
-
22
- def read_svg
23
- File.read(svg_path).html_safe
24
- rescue
25
- if Rails.env.development? || Rails.env.test?
26
- raise "`#{@icon_name}` is not a valid icon name"
27
- end
28
- end
29
-
30
- def svg_path
31
- Lookbook::Engine.root.join("assets/icons/#{@icon_name}.svg")
32
- end
33
17
  end
34
18
  end
@@ -2,7 +2,10 @@
2
2
  id: id,
3
3
  key: "#{id}-entity-#{type}",
4
4
  class: "list-none",
5
+ "x-init": "$nextTick(() => checkActive())",
5
6
  "x-show": "!filteredOut",
7
+ "@navigation:complete.window": "checkActive",
8
+ # "x-effect": "active = ($refs.link && (window.location.pathname === $refs.link.getAttribute('href')))",
6
9
  data: { "entity-type": type.to_s.tr("_","-") },
7
10
  cloak: true do %>
8
11
  <%= lookbook_tag href.present? ? :a : :button,
@@ -6,20 +6,12 @@ export default function navItemComponent({ id, matchers }) {
6
6
  return {
7
7
  filteredOut: false,
8
8
 
9
+ active: false,
10
+
9
11
  get open() {
10
12
  return this.isCollection && this.isOpen(id);
11
13
  },
12
14
 
13
- get active() {
14
- if (this.$refs.link) {
15
- return (
16
- this.location &&
17
- this.location.pathname === this.$refs.link.getAttribute("href")
18
- );
19
- }
20
- return false;
21
- },
22
-
23
15
  get children() {
24
16
  return this.$refs.items ? Array.from(this.$refs.items.children) : [];
25
17
  },
@@ -28,6 +20,12 @@ export default function navItemComponent({ id, matchers }) {
28
20
  return !this.$refs.link;
29
21
  },
30
22
 
23
+ checkActive() {
24
+ this.active =
25
+ this.$refs.link &&
26
+ window.location.pathname === this.$refs.link.getAttribute("href");
27
+ },
28
+
31
29
  toggle() {
32
30
  this.toggleOpen(id);
33
31
  },
@@ -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,
@@ -13,5 +13,15 @@ module Lookbook
13
13
  lookbook_home_path
14
14
  end
15
15
  end
16
+
17
+ # Requests
18
+
19
+ def request_frame
20
+ request.headers["X-Lookbook-Frame"] || "root"
21
+ end
22
+
23
+ def frame_request?
24
+ request.headers["X-Lookbook-Frame"].present?
25
+ end
16
26
  end
17
27
  end
@@ -1,88 +1,90 @@
1
1
  <% content_for :body do %>
2
- <div
3
- id="app"
4
- x-data="app"
5
- x-cloak
6
- x-on:popstate.window="handleNavigation"
7
- x-on:click.document="hijax"
8
- x-on:navigation:start="closeMobileSidebar"
9
- x-on:dom:update-complete.window="Lookbook.initEmbeds()"
10
- class="w-screen h-screen grid grid-rows-[40px_1fr] relative">
2
+ <% if request_frame == "root" %>
3
+ <div
4
+ id="app"
5
+ x-data="app"
6
+ x-cloak
7
+ x-on:popstate.window="handleNavigation"
8
+ x-on:click.document="hijax"
9
+ x-on:navigation:start="closeMobileSidebar"
10
+ x-on:dom:update-complete.window="Lookbook.initEmbeds()"
11
+ class="w-screen h-screen grid grid-rows-[40px_1fr] relative">
11
12
 
12
- <%= render "lookbook/partials/user_styles" %>
13
+ <%= render "lookbook/partials/user_styles" %>
13
14
 
14
- <%= lookbook_render :header,
15
- id: "app-header",
16
- debug_menu: @config.debug_menu,
17
- project_name: @config.project_name,
18
- project_logo: @config.project_logo %>
15
+ <%= lookbook_render :header,
16
+ id: "app-header",
17
+ debug_menu: @config.debug_menu,
18
+ project_name: @config.project_name,
19
+ project_logo: @config.project_logo %>
19
20
 
20
- <% unless @blank_slate %>
21
-
22
- <%= lookbook_render :split_layout,
23
- alpine_data: "$store.layout.main",
24
- ":class": "$store.layout.mobile && '!block'" do |layout| %>
21
+ <% unless @blank_slate %>
22
+
23
+ <%= lookbook_render :split_layout,
24
+ alpine_data: "$store.layout.main",
25
+ ":class": "$store.layout.mobile && '!block'" do |layout| %>
25
26
 
26
- <% layout.with_pane id: "app-sidebar", class: "flex flex-col bg-lookbook-sidebar-bg relative translate-x-0",
27
- ":class": "{
28
- 'transition': $store.layout.mobile,
29
- 'translate-x-full': $store.layout.mobile && sidebarHidden,
30
- '!absolute right-0 bottom-0 top-[40px] h-[calc(100%_-_40px)] w-full max-w-[420px] z-[1001] border-l border-lookbook-divider': $store.layout.mobile
31
- }",
32
- "x-on:click.outside": "closeMobileSidebar",
33
- cloak: true do %>
27
+ <% layout.with_pane id: "app-sidebar", class: "flex flex-col bg-lookbook-sidebar-bg relative translate-x-0",
28
+ ":class": "{
29
+ 'transition': $store.layout.mobile,
30
+ 'translate-x-full': $store.layout.mobile && sidebarHidden,
31
+ '!absolute right-0 bottom-0 top-[40px] h-[calc(100%_-_40px)] w-full max-w-[420px] z-[1001] border-l border-lookbook-divider': $store.layout.mobile
32
+ }",
33
+ "x-on:click.outside": "closeMobileSidebar",
34
+ cloak: true do %>
34
35
 
35
- <% if @sidebar_panels.any? %>
36
- <%= lookbook_render :split_layout,
37
- alpine_data: "$store.layout.#{@sidebar_panels.many? ? "sidebar" : "singleSectionSidebar"}",
38
- style: "height: calc(100vh - 2.5rem);" do |layout| %>
36
+ <% if @sidebar_panels.any? %>
37
+ <%= lookbook_render :split_layout,
38
+ alpine_data: "$store.layout.#{@sidebar_panels.many? ? "sidebar" : "singleSectionSidebar"}",
39
+ style: "height: calc(100vh - 2.5rem);" do |layout| %>
39
40
 
40
- <% @sidebar_panels.each do |panel| %>
41
- <% if panel == :previews && @previews.any? %>
42
- <% layout.with_pane class: "overflow-hidden" do %>
43
- <%= lookbook_render :nav,
44
- id: "previews-nav",
45
- tree: @previews.to_tree,
46
- alpine_data: "$store.nav.previews" do |nav| %>
47
- <%= nav.with_toolbar do |toolbar| %>
48
- <% toolbar.with_section padded: true do %>
49
- <h4 class="pt-1"><%= @config.preview_collection_label %></h4>
50
- <% end %>
51
- <% toolbar.with_section align: :right, padded: false do %>
52
- <%= lookbook_render :button_group, size: :xs do |group| %>
53
- <% group.with_button icon: :minus_square,
54
- tooltip: "Collapse all",
55
- "x-on:click": "closeAll" %>
41
+ <% @sidebar_panels.each do |panel| %>
42
+ <% if panel == :previews && @previews.any? %>
43
+ <% layout.with_pane class: "overflow-hidden" do %>
44
+ <%= lookbook_render :nav,
45
+ id: "previews-nav",
46
+ tree: @previews.to_tree,
47
+ alpine_data: "$store.nav.previews" do |nav| %>
48
+ <%= nav.with_toolbar do |toolbar| %>
49
+ <% toolbar.with_section padded: true do %>
50
+ <h4 class="pt-1"><%= @config.preview_collection_label %></h4>
51
+ <% end %>
52
+ <% toolbar.with_section align: :right, padded: false do %>
53
+ <%= lookbook_render :button_group, size: :xs do |group| %>
54
+ <% group.with_button icon: :minus_square,
55
+ tooltip: "Collapse all",
56
+ "x-on:click": "closeAll" %>
57
+ <% end %>
56
58
  <% end %>
57
59
  <% end %>
58
- <% end %>
59
- <% if @config.preview_nav_filter %>
60
- <% nav.with_filter store: "$store.nav.previews.filter", placeholder: "Filter previews by name&hellip;" %>
60
+ <% if @config.preview_nav_filter %>
61
+ <% nav.with_filter store: "$store.nav.previews.filter", placeholder: "Filter previews by name&hellip;" %>
62
+ <% end %>
61
63
  <% end %>
62
64
  <% end %>
63
65
  <% end %>
64
- <% end %>
65
66
 
66
- <% if panel == :pages && @pages.any? %>
67
- <% layout.with_pane class: "overflow-hidden" do %>
68
- <%= lookbook_render :nav,
69
- id: "pages-nav",
70
- tree: @pages.to_tree,
71
- alpine_data: "$store.nav.pages" do |nav| %>
72
- <%= nav.with_toolbar do |toolbar| %>
73
- <% toolbar.with_section padded: true do %>
74
- <h4 class="pt-1"><%= @config.page_collection_label %></h4>
75
- <% end %>
76
- <% toolbar.with_section align: :right, padded: false do %>
77
- <%= lookbook_render :button_group, size: :xs do |group| %>
78
- <% group.with_button icon: :minus_square,
79
- tooltip: "Collapse all",
80
- "x-on:click": "closeAll" %>
67
+ <% if panel == :pages && @pages.any? %>
68
+ <% layout.with_pane class: "overflow-hidden" do %>
69
+ <%= lookbook_render :nav,
70
+ id: "pages-nav",
71
+ tree: @pages.to_tree,
72
+ alpine_data: "$store.nav.pages" do |nav| %>
73
+ <%= nav.with_toolbar do |toolbar| %>
74
+ <% toolbar.with_section padded: true do %>
75
+ <h4 class="pt-1"><%= @config.page_collection_label %></h4>
76
+ <% end %>
77
+ <% toolbar.with_section align: :right, padded: false do %>
78
+ <%= lookbook_render :button_group, size: :xs do |group| %>
79
+ <% group.with_button icon: :minus_square,
80
+ tooltip: "Collapse all",
81
+ "x-on:click": "closeAll" %>
82
+ <% end %>
81
83
  <% end %>
82
84
  <% end %>
83
- <% end %>
84
- <% if @config.page_nav_filter %>
85
- <% nav.with_filter store: "$store.nav.pages.filter", placeholder: "Filter pages by name&hellip;" %>
85
+ <% if @config.page_nav_filter %>
86
+ <% nav.with_filter store: "$store.nav.pages.filter", placeholder: "Filter pages by name&hellip;" %>
87
+ <% end %>
86
88
  <% end %>
87
89
  <% end %>
88
90
  <% end %>
@@ -90,26 +92,35 @@
90
92
  <% end %>
91
93
  <% end %>
92
94
  <% end %>
93
- <% end %>
94
95
 
95
- <% layout.with_pane id: "app-main", class: "overflow-hidden h-full", ":class": "$store.layout.mobile && 'w-screen'" do %>
96
- <%= content_for?(:main) ? yield(:main) : yield %>
96
+ <% layout.with_pane id: "app-main", class: "overflow-hidden h-full", ":class": "$store.layout.mobile && 'w-screen'" do %>
97
+ <%= content_for?(:main) ? yield(:main) : yield %>
98
+ <% end %>
97
99
  <% end %>
100
+ <% else %>
101
+ <div id="app-main" class="w-screen h-full overflow-hidden">
102
+ <%= content_for?(:main) ? yield(:main) : yield %>
103
+ </div>
98
104
  <% end %>
99
- <% else %>
100
- <div id="app-main" class="w-screen h-full overflow-hidden">
101
- <%= content_for?(:main) ? yield(:main) : yield %>
102
- </div>
103
- <% end %>
104
-
105
- <div class="absolute opacity-0 bg-black inset-0 top-[39px] z-[-1] transition-opacity" x-bind:class="($store.layout.mobile && !sidebarHidden) && '!opacity-30 !z-[1000]'" data-cloak></div>
105
+
106
+ <div class="absolute opacity-0 bg-black inset-0 top-[39px] z-[-1] transition-opacity" x-bind:class="($store.layout.mobile && !sidebarHidden) && '!opacity-30 !z-[1000]'" data-cloak></div>
107
+
108
+ <% if content_for? :dropdowns %>
109
+ <div class="hidden">
110
+ <%= content_for :dropdowns -%>
111
+ </div>
112
+ <% end %>
113
+ </div>
114
+ <% elsif request_frame == "main" %>
115
+ <div id="app-main">
116
+ <%= content_for?(:main) ? yield(:main) : yield %>
117
+ </div>
118
+ <% end %>
119
+ <% end %>
106
120
 
107
- <% if content_for? :dropdowns %>
108
- <div class="hidden">
109
- <%= content_for :dropdowns -%>
110
- </div>
111
- <% end %>
112
- </div>
121
+ <% if frame_request? %>
122
+ <%= yield :body %>
123
+ <% else %>
124
+ <%= render template: "layouts/lookbook/skeleton" %>
113
125
  <% end %>
114
126
 
115
- <%= render template: "layouts/lookbook/skeleton" %>
@@ -1,22 +1,34 @@
1
1
  <% content_for :body do %>
2
- <div
3
- id="app"
4
- x-data="app"
5
- x-cloak
6
- x-on:popstate.window="handleNavigation"
7
- x-on:click.document="hijax"
8
- class="overflow-hidden">
9
-
10
- <%= render "lookbook/partials/user_styles" %>
2
+ <% if request_frame == "root" %>
3
+ <div
4
+ id="app"
5
+ x-data="app"
6
+ x-cloak
7
+ x-on:popstate.window="handleNavigation"
8
+ x-on:click.document="hijax"
9
+ class="overflow-hidden">
10
+
11
+ <%= render "lookbook/partials/user_styles" %>
11
12
 
12
- <%= content_for?(:main) ? yield(:main) : yield %>
13
- </div>
14
-
15
- <% if content_for? :dropdowns %>
16
- <div class="hidden">
17
- <%= content_for :dropdowns -%>
13
+ <div id="app-main" class="contents">
14
+ <%= content_for?(:main) ? yield(:main) : yield %>
15
+ </div>
18
16
  </div>
19
- <% end %>
17
+
18
+ <% if content_for? :dropdowns %>
19
+ <div class="hidden">
20
+ <%= content_for :dropdowns -%>
21
+ </div>
22
+ <% end %>
23
+ <% elsif request_frame == "main" %>
24
+ <div id="app-main">
25
+ <%= content_for?(:main) ? yield(:main) : yield %>
26
+ </div>
27
+ <% end %>
20
28
  <% end %>
21
29
 
22
- <%= render template: "layouts/lookbook/skeleton" %>
30
+ <% if frame_request? %>
31
+ <%= yield :body %>
32
+ <% else %>
33
+ <%= render template: "layouts/lookbook/skeleton" %>
34
+ <% end %>
data/assets/js/app.js CHANGED
@@ -43,7 +43,9 @@ export default function app() {
43
43
  this.debug("Navigating to ", window.location.pathname);
44
44
  this.$dispatch("navigation:start");
45
45
  this.location = window.location;
46
- await this.updateDOM();
46
+ await this.updateDOM("#app-main", {
47
+ headers: { "X-Lookbook-Frame": "main" },
48
+ });
47
49
  this.$dispatch("navigation:complete");
48
50
  },
49
51
 
@@ -65,16 +67,17 @@ export default function app() {
65
67
  }
66
68
  },
67
69
 
68
- async updateDOM() {
70
+ async updateDOM(rootSelector = `#${this.$root.id}`, options = {}) {
69
71
  this.debug("Starting DOM update");
70
72
  this.$dispatch("dom:update-start");
71
73
  this.requestStart();
72
74
  try {
73
75
  const { fragment, title } = await fetchHTML(
74
76
  window.location,
75
- `#${this.$root.id}`
77
+ rootSelector,
78
+ options
76
79
  );
77
- morph(this.$root, fragment);
80
+ morph(document.querySelector(rootSelector), fragment);
78
81
  document.title = title;
79
82
  this.requestEnd();
80
83
  this.$dispatch("dom:update-complete");
@@ -1,5 +1,5 @@
1
- async function fetchHTML(url, selector) {
2
- const response = await fetch(url || window.document.location);
1
+ async function fetchHTML(url, selector, options = {}) {
2
+ const response = await fetch(url || window.document.location, options);
3
3
  const html = await response.text();
4
4
  const doc = new DOMParser().parseFromString(html, "text/html");
5
5
  return {
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
@@ -66,7 +67,7 @@ shared:
66
67
  links:
67
68
  docs: https://v2.lookbook.build
68
69
  demo: https://v2-demo.lookbook.build
69
- repo: https://github.com/ViewComponent/lookbook/tree/v2
70
+ repo: https://github.com/lookbook-hq/lookbook/tree/v2
70
71
 
71
72
  development:
72
73
  debug_menu: true
@@ -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.1"
3
3
  end