lookbook 1.0.4 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd24f301fb1e05131ba58a2d236b15155f38b372c52ada4823ea6f76111dc0b1
4
- data.tar.gz: 8675198f147aa93461a89964ad2b28461facdd672088b3edfe0880ea1b293545
3
+ metadata.gz: 2985b373024d4f48a503252274dc0606cfbb062ea2d229163c62980f9ff492b7
4
+ data.tar.gz: 60352ee8d3599fe86b8fe7dc068f391913ed4727bf2b500f605fe8b49ad7dbc0
5
5
  SHA512:
6
- metadata.gz: 5a9e80161cf8880083c2138144304dfc5427478c8114073f9409e3fb883eddf9abe7e055aea33b16625316c15be15fd139b8ab3607d808ff90419b5ad95b4eab
7
- data.tar.gz: 1e1836fdad458167f63e3736d3d99107b1a0346da530fe57f9be03eb188c029d5891c8534999475673aa78fd02c645c37edb181b5960165316172bcf5cded59b
6
+ metadata.gz: f962058591eba3fd20629d4cff57515f4931b754091af6112ddcca16a911945640dbc556031edcfb34b780aa7f0690c40d32a811077ff0bb91c3f42f143ff8e2
7
+ data.tar.gz: b5d4d2d49675b4389bc1bb4814559eaf01e4445e0c2623a796a8a82d27ccdfeacd742837e3022c027fd2d5b22bb02a99b0720a321f6b9151145fd3f16266cbd4
@@ -11,6 +11,7 @@ export default function app() {
11
11
 
12
12
  init() {
13
13
  if (window.SOCKET_PATH) {
14
+ console.log("SOCKET CREATED");
14
15
  const socket = createSocket(window.SOCKET_PATH);
15
16
  socket.addListener("Lookbook::ReloadChannel", () => this.updateDOM());
16
17
  }
@@ -1,5 +1,5 @@
1
1
  import { createConsumer } from "@rails/actioncable";
2
- import debounce from "debounce";
2
+ import { debounce } from "throttle-debounce";
3
3
  import { log } from "../plugins/logger";
4
4
 
5
5
  export default function socket(endpoint) {
@@ -8,10 +8,14 @@ export default function socket(endpoint) {
8
8
  return {
9
9
  addListener(channel, callback) {
10
10
  consumer.subscriptions.create(channel, {
11
- received: debounce((data) => {
12
- log.debug("Lookbook files changed");
13
- callback(data);
14
- }, 200),
11
+ received: debounce(
12
+ 200,
13
+ (data) => {
14
+ log.debug("Lookbook files changed");
15
+ callback(data);
16
+ },
17
+ { atBegin: true }
18
+ ),
15
19
  connected() {
16
20
  log.info("Lookbook websocket connected");
17
21
  },
@@ -11,7 +11,7 @@
11
11
  </div>
12
12
  <% end %>
13
13
 
14
- <div class="overflow-auto">
14
+ <div class="overflow-auto h-full">
15
15
  <% if items.any? %>
16
16
  <ul class="py-2" x-ref="items" x-show="!empty" x-cloak>
17
17
  <%= safe_join(items) %>
@@ -1,4 +1,4 @@
1
- import debounce from "debounce";
1
+ import { debounce } from "throttle-debounce";
2
2
  import tippy from "~/app/assets/lookbook/js/lib/tippy";
3
3
  import { observeSize } from "@helpers/layout";
4
4
  import { getElementSize } from "@helpers/dom";
@@ -49,7 +49,7 @@ export default function tabsComponent(store) {
49
49
 
50
50
  this.parentObserver = observeSize(
51
51
  this.$root.parentElement,
52
- debounce(this.handleResize.bind(this), 10)
52
+ debounce(10, this.handleResize.bind(this))
53
53
  );
54
54
 
55
55
  this.$watch("visibleTabsCount", (value) => {
@@ -1,6 +1,9 @@
1
1
  module Lookbook
2
2
  class ApplicationController < ActionController::Base
3
- content_security_policy false, if: -> { Rails.env.development? }
3
+ if respond_to?(:content_security_policy)
4
+ content_security_policy false, if: -> { Rails.env.development? }
5
+ end
6
+
4
7
  protect_from_forgery with: :exception
5
8
 
6
9
  helper Lookbook::ApplicationHelper
@@ -8,6 +11,7 @@ module Lookbook
8
11
  helper Lookbook::ComponentHelper
9
12
 
10
13
  before_action :generate_theme_overrides
14
+ before_action :assign_collections
11
15
 
12
16
  def self.controller_path
13
17
  "lookbook"
@@ -28,6 +32,11 @@ module Lookbook
28
32
  @theme_overrides ||= Lookbook.theme.to_css
29
33
  end
30
34
 
35
+ def assign_collections
36
+ @previews = Preview.all
37
+ @pages = Page.all
38
+ end
39
+
31
40
  def feature_enabled?(feature)
32
41
  Lookbook::Features.enabled?(feature)
33
42
  end
@@ -18,7 +18,6 @@ module Lookbook
18
18
  end
19
19
 
20
20
  def show
21
- @pages = Lookbook.pages
22
21
  @page = @pages.find_by_path(params[:path])
23
22
  if @page
24
23
  @next_page = @pages.find_next(@page)
@@ -158,22 +158,25 @@ module Lookbook
158
158
 
159
159
  def panels
160
160
  return @panels if @panels.present?
161
- @panels = []
162
- Lookbook.config.inspector_panels.each do |name, config|
161
+ inspector_data_hash = inspector_data.to_h
162
+ panel_counts = {}
163
+
164
+ @panels = Lookbook.config.inspector_panels.map do |name, config|
163
165
  config_with_defaults = Lookbook.config.inspector_panel_defaults.merge(config)
166
+ panel_counts[config_with_defaults[:pane].to_sym] ||= 0
167
+ panel_counts[config_with_defaults[:pane].to_sym] += 1
164
168
 
165
169
  callable_data = {
166
170
  name: name.to_s,
167
- index_position: (@panels.count { |p| p.pane == config.pane } + 1),
168
- **inspector_data
171
+ index_position: panel_counts[config_with_defaults[:pane].to_sym],
172
+ **inspector_data_hash
169
173
  }
170
174
 
171
175
  resolved_config = config_with_defaults.transform_values do |value|
172
176
  value.instance_of?(Proc) ? value.call(Lookbook::Store.new(callable_data)) : value
173
177
  end
174
178
  resolved_config[:name] = name.to_s
175
-
176
- @panels << Lookbook::Store.new(resolved_config, deep: false)
179
+ Store.new(resolved_config)
177
180
  end
178
181
 
179
182
  @panels = @panels.select(&:show).sort_by { |p| [p.position, p.label] }
@@ -7,7 +7,7 @@ module Lookbook
7
7
  end
8
8
 
9
9
  def code(language = :html, **attrs, &block)
10
- attrs[:language] = language
10
+ attrs[:language] ||= language
11
11
  render Lookbook::Code::Component.new(**attrs), &block
12
12
  end
13
13
 
@@ -1,5 +1,5 @@
1
1
  <% content_for :shell do %>
2
- <% if Lookbook.previews? || Lookbook.pages? %>
2
+ <% if @previews.any? || @pages.any? %>
3
3
  <%= render_component :split_layout,
4
4
  alpine_data: "$store.layout.main",
5
5
  ":class": "$store.layout.mobile && '!block'" do |layout| %>
@@ -14,14 +14,14 @@
14
14
  cloak: true do %>
15
15
 
16
16
  <%= render_component :split_layout,
17
- alpine_data: "$store.layout.#{Lookbook.pages? && Lookbook.previews? ? "sidebar" : "singleSectionSidebar"}",
17
+ alpine_data: "$store.layout.#{@pages.any? && @previews.any? ? "sidebar" : "singleSectionSidebar"}",
18
18
  style: "height: calc(100vh - 2.5rem);" do |layout| %>
19
19
 
20
- <% if Lookbook.previews? %>
20
+ <% if @previews.any? %>
21
21
  <% layout.pane class: "overflow-hidden" do %>
22
22
  <%= render_component :nav,
23
23
  id: "previews-nav",
24
- collection: Lookbook.previews,
24
+ collection: @previews,
25
25
  alpine_data: "$store.nav.previews",
26
26
  collapse_singles: true do |nav| %>
27
27
  <%= nav.toolbar do |toolbar| %>
@@ -34,11 +34,11 @@
34
34
  <% end %>
35
35
  <% end %>
36
36
 
37
- <% if Lookbook.pages? %>
37
+ <% if @pages.any? %>
38
38
  <% layout.pane class: "overflow-hidden" do %>
39
39
  <%= render_component :nav,
40
40
  id: "pages-nav",
41
- collection: Lookbook.pages,
41
+ collection: @pages,
42
42
  alpine_data: "$store.nav.pages" do |nav| %>
43
43
  <%= nav.toolbar do |toolbar| %>
44
44
  <% toolbar.section padded: true do %>
@@ -49,36 +49,6 @@
49
49
  <% end %>
50
50
  <% end %>
51
51
  <% end %>
52
-
53
- <% if Lookbook::Preview.errors.any? %>
54
- <div x-data="{hidden: false}" class="flex-none border-t border-lookbook-divider absolute bottom-0 left-0 right-0" x-show="!hidden">
55
- <%= render_component :toolbar do |toolbar| %>
56
- <% toolbar.section padded: true, class: "flex items-center" do %>
57
- <%= icon :alert_triangle, size: 4, class: "text-red-700" %>
58
- <span class="ml-2">Preview load errors</span>
59
- <% end %>
60
- <% toolbar.section align: :right do %>
61
- <% render_component :button, icon: :x, "@click": "hidden = !hidden" %>
62
- <% end %>
63
- <% end %>
64
-
65
- <div class="h-full max-h-[300px] overflow-hidden">
66
- <div class="bg-red-50 w-full overflow-auto h-full">
67
- <ul class="text-sm divide-y divide-red-200">
68
- <% Lookbook::Preview.errors.each do |error| %>
69
- <% error = error.is_a?(Lookbook::Error) ? error : Lookbook::Error.new(error) %>
70
- <li class="px-4 py-3">
71
- <h4 class="break-all leading-tight text-xs ">
72
- <%= error.file_name %><%= ":#{error.line_number}" if error.line_number %>
73
- </h4>
74
- <pre class="text-red-800 text-xs mt-2 whitespace-pre-wrap opacity-80 font-mono"><%= error.message %></pre>
75
- </li>
76
- <% end %>
77
- </ul>
78
- </div>
79
- </div>
80
- </div>
81
- <% end %>
82
52
  <% end %>
83
53
 
84
54
  <% layout.pane id: "app-main", class: "overflow-hidden h-full", ":class": "$store.layout.mobile && 'w-screen'" do %>
@@ -1,10 +1,10 @@
1
1
  <div id="landing" class="flex flex-col items-center justify-center h-full w-full">
2
- <div class="text-center" id="landing-<%= Lookbook.previews? ? "with" : "no" %>-content">
2
+ <div class="text-center" id="landing-<%= @previews.any? ? "with" : "no" %>-content">
3
3
  <h5 class="text-base text-lookbook-blank-slate-title truncate uppercase font-black tracking-wider mb-2">
4
4
  <%= config.project_name %>
5
5
  </h5>
6
6
  <div class="opacity-60">
7
- <% if Lookbook.previews? %>
7
+ <% if @previews.any? %>
8
8
  <p>Select a preview from the nav to get started.</p>
9
9
  <% else %>
10
10
  <p><a class="underline" href="https://lookbook.build/guide/previews" target="_blank">Create a preview</a> to get started.</p>
@@ -25,7 +25,7 @@
25
25
 
26
26
  <% toolbar.section divide: :left, class: "flex-none relative z-10" do %>
27
27
  <%= render_component :button_group do |group| %>
28
- <% if Lookbook.pages.any? %>
28
+ <% if @pages.any? %>
29
29
  <% group.button icon: :code,
30
30
  tooltip: "Copy page embed code",
31
31
  copy: true do %>
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  Lookbook::Engine.routes.draw do
2
2
  if Lookbook::Engine.websocket?
3
- mount Lookbook::Engine.websocket => Lookbook.config.cable_mount_path
3
+ mount Lookbook::Engine.websocket => Lookbook.config.cable_mount_path, :as => :cable
4
4
  end
5
5
 
6
6
  root to: "application#index", as: :lookbook_home
@@ -5,7 +5,7 @@ require "lookbook/store"
5
5
  module Lookbook
6
6
  class Config
7
7
  def initialize
8
- @options = Store.new
8
+ @options = Store.new({}, true)
9
9
 
10
10
  @options.set({
11
11
  project_name: "Lookbook",
@@ -31,10 +31,9 @@ module Lookbook
31
31
  listen_extensions: ["rb", "html.*"],
32
32
  listen_use_polling: false,
33
33
 
34
- cable_mount_path: "/lookbook-cable",
34
+ cable_mount_path: "/cable",
35
35
  cable_logger: Lookbook.logger,
36
36
 
37
- runtime_parsing: !Rails.env.production?,
38
37
  parser_registry_path: "tmp/storage/.yardoc",
39
38
 
40
39
  ui_theme: "indigo",
@@ -104,6 +103,10 @@ module Lookbook
104
103
  })
105
104
  end
106
105
 
106
+ def runtime_parsing=(value)
107
+ Lookbook.logger.warn "The `runtime_parsing` config option has been deprecated and will be removed in v2.0"
108
+ end
109
+
107
110
  def project_name
108
111
  @options.project_name == false ? nil : @options.project_name
109
112
  end
data/lib/lookbook/data.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module Lookbook
2
2
  module Data
3
3
  def data
4
- @data ||= Store.new
4
+ @data ||= Store.new({}, true)
5
5
  end
6
6
 
7
7
  def data=(props)
8
- @data = Store.new(props)
8
+ @data = Store.new(props, true)
9
9
  end
10
10
  end
11
11
  end
@@ -35,7 +35,7 @@ module Lookbook
35
35
  {
36
36
  version: version,
37
37
  env: Rails.env.to_s,
38
- config: config
38
+ config: config.to_h
39
39
  }
40
40
  end
41
41
 
@@ -43,18 +43,10 @@ module Lookbook
43
43
  Preview.all
44
44
  end
45
45
 
46
- def previews?
47
- Preview.any?
48
- end
49
-
50
46
  def pages
51
47
  Page.all
52
48
  end
53
49
 
54
- def pages?
55
- Page.any?
56
- end
57
-
58
50
  def broadcast(event_name, data = {})
59
51
  Engine.websocket&.broadcast(event_name.to_s, data)
60
52
  end
@@ -99,6 +91,11 @@ module Lookbook
99
91
  @preview_controller = Lookbook.config.preview_controller.constantize
100
92
  @preview_controller.include(Lookbook::PreviewController)
101
93
 
94
+ parser.after_parse do |registry|
95
+ Preview.load!(registry.all(:class))
96
+ reload_ui
97
+ end
98
+
102
99
  if Gem::Version.new(Rails.version) >= Gem::Version.new("6.1.3.1")
103
100
  # Rails.application.server is only available for newer Rails versions
104
101
  Rails.application.server do
@@ -111,19 +108,9 @@ module Lookbook
111
108
  end
112
109
  end
113
110
 
114
- if config.lookbook.runtime_parsing
115
- Lookbook::Engine.parser.parse
116
- else
117
- unless File.exist?(config.lookbook.parser_registry_path)
118
- Lookbook.logger.warn "
119
- Runtime parsing is disabled but no registry file has been found.
120
- Did you run `rake lookbook:preparse` before starting the app?
121
- Expected to find registry file at #{config.lookbook.parser_registry_path}
122
- "
123
- end
111
+ parser.parse do
112
+ Lookbook::Engine.run_hooks(:after_initialize)
124
113
  end
125
-
126
- Lookbook::Engine.run_hooks(:after_initialize)
127
114
  end
128
115
 
129
116
  at_exit do
@@ -140,32 +127,29 @@ module Lookbook
140
127
  return unless config.listen == true
141
128
  Listen.logger = Lookbook.logger
142
129
 
143
- preview_listener = Listen.to(
144
- *config.listen_paths,
145
- only: /\.(#{config.listen_extensions.join("|")})$/,
146
- force_polling: config.listen_use_polling
147
- ) do |modified, added, removed|
148
- changes = {modified: modified, added: added, removed: removed}
149
- begin
150
- parser.parse
151
- rescue
130
+ listen_paths = config.listen_paths.uniq
131
+ if listen_paths.any?
132
+ preview_listener = Listen.to(*listen_paths,
133
+ only: /\.(#{config.listen_extensions.join("|")})$/,
134
+ force_polling: config.listen_use_polling) do |modified, added, removed|
135
+ parser.parse do
136
+ run_hooks(:after_change, {modified: modified, added: added, removed: removed})
137
+ end
152
138
  end
153
- Lookbook::Preview.clear_cache
154
- reload_ui(changes)
155
- run_hooks(:after_change, changes)
139
+ register_listener(preview_listener)
156
140
  end
157
- register_listener(preview_listener)
158
-
159
- page_listener = Listen.to(
160
- *config.page_paths,
161
- only: /\.(html.*|md.*)$/,
162
- force_polling: config.listen_use_polling
163
- ) do |modified, added, removed|
164
- changes = {modified: modified, added: added, removed: removed}
165
- reload_ui(changes)
166
- run_hooks(:after_change, changes)
141
+
142
+ page_paths = config.page_paths.uniq
143
+ if page_paths.any?
144
+ page_listener = Listen.to(*page_paths,
145
+ only: /\.(html.*|md.*)$/,
146
+ force_polling: config.listen_use_polling) do |modified, added, removed|
147
+ changes = {modified: modified, added: added, removed: removed}
148
+ reload_ui
149
+ run_hooks(:after_change, changes)
150
+ end
151
+ register_listener(page_listener)
167
152
  end
168
- register_listener(page_listener)
169
153
  end
170
154
 
171
155
  def websocket
@@ -176,7 +160,7 @@ module Lookbook
176
160
 
177
161
  cable = ActionCable::Server::Configuration.new
178
162
  cable.cable = {adapter: "async"}.with_indifferent_access
179
- cable.mount_path = config.cable_mount_path
163
+ cable.mount_path = nil
180
164
  cable.connection_class = -> { Lookbook::Connection }
181
165
  cable.logger = config.cable_logger
182
166
 
@@ -202,7 +186,7 @@ module Lookbook
202
186
  end
203
187
 
204
188
  def parser
205
- @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths, config.lookbook.parser_registry_path)
189
+ @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths)
206
190
  end
207
191
 
208
192
  def log_level
@@ -237,8 +221,8 @@ module Lookbook
237
221
  end
238
222
  end
239
223
 
240
- def reload_ui(changed = {})
241
- websocket&.broadcast("reload", changed)
224
+ def reload_ui
225
+ websocket&.broadcast("reload", {})
242
226
  end
243
227
 
244
228
  def prevent_listening?
@@ -3,24 +3,32 @@ require "yard"
3
3
  module Lookbook
4
4
  class Parser
5
5
  attr_reader :registry_path
6
- def initialize(paths, registry_path)
6
+ def initialize(paths)
7
7
  @paths = paths.map { |p| "#{p}/**/*preview.rb" }
8
- @registry_path = registry_path.to_s
9
- YARD::Registry.yardoc_file = registry_path
8
+ @after_parse_callbacks = []
9
+ @after_parse_once_callbacks = []
10
+ @parsing = false
11
+
12
+ YARD::Parser::SourceParser.after_parse_list do
13
+ [*@after_parse_callbacks, *@after_parse_once_callbacks].each do |callback|
14
+ callback.call(YARD::Registry)
15
+ end
16
+ @after_parse_once_callbacks = []
17
+ @parsing = false
18
+ end
10
19
  end
11
20
 
12
- def parse
13
- YARD::Registry.clear
14
- YARD::Registry.lock_for_writing do
21
+ def parse(&block)
22
+ unless @parsing
23
+ @parsing = true
24
+ @after_parse_once_callbacks << block if block
25
+ YARD::Registry.clear
15
26
  YARD.parse(@paths)
16
- YARD::Registry.save(false, registry_path)
17
27
  end
18
28
  end
19
29
 
20
- def get_code_object(path)
21
- registry = YARD::RegistryStore.new
22
- registry.load!(registry_path)
23
- registry.get(path)
30
+ def after_parse(&block)
31
+ @after_parse_callbacks << block
24
32
  end
25
33
 
26
34
  class << self
@@ -5,9 +5,9 @@ module Lookbook
5
5
  delegate :name, :render_args, to: :@preview
6
6
  delegate :position, :group, :notes, :hidden?, :tags, :tag, to: :@preview_inspector
7
7
 
8
- def initialize(preview)
8
+ def initialize(preview, code_object)
9
9
  @preview = preview
10
- @preview_inspector = SourceInspector.new(@preview.name)
10
+ @preview_inspector = SourceInspector.new(code_object)
11
11
  super(preview_class_path(@preview.name))
12
12
  end
13
13
 
@@ -35,7 +35,7 @@ module Lookbook
35
35
  return @examples if @examples.present?
36
36
  public_methods = @preview.public_instance_methods(false)
37
37
  public_method_objects = @preview_inspector&.methods&.select { |m| public_methods.include?(m.name) }
38
- examples = (public_method_objects || []).map { |m| PreviewExample.new(m.name.to_s, self) }
38
+ examples = (public_method_objects || []).map { |m| PreviewExample.new(m.name.to_s, self, m) }
39
39
  sorted = Lookbook.config.sort_examples ? examples.sort_by(&:label) : examples
40
40
  @examples = []
41
41
  if @preview_inspector&.groups&.any?
@@ -109,6 +109,9 @@ module Lookbook
109
109
 
110
110
  protected
111
111
 
112
+ @preview_objects = nil
113
+ @previews = nil
114
+
112
115
  def guess_component
113
116
  name.chomp("Preview").constantize
114
117
  rescue
@@ -129,26 +132,20 @@ module Lookbook
129
132
  end
130
133
 
131
134
  def all
132
- load_previews if preview_files.size > ViewComponent::Preview.descendants.size
133
-
134
- @previews = nil if cache_stale?
135
- return @previews unless @previews.nil?
136
-
137
- previews = ViewComponent::Preview.descendants.map do |p|
138
- new(p)
139
- rescue
140
- Rails.logger.error "[lookbook] error instantiating preview\n#{exception.full_message}"
141
- end
142
-
143
- if errors.any?
144
- errors.each do |error|
145
- Rails.logger.error "[lookbook] preview error\n#{error.full_message}\n"
146
- end
135
+ if @previews.nil? && @preview_objects.present?
136
+ previews = @preview_objects.map do |code_object|
137
+ klass = code_object.path.constantize
138
+ new(klass, code_object) if klass.ancestors.include?(ViewComponent::Preview)
139
+ rescue => exception
140
+ Lookbook.logger.error Lookbook::Error.new(exception)
141
+ nil
142
+ end.compact
143
+
144
+ sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
145
+ @previews = PreviewCollection.new(sorted_previews)
146
+ else
147
+ PreviewCollection.new([])
147
148
  end
148
-
149
- sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
150
- @previews = PreviewCollection.new(sorted_previews)
151
- mark_as_cached if Lookbook.config.listen == true
152
149
  @previews
153
150
  end
154
151
 
@@ -156,60 +153,9 @@ module Lookbook
156
153
  @errors ||= []
157
154
  end
158
155
 
159
- def clear_cache
160
- cache_dir = File.dirname(cache_marker_path)
161
- FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
162
- File.write(cache_marker_path, Time.now.to_i)
163
- end
164
-
165
- protected
166
-
167
- def cache_marker_path
168
- Rails.root.join("tmp/cache/lookbook-previews")
169
- end
170
-
171
- def cache_stale?
172
- return false if !File.exist?(cache_marker_path)
173
- cache_timestamp = File.read(cache_marker_path).to_i
174
- if @last_cache_timestamp.nil? || cache_timestamp > @last_cache_timestamp
175
- @last_cache_timestamp = cache_timestamp
176
- true
177
- else
178
- false
179
- end
180
- end
181
-
182
- def mark_as_cached
183
- cache_dir = File.dirname(cache_marker_path)
184
- FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
185
- File.write(cache_marker_path, Time.now)
186
- end
187
-
188
- def load_previews
189
- @errors = []
190
- preview_files.each do |file|
191
- require_dependency file[:path]
192
- rescue SyntaxError, StandardError => exception
193
- @errors.push(
194
- Lookbook::Error.new(exception,
195
- title: "Preview #{exception.class}",
196
- file_name: file[:rel_path],
197
- file_path: file[:path])
198
- )
199
- end
200
- end
201
-
202
- def preview_files
203
- files = Array(Lookbook.config.preview_paths).map do |preview_path|
204
- Dir["#{preview_path}/**/*preview.rb"].map do |path|
205
- {
206
- path: path,
207
- base_path: preview_path,
208
- rel_path: Pathname(path).relative_path_from(Pathname.new(preview_path)).to_s
209
- }
210
- end
211
- end
212
- files.flatten
156
+ def load!(preview_objects)
157
+ @preview_objects = preview_objects
158
+ @previews = nil
213
159
  end
214
160
  end
215
161