lookbook 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/lookbook/js/helpers/string.js +23 -1
  3. data/app/assets/lookbook/js/lookbook.js +0 -1
  4. data/app/components/lookbook/display_options/editor/component.html.erb +13 -0
  5. data/app/components/lookbook/display_options/editor/component.rb +7 -0
  6. data/app/components/lookbook/display_options/field/component.css +33 -0
  7. data/app/components/lookbook/display_options/field/component.html.erb +8 -0
  8. data/app/components/lookbook/display_options/field/component.js +30 -0
  9. data/app/components/lookbook/display_options/field/component.rb +28 -0
  10. data/app/components/lookbook/inspector_panel/component.html.erb +1 -1
  11. data/app/components/lookbook/inspector_panel/component.rb +10 -11
  12. data/app/components/lookbook/params/editor/component.rb +6 -3
  13. data/app/components/lookbook/params/field/component.rb +1 -5
  14. data/app/components/lookbook/tab_panels/panel/component.html.erb +1 -1
  15. data/app/components/lookbook/tab_panels/panel/component.rb +1 -2
  16. data/app/components/lookbook/tabs/dropdown_tab/component.html.erb +1 -0
  17. data/app/components/lookbook/tabs/tab/component.html.erb +1 -0
  18. data/app/components/lookbook/viewport/component.html.erb +1 -1
  19. data/app/components/lookbook/viewport/component.rb +2 -1
  20. data/app/controllers/lookbook/previews_controller.rb +40 -29
  21. data/app/helpers/lookbook/preview_helper.rb +1 -1
  22. data/app/views/lookbook/preview.html.erb +1 -1
  23. data/app/views/lookbook/previews/panels/_params.html.erb +1 -1
  24. data/app/views/lookbook/previews/panels/_preview.html.erb +9 -6
  25. data/app/views/lookbook/previews/show.html.erb +29 -11
  26. data/config/app.yml +36 -0
  27. data/config/hooks.yml +4 -0
  28. data/config/inputs.yml +48 -0
  29. data/config/panels.yml +30 -0
  30. data/config/routes.rb +1 -1
  31. data/config/tags.yml +29 -0
  32. data/lib/lookbook/engine.rb +40 -87
  33. data/lib/lookbook/markdown.rb +1 -11
  34. data/lib/lookbook/page.rb +1 -1
  35. data/lib/lookbook/params.rb +0 -7
  36. data/lib/lookbook/parser.rb +3 -10
  37. data/lib/lookbook/preview.rb +7 -3
  38. data/lib/lookbook/preview_example.rb +7 -3
  39. data/lib/lookbook/preview_group.rb +2 -2
  40. data/lib/lookbook/services/config_loader.rb +20 -0
  41. data/lib/lookbook/services/search_param_builder.rb +13 -0
  42. data/lib/lookbook/services/search_param_parser.rb +15 -0
  43. data/lib/lookbook/services/tags/key_value_tag_parser.rb +24 -0
  44. data/lib/lookbook/source_inspector.rb +10 -16
  45. data/lib/lookbook/stores/config_store.rb +80 -0
  46. data/lib/lookbook/stores/hook_store.rb +28 -0
  47. data/lib/lookbook/stores/input_store.rb +58 -0
  48. data/lib/lookbook/stores/panel_store.rb +141 -0
  49. data/lib/lookbook/stores/tag_store.rb +46 -0
  50. data/lib/lookbook/support/errors/config_error.rb +7 -0
  51. data/lib/lookbook/support/errors/lookbook_error.rb +21 -0
  52. data/lib/lookbook/support/errors/parser_error.rb +7 -0
  53. data/lib/lookbook/support/service.rb +7 -0
  54. data/lib/lookbook/support/store.rb +77 -0
  55. data/lib/lookbook/support/utils/attribute_utils.rb +9 -0
  56. data/lib/lookbook/support/utils/path_utils.rb +19 -0
  57. data/lib/lookbook/tags.rb +5 -14
  58. data/lib/lookbook/version.rb +1 -1
  59. data/lib/lookbook.rb +106 -30
  60. data/public/lookbook-assets/css/lookbook.css +33 -0
  61. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  62. data/public/lookbook-assets/js/lookbook.js +158 -21
  63. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  64. metadata +43 -7
  65. data/lib/lookbook/config.rb +0 -282
  66. data/lib/lookbook/data.rb +0 -11
  67. data/lib/lookbook/hooks.rb +0 -21
  68. data/lib/lookbook/panels.rb +0 -25
  69. data/lib/lookbook/store.rb +0 -48
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: 1.1.0
4
+ version: 1.2.0
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-10-01 00:00:00.000000000 Z
11
+ date: 2022-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zeitwerk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.5'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: railties
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -226,6 +240,12 @@ files:
226
240
  - app/components/lookbook/dimensions_display/component.html.erb
