lookbook 1.1.1 → 1.2.1

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