lookbook 0.7.2.beta.2 → 0.7.2.beta.3

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: 990948c73a9d1c658a44b0ae4ac88c2c850fa92dfe9e40551b4634311113fe87
4
- data.tar.gz: a203b8a19a1b9dc3d3ec91af757b1bb75edd84fed009e329f720b7e5891f737e
3
+ metadata.gz: 852092ae163c9f99f18df3ac6ccd9c54fa41050d9eab7c6ce193404af3a73978
4
+ data.tar.gz: 47b59f02f782fc536e68cb016ab9d8effe26c58957a6e273568deebdd00217cb
5
5
  SHA512:
6
- metadata.gz: bb588034ce795c97cccffbf1d7de75bbce28895009975576e8d2bcf50a3e4878771fe38cba600aa6986d59b3e3579023a2782a8dc0cc4bd349376a8bd67978b5
7
- data.tar.gz: 3485c0882de17d7a3c63a27872a79615043d7c03651e555394f53accaed865c36b45e43f086deb23dd8d0a4118049ac4cbd936943765afb619e0a9e413287d7e
6
+ metadata.gz: e1e15295d9ee395d05b2971f4441387219d99b358020ff4a83816229ce2ca63ac3c30f5d2c74938c37bcff579abc34105caa37ed38183f7e3888b176c62f0fb9
7
+ data.tar.gz: 8ac54bd1cf4d4044c9ff037cc1ccf44fd6d674fbb643e35aa1b98e729eaa5dbc8636233bc7461ab0670ecdfc1cfd5ed9251dd03d86ede5595a0274f3db01581a
@@ -28,10 +28,7 @@ module Lookbook
28
28
  @title = @page.title
29
29
  rescue => exception
30
30
  render "lookbook/error", locals: {
31
- error: Lookbook::Error.new(exception, {
32
- file_path: @page.full_path,
33
- source_code: @page.content
34
- })
31
+ error: Lookbook::Error.new(exception, file_path: @page.full_path, source_code: @page.content)
35
32
  }
36
33
  end
37
34
  end
@@ -176,7 +176,7 @@ module Lookbook
176
176
  }
177
177
  end
178
178
  end
179
- Lookbook::Error.new(exception, error_params || {})
179
+ Lookbook::Error.new(exception, **(error_params || {}))
180
180
  end
181
181
  end
182
182
  end
@@ -10,7 +10,7 @@ module Lookbook
10
10
  end
11
11
 
12
12
  def code(language = "ruby", **opts, &block)
13
- render_component "code", {language: language, **opts}, &block
13
+ render_component "code", language: language, **opts, &block
14
14
  end
15
15
 
16
16
  if Rails.version.to_f < 6.1
@@ -19,12 +19,11 @@ module Lookbook
19
19
 
20
20
  if example
21
21
  @embed_counter += 1
22
- render_component "embed", {
22
+ render_component "embed",
23
23
  id: generate_id("embed", url_for, example.lookup_path, @embed_counter - 1),
24
24
  example: example,
25
25
  params: params,
26
26
  opts: opts
27
- }
28
27
  else
29
28
  embed_not_found
30
29
  end
@@ -83,9 +83,6 @@ module Lookbook
83
83
 
84
84
  config.after_initialize do
85
85
  @preview_listener = Listen.to(*config.lookbook.listen_paths, only: /\.(rb|html.*)$/) do |modified, added, removed|
86
- if Lookbook::Preview.errors.any?
87
- Lookbook::Preview.reload
88
- end
89
86
  begin
90
87
  parser.parse
91
88
  rescue
data/lib/lookbook/page.rb CHANGED
@@ -106,7 +106,7 @@ module Lookbook
106
106
  rescue => exception
107
107
  frontmatter = {}
108
108
  line_number_match = exception.message.match(/.*line\s(\d+)/)
109
- @errors.push(Lookbook::Error.new(exception, {
109
+ @errors.push(Lookbook::Error.new(exception, **{
110
110
  title: "YAML frontmatter parsing error",
111
111
  file_path: @pathname.to_s,
112
112
  line_number: line_number_match ? line_number_match[1] : false
@@ -97,61 +97,47 @@ module Lookbook
97
97
  end
98
98
 
99
99
  def all
100
- previews = load_previews.map do |p|
100
+ load_previews if preview_files.size > ViewComponent::Preview.descendants.size
101
+
102
+ previews = ViewComponent::Preview.descendants.map do |p|
101
103
  new(p)
102
104
  rescue
103
105
  Rails.logger.error "[lookbook] error instantiating preview\n#{exception.full_message}"
104
106
  end
105
107
 
108
+ if errors.any?
109
+ errors.each do |error|
110
+ Rails.logger.error "[lookbook] preview error\n#{error.full_message}\n"
111
+ end
112
+ end
113
+
106
114
  sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
107
115
  PreviewCollection.new(sorted_previews)
108
116
  end
109
117
 
110
118
  def errors
111
- @errors || []
112
- end
113
-
114
- def reload
115
- load_previews
119
+ @errors ||= []
116
120
  end
117
121
 
118
122
  protected
119
123
 
120
- def reset_files_data
121
- @loaded_files = []
122
- @errors = []
123
- end
124
-
125
124
  def load_previews
126
- reset_files_data if @loaded_files.nil?
127
- require_preview_files if @errors.any?
128
-
129
- preview_classes = ViewComponent::Preview.descendants
130
- if preview_files.size > preview_classes.size
131
- require_preview_files
132
- end
133
-
134
- ViewComponent::Preview.descendants.filter { |klass| @loaded_files.include? "#{klass.name.underscore}.rb" }
135
- end
136
-
137
- def require_preview_files
138
- reset_files_data
125
+ @errors = []
139
126
  preview_files.each do |file|
140
- require_dependency(file[:path])
141
- @loaded_files.push(file[:rel_path])
127
+ require_dependency file[:path]
142
128
  rescue => exception
143
- Rails.logger.error "[lookbook] preview error\n#{exception.full_message}\n"
144
- @errors.push(Lookbook::Error.new(exception, {
145
- title: "Preview #{exception.class}",
146
- file_name: file[:rel_path],
147
- file_path: file[:path]
148
- }))
129
+ @errors.push(
130
+ Lookbook::Error.new(exception,
131
+ title: "Preview #{exception.class}",
132
+ file_name: file[:rel_path],
133
+ file_path: file[:path])
134
+ )
149
135
  end
150
136
  end
151
137
 
152
138
  def preview_files
153
139
  files = Array(Lookbook.config.preview_paths).map do |preview_path|
154
- Dir["#{preview_path}/**/*_preview.rb"].map do |path|
140
+ Dir["#{preview_path}/**/*preview.rb"].map do |path|
155
141
  {
156
142
  path: path,
157
143
  base_path: preview_path,
@@ -1,3 +1,3 @@
1
1
  module Lookbook
2
- VERSION = "0.7.2.beta.2"
2
+ VERSION = "0.7.2.beta.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2.beta.2
4
+ version: 0.7.2.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Perkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-29 00:00:00.000000000 Z
11
+ date: 2022-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable