lookbook 0.7.2.beta.2 → 0.7.2.beta.5
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 +4 -4
- data/app/controllers/lookbook/pages_controller.rb +1 -4
- data/app/controllers/lookbook/previews_controller.rb +3 -4
- data/app/helpers/lookbook/component_helper.rb +1 -1
- data/app/helpers/lookbook/page_helper.rb +1 -2
- data/lib/lookbook/engine.rb +11 -21
- data/lib/lookbook/page.rb +1 -1
- data/lib/lookbook/preview.rb +27 -35
- data/lib/lookbook/preview_controller.rb +2 -2
- data/lib/lookbook/preview_group.rb +5 -1
- data/lib/lookbook/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5c4fab31fdd907dfcc4e990f703be32ce602db1729187d88c88abf60cc126bc
|
|
4
|
+
data.tar.gz: 57373e4f626acbbe451532587758f8962ba9186314d31752001f3b05baef5338
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4fc584e15f47fb60256e7fa49111df0a97fe7ac1a588c8e84657957e321cd1e9f627700a5969fd7efa03bf26a923005dc742ab277f2e993416fc1c83a2a5af89
|
|
7
|
+
data.tar.gz: 69a701e03da79385d9302e61c9df58b364eaf3e2f2160e8660c762810d9851a943297b061ad962af6fb0b056754e3b8af191c32a64f098a1487c1599bc668965
|
|
@@ -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
|
|
@@ -66,7 +66,7 @@ module Lookbook
|
|
|
66
66
|
{
|
|
67
67
|
label: example.label,
|
|
68
68
|
notes: example.notes,
|
|
69
|
-
html: preview_controller.render_example_to_string
|
|
69
|
+
html: preview_controller.process(:render_example_to_string, @preview, example.name),
|
|
70
70
|
source: has_template ? example.template_source(render_args[:template]) : example.method_source,
|
|
71
71
|
source_lang: has_template ? example.template_lang(render_args[:template]) : example.source_lang,
|
|
72
72
|
params: example.params
|
|
@@ -74,7 +74,7 @@ module Lookbook
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def render_examples(examples)
|
|
77
|
-
preview_controller.render_in_layout_to_string
|
|
77
|
+
preview_controller.process(:render_in_layout_to_string, "layouts/lookbook/preview", {examples: examples}, @preview.layout)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
def set_params
|
|
@@ -167,7 +167,6 @@ module Lookbook
|
|
|
167
167
|
message_parts = exception.message.split("\n").first.split
|
|
168
168
|
component_class = message_parts.first.constantize
|
|
169
169
|
naughty_method = message_parts.last.delete("#").delete("`").delete(".")
|
|
170
|
-
p naughty_method
|
|
171
170
|
method = component_class.instance_method(naughty_method.to_sym)
|
|
172
171
|
if method
|
|
173
172
|
{
|
|
@@ -176,7 +175,7 @@ module Lookbook
|
|
|
176
175
|
}
|
|
177
176
|
end
|
|
178
177
|
end
|
|
179
|
-
Lookbook::Error.new(exception, error_params || {})
|
|
178
|
+
Lookbook::Error.new(exception, **(error_params || {}))
|
|
180
179
|
end
|
|
181
180
|
end
|
|
182
181
|
end
|
|
@@ -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
|
data/lib/lookbook/engine.rb
CHANGED
|
@@ -83,36 +83,26 @@ 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
|
|
92
89
|
end
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
})
|
|
100
|
-
end
|
|
101
|
-
end
|
|
90
|
+
Lookbook::Preview.clear_cache
|
|
91
|
+
Lookbook::Engine.websocket&.broadcast("reload", {
|
|
92
|
+
modified: modified,
|
|
93
|
+
removed: removed,
|
|
94
|
+
added: added
|
|
95
|
+
})
|
|
102
96
|
end
|
|
103
97
|
@preview_listener.start
|
|
104
98
|
|
|
105
99
|
if Lookbook::Features.enabled?(:pages)
|
|
106
100
|
@page_listener = Listen.to(*config.lookbook.page_paths.filter { |dir| Dir.exist? dir }, only: /\.(html.*|md.*)$/) do |modified, added, removed|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
added: added
|
|
113
|
-
})
|
|
114
|
-
end
|
|
115
|
-
end
|
|
101
|
+
Lookbook::Engine.websocket&.broadcast("reload", {
|
|
102
|
+
modified: modified,
|
|
103
|
+
removed: removed,
|
|
104
|
+
added: added
|
|
105
|
+
})
|
|
116
106
|
end
|
|
117
107
|
@page_listener.start
|
|
118
108
|
end
|
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
|
data/lib/lookbook/preview.rb
CHANGED
|
@@ -96,62 +96,54 @@ module Lookbook
|
|
|
96
96
|
!!find(path)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
def clear_cache
|
|
100
|
+
@previews = nil
|
|
101
|
+
end
|
|
102
|
+
|
|
99
103
|
def all
|
|
100
|
-
|
|
104
|
+
load_previews if preview_files.size > ViewComponent::Preview.descendants.size
|
|
105
|
+
|
|
106
|
+
return @previews if @previews.present?
|
|
107
|
+
|
|
108
|
+
previews = ViewComponent::Preview.descendants.map do |p|
|
|
101
109
|
new(p)
|
|
102
110
|
rescue
|
|
103
111
|
Rails.logger.error "[lookbook] error instantiating preview\n#{exception.full_message}"
|
|
104
112
|
end
|
|
105
113
|
|
|
114
|
+
if errors.any?
|
|
115
|
+
errors.each do |error|
|
|
116
|
+
Rails.logger.error "[lookbook] preview error\n#{error.full_message}\n"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
106
120
|
sorted_previews = previews.compact.sort_by { |preview| [preview.position, preview.label] }
|
|
107
|
-
PreviewCollection.new(sorted_previews)
|
|
121
|
+
@previews ||= PreviewCollection.new(sorted_previews)
|
|
108
122
|
end
|
|
109
123
|
|
|
110
124
|
def errors
|
|
111
|
-
@errors
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def reload
|
|
115
|
-
load_previews
|
|
125
|
+
@errors ||= []
|
|
116
126
|
end
|
|
117
127
|
|
|
118
128
|
protected
|
|
119
129
|
|
|
120
|
-
def reset_files_data
|
|
121
|
-
@loaded_files = []
|
|
122
|
-
@errors = []
|
|
123
|
-
end
|
|
124
|
-
|
|
125
130
|
def load_previews
|
|
126
|
-
|
|
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
|
|
131
|
+
@errors = []
|
|
139
132
|
preview_files.each do |file|
|
|
140
|
-
require_dependency
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}))
|
|
133
|
+
require_dependency file[:path]
|
|
134
|
+
rescue SyntaxError, StandardError => exception
|
|
135
|
+
@errors.push(
|
|
136
|
+
Lookbook::Error.new(exception,
|
|
137
|
+
title: "Preview #{exception.class}",
|
|
138
|
+
file_name: file[:rel_path],
|
|
139
|
+
file_path: file[:path])
|
|
140
|
+
)
|
|
149
141
|
end
|
|
150
142
|
end
|
|
151
143
|
|
|
152
144
|
def preview_files
|
|
153
145
|
files = Array(Lookbook.config.preview_paths).map do |preview_path|
|
|
154
|
-
Dir["#{preview_path}/**/*
|
|
146
|
+
Dir["#{preview_path}/**/*preview.rb"].map do |path|
|
|
155
147
|
{
|
|
156
148
|
path: path,
|
|
157
149
|
base_path: preview_path,
|
|
@@ -11,12 +11,12 @@ module Lookbook
|
|
|
11
11
|
opts = {}
|
|
12
12
|
opts[:layout] = nil
|
|
13
13
|
opts[:locals] = locals if locals.present?
|
|
14
|
-
render_to_string
|
|
14
|
+
render html: render_to_string(template, **opts)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def render_in_layout_to_string(template, locals, layout = nil)
|
|
18
18
|
append_view_path Lookbook::Engine.root.join("app/views")
|
|
19
|
-
render_to_string
|
|
19
|
+
render html: render_to_string(template, locals: locals, **determine_layout(layout))
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
data/lib/lookbook/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.7.2.beta.5
|
|
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-
|
|
11
|
+
date: 2022-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actioncable
|