227
241
  - app/components/lookbook/dimensions_display/component.js
228
242
  - app/components/lookbook/dimensions_display/component.rb
243
+ - app/components/lookbook/display_options/editor/component.html.erb
244
+ - app/components/lookbook/display_options/editor/component.rb
245
+ - app/components/lookbook/display_options/field/component.css
246
+ - app/components/lookbook/display_options/field/component.html.erb
247
+ - app/components/lookbook/display_options/field/component.js
248
+ - app/components/lookbook/display_options/field/component.rb
229
249
  - app/components/lookbook/embed/component.html.erb
230
250
  - app/components/lookbook/embed/component.js
231
251
  - app/components/lookbook/embed/component.rb
@@ -316,24 +336,25 @@ files:
316
336
  - app/views/lookbook/previews/panels/_preview.html.erb
317
337
  - app/views/lookbook/previews/panels/_source.html.erb
318
338
  - app/views/lookbook/previews/show.html.erb
339
+ - config/app.yml
340
+ - config/hooks.yml
341
+ - config/inputs.yml
342
+ - config/panels.yml
319
343
  - config/routes.rb
344
+ - config/tags.yml
320
345
  - lib/lookbook.rb
321
346
  - lib/lookbook/code_formatter.rb
322
347
  - lib/lookbook/collection.rb
323
348
  - lib/lookbook/component.rb
324
- - lib/lookbook/config.rb
325
- - lib/lookbook/data.rb
326
349
  - lib/lookbook/engine.rb
327
350
  - lib/lookbook/entity.rb
328
351
  - lib/lookbook/error.rb
329
352
  - lib/lookbook/features.rb
330
- - lib/lookbook/hooks.rb
331
353
  - lib/lookbook/lang.rb
332
354
  - lib/lookbook/markdown.rb
333
355
  - lib/lookbook/page.rb
334
356
  - lib/lookbook/page_collection.rb
335
357
  - lib/lookbook/page_section.rb
336
- - lib/lookbook/panels.rb
337
358
  - lib/lookbook/params.rb
338
359
  - lib/lookbook/parser.rb
339
360
  - lib/lookbook/preview.rb
@@ -341,8 +362,23 @@ files:
341
362
  - lib/lookbook/preview_controller.rb
342
363
  - lib/lookbook/preview_example.rb
343
364
  - lib/lookbook/preview_group.rb
365
+ - lib/lookbook/services/config_loader.rb
366
+ - lib/lookbook/services/search_param_builder.rb
367
+ - lib/lookbook/services/search_param_parser.rb
368
+ - lib/lookbook/services/tags/key_value_tag_parser.rb
344
369
  - lib/lookbook/source_inspector.rb
345
- - lib/lookbook/store.rb
370
+ - lib/lookbook/stores/config_store.rb
371
+ - lib/lookbook/stores/hook_store.rb
372
+ - lib/lookbook/stores/input_store.rb
373
+ - lib/lookbook/stores/panel_store.rb
374
+ - lib/lookbook/stores/tag_store.rb
375
+ - lib/lookbook/support/errors/config_error.rb
376
+ - lib/lookbook/support/errors/lookbook_error.rb
377
+ - lib/lookbook/support/errors/parser_error.rb
378
+ - lib/lookbook/support/service.rb
379
+ - lib/lookbook/support/store.rb
380
+ - lib/lookbook/support/utils/attribute_utils.rb
381
+ - lib/lookbook/support/utils/path_utils.rb
346
382
  - lib/lookbook/tag.rb
