lookbook 1.5.1 → 1.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: 11cae6b11c0235c9c609462d70782b48f95e8f33a654296cabbf4e081cab4c27
4
- data.tar.gz: df711457ea8f7c7b2ea8956cf621130bf508b539c17563efc0d40592161430e5
3
+ metadata.gz: 7f540f127ea326803394a4fb256d8ec3f27a9f7564f003d075b5e3b70ccd0ff2
4
+ data.tar.gz: 7987f3e5caaeb9cc8ebd3e0a38fc3b2735ba3c894207320b612e15075441ac5e
5
5
  SHA512:
6
- metadata.gz: e0adbfc0d81f98a8876c3e5b5325808c4b3120c702fe2a4b85af3d4599cffaf869bb0b5ba453685c2f31b6b1a1080750bdc77da9c4a9d0d940187aa9f6846490
7
- data.tar.gz: cc581f238ea0f3fc00108350a6ab7657cd41a1ee9ea0f946a91a2d0baf86f11dcd532ca0bbdc6fe1a3f67e275e9f9c976be4bcb0a6726555391e34576fc00fdc
6
+ metadata.gz: 4984fbeb06a7ba811cb45a0253fb9391f238c1fbe48e8cb4d2f8b32166e5551c08a9df6116b737423af6ecdd90d13bd91317189d962fc174b32e16b848f21f26
7
+ data.tar.gz: aadc14cb2bc965a03fbed65fb6824b898449567fc09574974dd4edde3c317fe52ef5ba989b9039f291a34c6ad0673471f22c9b2ce5869567a3e684d78fbdfbbe
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <br>
2
- <img src=".github/assets/lookbook_logo.svg" width="180">
2
+ <img alt="Lookbook Logo" src=".github/assets/lookbook_logo.svg" width="180">
3
3
 
4
4
  A tool to help browse, develop, test & document [ViewComponents](https://viewcomponent.org/) in Ruby on Rails apps.
5
5
 
@@ -25,7 +25,7 @@ A tool to help browse, develop, test & document [ViewComponents](https://viewcom
25
25
 
26
26
  ## Development
27
27
 
28
- Lookbook is implemented as an isolated [Rails Engine](https://guides.rubyonrails.org/engines.html) and uses [ViewComponent](https://viewcomponent.org), [Tailwind](https://tailwindcss.com/) and [Alpine](https://alpinejs.dev/) for it's UI.
28
+ Lookbook is implemented as an isolated [Rails Engine](https://guides.rubyonrails.org/engines.html) and uses [ViewComponent](https://viewcomponent.org), [Tailwind](https://tailwindcss.com/) and [Alpine](https://alpinejs.dev/) for its UI.
29
29
 
30
30
  This repository contains:
31
31
 
@@ -78,9 +78,9 @@ Lookbook was created by [Mark Perkins](https://github.com/allmarkedup) and conti
78
78
  <br>
79
79
  <br>
80
80
  <a href="https://github.com/ViewComponent/lookbook/graphs/contributors">
81
- <img src="https://contrib.rocks/image?repo=ViewComponent/lookbook&columns=14" width="800" />
81
+ <img alt="Lookbook contributors" src="https://contrib.rocks/image?repo=ViewComponent/lookbook&columns=14" width="800" />
82
82
  </a>
83
83
 
84
84
  ## License
85
85
 
86
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -44,14 +44,15 @@ module Lookbook
44
44
  display_params = SearchParamParser.call(params[:_display])
45
45
  display_params.each do |name, value|
46
46
  if @dynamic_display_options.key?(name)
47
- cookies["lookbook-display-#{name}"] = value
47
+ cookies["lookbook-display-#{name}"] = value.is_a?(Array) ? value[1] : value
48
48
  end
49
49
  end
50
50
  end
51
51
 
52
52
  @dynamic_display_options.each do |name, opts|
53
53
  choices = opts.is_a?(Hash) ? opts[:choices].to_a : opts
54
- @static_display_options[name] ||= cookies.fetch("lookbook-display-#{name}", choices.first)
54
+ value = choices.first.is_a?(Array) ? choices.first[1] : choices.first
55
+ @static_display_options[name] ||= cookies.fetch("lookbook-display-#{name}", value)
55
56
  end
56
57
 
57
58
  unless params[:_display]
@@ -3,6 +3,8 @@ module Lookbook
3
3
  include TargetableConcern
4
4
  include WithPreviewControllerConcern
5
5
 
6
+ before_action { response.headers.delete("X-Frame-Options") }
7
+
6
8
  layout "lookbook/inspector"
7
9
  helper Lookbook::PreviewHelper
8
10
 
@@ -18,10 +20,15 @@ module Lookbook
18
20
  {
19
21
  name: preview.name,
20
22
  examples: preview.examples.map { |example|
21
- {
22
- inspect_path: example.url_path,
23
- name: example.name
24
- }
23
+ case example
24
+ when Lookbook::PreviewExample
25
+ example_json(example)
26
+ when Lookbook::PreviewGroup
27
+ {
28
+ name: example.name,
29
+ examples: example.examples.map { |ex| example_json(ex) }
30
+ }
31
+ end
25
32
  }
26
33
  }
27
34
  end
@@ -48,5 +55,16 @@ module Lookbook
48
55
  show_404 layout: "lookbook/standalone"
49
56
  end
50
57
  end
58
+
59
+ private
60
+
61
+ def example_json(example)
62
+ {
63
+ inspect_path: example.url_path,
64
+ name: example.name,
65
+ preview_path: example.preview_path,
66
+ lookup_path: example.lookup_path
67
+ }
68
+ end
51
69
  end
52
70
  end
@@ -13,7 +13,7 @@
13
13
  }",
14
14
  "@click.outside": "closeMobileSidebar",
15
15
  cloak: true do %>
16
- <% cache do %>
16
+ <% cache Lookbook::Engine.last_changed do %>
17
17
  <%= lookbook_render :split_layout,
18
18
  alpine_data: "$store.layout.#{@pages.any? && @previews.any? ? "sidebar" : "singleSectionSidebar"}",
19
19
  style: "height: calc(100vh - 2.5rem);" do |layout| %>
@@ -2,7 +2,7 @@
2
2
  <%# Render a group of examples %>
3
3
  <% examples.each do |example| %>
4
4
  <div style="margin-bottom: 30px !important; display: block !important;">
5
- <h6 style="all: unset; display: block; color: #999; font-family: sans-serif; font-size: 14px; margin-top: 0; margin-bottom: 10px;">
5
+ <h6 style="all: unset; display: block; color: #555; font-family: sans-serif; font-size: 14px; margin-top: 0; margin-bottom: 10px;">
6
6
  <%= example.label %>
7
7
  </h6>
8
8
  <%= example.output %>
@@ -43,6 +43,7 @@ module Lookbook
43
43
  initializer "lookbook.file_watcher.pages" do
44
44
  file_watcher.watch(opts.page_paths, opts.page_extensions) do |changes|
45
45
  Engine.pages.load(Engine.page_paths)
46
+ Engine.mark_changed
46
47
  Engine.websocket.broadcast(:reload)
47
48
  run_hooks(:after_change, changes)
48
49
  end
@@ -51,6 +52,7 @@ module Lookbook
51
52
  initializer "lookbook.parser.previews_load_callback" do
52
53
  parser.after_parse do |code_objects|
53
54
  Engine.previews.load(code_objects.all(:class))
55
+ Engine.mark_changed
54
56
  Engine.websocket.broadcast(:reload)
55
57
  end
56
58
  end
@@ -168,6 +170,14 @@ module Lookbook
168
170
  @_previews ||= PreviewCollection.new
169
171
  end
170
172
 
173
+ def mark_changed
174
+ @_last_changed = nil
175
+ end
176
+
177
+ def last_changed
178
+ @_last_changed ||= (Time.now.to_f * 1000).to_i
179
+ end
180
+
171
181
  attr_reader :preview_controller
172
182
  end
173
183
 
@@ -57,6 +57,10 @@ module Lookbook
57
57
  lookbook_inspect_path(path)
58
58
  end
59
59
 
60
+ def preview_path
61
+ lookbook_preview_path(path)
62
+ end
63
+
60
64
  def type
61
65
  :example
62
66
  end
@@ -39,6 +39,10 @@ module Lookbook
39
39
  lookbook_inspect_path(path)
40
40
  end
41
41
 
42
+ def preview_path
43
+ lookbook_preview_path(path)
44
+ end
45
+
42
46
  def type
43
47
  :group
44
48
  end
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.3"
3
3
  end