347
383
  - lib/lookbook/tag_options.rb
348
384
  - lib/lookbook/tags.rb
@@ -1,282 +0,0 @@
1
- require "lookbook/markdown"
2
- require "lookbook/theme"
3
- require "lookbook/store"
4
-
5
- module Lookbook
6
- class Config
7
- def initialize
8
- @options = Store.new({}, true)
9
-
10
- @options.set({
11
- project_name: "Lookbook",
12
- log_level: 2,
13
- log_use_rails_logger: true,
14
- auto_refresh: true,
15
-
16
- components_path: "app/components",
17
-
18
- page_controller: "Lookbook::PageController",
19
- page_route: "pages",
20
- page_paths: ["test/components/docs"],
21
- page_options: {},
22
- markdown_options: Markdown::DEFAULT_OPTIONS,
23
-
24
- preview_paths: [],
25
- preview_display_params: {},
26
- preview_srcdoc: nil,
27
- preview_tags: {},
28
- preview_disable_action_view_annotations: true,
29
- preview_param_inputs: {
30
- select: "lookbook/previews/inputs/select",
31
- textarea: "lookbook/previews/inputs/textarea",
32
- toggle: "lookbook/previews/inputs/toggle",
33
- color: "lookbook/previews/inputs/color",
34
- range: "lookbook/previews/inputs/range",
35
- text: "lookbook/previews/inputs/text",
36
- email: "lookbook/previews/inputs/text",
37
- number: "lookbook/previews/inputs/text",
38
- tel: "lookbook/previews/inputs/text",
39
- url: "lookbook/previews/inputs/text",
40
- date: "lookbook/previews/inputs/text",
41
- datetime_local: "lookbook/previews/inputs/text"
42
- },
43
- preview_params_options_eval: false,
44
- sort_examples: false,
45
-
46
- listen: Rails.env.development?,
47
- listen_paths: [],
48
- listen_extensions: ["rb", "html.*"],
49
- listen_use_polling: false,
50
-
51
- cable_mount_path: "/cable",
52
-
53
- parser_registry_path: "tmp/storage/.yardoc",
54
-
55
- ui_theme: "indigo",
56
- ui_theme_overrides: {},
57
- ui_favicon: true,
58
-
59
- hooks: {
60
- after_initialize: [],
61
- before_exit: [],
62
- after_change: []
63
- },
64
-
65
- debug_menu: Rails.env.development?,
66
-
67
- experimental_features: false,
68
-
69
- inspector_panels: {
70
- preview: {
71
- pane: :main,
72
- position: 1,
73
- partial: "lookbook/previews/panels/preview",
74
- hotkey: "v",
75
- panel_classes: "overflow-hidden",
76
- padded: false,
77
- system: true
78
- },
79
- output: {
80
- pane: :main,
81
- position: 2,
82
- partial: "lookbook/previews/panels/output",
83
- label: "HTML",
84
- hotkey: "h",
85
- padded: false,
86
- system: true
87
- },
88
- source: {
89
- pane: :drawer,
90
- position: 1,
91
- partial: "lookbook/previews/panels/source",
92
- label: "Source",
93
- hotkey: "s",
94
- copy: ->(data) { data.examples.map { |e| e.source }.join("\n") },
95
- padded: false,
96
- system: true
97
- },
98
- notes: {
99
- pane: :drawer,
100
- position: 2,
101
- partial: "lookbook/previews/panels/notes",
102
- label: "Notes",
103
- hotkey: "n",
104
- disabled: ->(data) { data.examples.select { |e| e.notes.present? }.none? },
105
- padded: false,
106
- system: true
107
- },
108
- params: {
109
- pane: :drawer,
110
- position: 3,
111
- partial: "lookbook/previews/panels/params",
112
- label: "Params",
113
- hotkey: "p",
114
- disabled: ->(data) { data.preview.params.none? },
115
- padded: false,
116
- system: true
117
- }
118
- }
119
- })
120
- end
121
-
122
- def runtime_parsing=(value)
123
- Lookbook.logger.warn "The `runtime_parsing` config option has been deprecated and will be removed in v2.0"
124
- end
125
-
126
- def project_name
127
- @options.project_name == false ? nil : @options.project_name
128
- end
129
-
130
- def components_path
131
- absolute_path(@options.components_path)
132
- end
133
-
134
- def page_paths=(paths = [])
135
- @options.page_paths += paths if paths.is_a? Array
136
- end
137
-
138
- def page_paths
139
- normalize_paths(@options.page_paths)
140
- end
141
-
142
- def preview_paths=(paths = [])
143
- @options.preview_paths += paths if paths.is_a? Array
144
- end
145
-
146
- def preview_paths
147
- normalize_paths(@options.preview_paths)
148
- end
149
-
150
- def preview_srcdoc=(enable)
151
- Lookbook.logger.warn "The `preview_srcdoc` config option is deprecated and will be removed in v2.0"
152
- end
153
-
154
- def listen_paths
155
- normalize_paths(@options.listen_paths)
156
- end
157
-
158
- def listen_extensions=(extensions = [])
159
- @options.listen_extensions += extensions if extensions.is_a? Array
160
- @options.listen_extensions.uniq!
161
- end
162
-
163
- def parser_registry_path
164
- absolute_path(@options.parser_registry_path)
165
- end
166
-
167
- def inspector_panels(&block)
168
- panels = Store.new(@options.inspector_panels.select { |key, panel| panel != false })
169
- if block
170
- yield panels
171
- else
172
- panels
173
- end
174
- end
175
-
176
- def define_inspector_panel(name, opts = {})
177
- pane = opts[:pane].presence || :drawer
178
- siblings = inspector_panels.select { |key, panel| panel.pane == pane }
179
- opts[:position] ||= siblings.size + 1
180
- @options.inspector_panels[name] = opts
181
- siblings.each do |key, panel|
182
- if panel.position >= opts[:position]
183
- panel.position += 1
184
- end
185
- end
186
- end
187
-
188
- def amend_inspector_panel(name, opts = {})
189
- if opts == false
190
- @options.inspector_panels[name] = false
191
- else
192
- @options.inspector_panels[name].merge!(opts)
193
- end
194
- end
195
-
196
- def remove_inspector_panel(name)
197
- amend_inspector_panel(name, false)
198
- end
199
-
200
- def inspector_panel_defaults
201
- {
202
- id: ->(data) { "inspector-panel-#{data.name}" },
203
- partial: "lookbook/previews/panels/content",
204
- content: nil,
205
- label: ->(data) { data.name.titleize },
206
- pane: :drawer,
207
- position: ->(data) { data.index_position },
208
- hotkey: nil,
209
- disabled: false,
210
- show: true,
211
- copy: nil,
212
- panel_classes: nil,
213
- locals: {},
214
- system: false
215
- }
216
- end
217
-
218
- def ui_theme=(name)
219
- name = name.to_s
220
- if Theme.valid_theme?(name)
221
- @options.ui_theme = name
222
- else
223
- Lookbook.logger.warn "'#{name}' is not a valid Lookbook theme. Theme setting not changed."
224
- end
225
- end
226
-
227
- def ui_theme_overrides(&block)
228
- if block
229
- yield @options.ui_theme_overrides
230
- else
231
- @options.ui_theme_overrides
232
- end
233
- end
234
-
235
- def [](key)
236
- if respond_to? key.to_sym
237
- public_send(key.to_sym)
238
- else
239
- @options[key.to_sym]
240
- end
241
- end
242
-
243
- def []=(key, value)
244
- setter_key = "#{key}=".to_sym
245
- if respond_to? setter_key
246
- public_send(setter_key, value)
247
- else
248
- @options[key.to_sym] = value
249
- end
250
- end
251
-
252
- def to_h
253
- @options.to_h
254
- end
255
-
256
- def to_json(*a)
257
- to_h.to_json(*a)
258
- end
259
-
260
- protected
261
-
262
- def normalize_paths(paths)
263
- paths.map! do |path|
264
- full_path = absolute_path(path)
265
- full_path if Dir.exist?(full_path)
266
- end.compact!
267
- paths
268
- end
269
-
270
- def absolute_path(path)
271
- File.absolute_path(path.to_s, Rails.root)
272
- end
273
-
274
- def method_missing(name, *args)
275
- @options.send(name, *args)
276
- end
277
-
278
- def respond_to_missing?(name, *)
279
- to_h.key? name
280
- end
281
- end
282
- end
data/lib/lookbook/data.rb DELETED
@@ -1,11 +0,0 @@
1
- module Lookbook
2
- module Data
3
- def data
4
- @data ||= Store.new({}, true)
5
- end
6
-
7
- def data=(props)
8
- @data = Store.new(props, true)
9
- end
10
- end
11
- end
@@ -1,21 +0,0 @@
1
- module Lookbook
2
- module Hooks
3
- def after_initialize(&block)
4
- add_hook(:after_initialize, block)
5
- end
6
-
7
- def before_exit(&block)
8
- add_hook(:before_exit, block)
9
- end
10
-
11
- def after_change(&block)
12
- add_hook(:after_change, block)
13
- end
14
-
15
- protected
16
-
17
- def add_hook(event_name, block)
18
- Lookbook.config.hooks[event_name] << block
19
- end
20
- end
21
- end
@@ -1,25 +0,0 @@
1
- module Lookbook
2
- module Panels
3
- def define_panel(name, *args)
4
- Lookbook.config.define_inspector_panel(name, extract_opts(args))
5
- end
6
-
7
- def amend_panel(name, *args)
8
- Lookbook.amend_inspector_panel(name, extract_opts(args))
9
- end
10
-
11
- def remove_panel(name)
12
- Lookbook.remove_inspector_panel(name)
13
- end
14
-
15
- def extract_opts(args)
16
- if args.many?
17
- opts = args[1]
18
- opts[:partial] = args[0]
19
- opts
20
- elsif args.any?
21
- args[0].is_a?(String) ? {partial: args[0]} : args[0]
22
- end
23
- end
24
- end
25
- end
@@ -1,48 +0,0 @@
1
- module Lookbook
2
- class Store < ActiveSupport::OrderedOptions
3
- def initialize(data = {}, deep = false)
4
- super()
5
- @deep = deep
6
- set(data) if data.present?
7
- end
8
-
9
- def [](key)
10
- super(normalize_key(key))
11
- end
12
-
13
- def []=(key, value)
14
- super(normalize_key(key), normalize_value(value))
15
- end
16
-
17
- def set(data)
18
- data.keys.each do |key|
19
- self[normalize_key(key)] = normalize_value(data[key])
20
- end
21
- self
22
- end
23
-
24
- def get(key, fallback = nil)
25
- if key?(normalize_key(key))
26
- self[normalize_key(key)]
27
- else
28
- fallback
29
- end
30
- end
31
-
32
- def method_missing(name, *args)
33
- super(normalize_key(name), *args.map { |arg| normalize_value(arg) })
34
- end
35
-
36
- def respond_to_missing?(name, *)
37
- key?(name)
38
- end
39
-
40
- def normalize_key(key)
41
- key.to_s.downcase.tr("-", "_").to_sym
42
- end
43
-
44
- def normalize_value(value)
45
- @deep && !value.is_a?(Store) && value.is_a?(Hash) ? Store.new(value, @deep) : value
46
- end
47
- end
48
- end