lookbook 1.0.0.beta.5 → 1.0.0.beta.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -254
  3. data/app/assets/lookbook/css/lookbook.css +1 -1
  4. data/app/assets/lookbook/css/themes/blue.css +58 -37
  5. data/app/assets/lookbook/css/themes/indigo.css +58 -37
  6. data/app/assets/lookbook/css/themes/zinc.css +58 -37
  7. data/app/assets/lookbook/css/tooltip.css +5 -5
  8. data/app/components/lookbook/base_component.rb +0 -1
  9. data/app/components/lookbook/button/component.html.erb +2 -2
  10. data/app/components/lookbook/embed/component.html.erb +5 -5
  11. data/app/components/lookbook/embed/component.rb +8 -0
  12. data/app/components/lookbook/filter/component.html.erb +1 -1
  13. data/app/components/lookbook/header/component.html.erb +1 -1
  14. data/app/components/lookbook/inspector_panel/component.css +5 -0
  15. data/app/components/lookbook/inspector_panel/component.html.erb +6 -0
  16. data/app/components/lookbook/inspector_panel/component.rb +36 -0
  17. data/app/components/lookbook/nav/component.rb +1 -2
  18. data/app/components/lookbook/nav/item/component.html.erb +1 -1
  19. data/app/components/lookbook/params_editor/field/component.rb +2 -1
  20. data/app/components/lookbook/prose/component.html.erb +1 -1
  21. data/app/components/lookbook/tab_panels/component.rb +1 -1
  22. data/app/components/lookbook/tab_panels/panel/component.rb +2 -2
  23. data/app/components/lookbook/tabs/dropdown_tab/component.html.erb +1 -1
  24. data/app/components/lookbook/tabs/tab/component.html.erb +1 -1
  25. data/app/components/lookbook/tag_component.rb +1 -1
  26. data/app/components/lookbook/toolbar/component.html.erb +1 -1
  27. data/app/components/lookbook/viewport/component.css +1 -1
  28. data/app/components/lookbook/viewport/component.html.erb +1 -1
  29. data/app/controllers/lookbook/application_controller.rb +1 -1
  30. data/app/controllers/lookbook/pages_controller.rb +1 -0
  31. data/app/controllers/lookbook/previews_controller.rb +21 -9
  32. data/app/helpers/lookbook/application_helper.rb +9 -6
  33. data/app/helpers/lookbook/preview_helper.rb +2 -3
  34. data/app/views/layouts/lookbook/application.html.erb +1 -1
  35. data/app/views/layouts/lookbook/page.html.erb +2 -2
  36. data/app/views/layouts/lookbook/shell.html.erb +6 -0
  37. data/app/views/layouts/lookbook/skeleton.html.erb +15 -14
  38. data/app/views/lookbook/previews/panels/_content.html.erb +1 -1
  39. data/app/views/lookbook/previews/panels/_notes.html.erb +2 -2
  40. data/app/views/lookbook/previews/panels/_params.html.erb +1 -1
  41. data/app/views/lookbook/previews/show.html.erb +7 -5
  42. data/lib/lookbook/code_formatter.rb +1 -1
  43. data/lib/lookbook/collection.rb +1 -1
  44. data/lib/lookbook/component.rb +2 -3
  45. data/lib/lookbook/config.rb +68 -46
  46. data/lib/lookbook/data.rb +11 -0
  47. data/lib/lookbook/engine.rb +64 -68
  48. data/lib/lookbook/entity.rb +1 -1
  49. data/lib/lookbook/hooks.rb +21 -0
  50. data/lib/lookbook/markdown.rb +1 -1
  51. data/lib/lookbook/page.rb +4 -5
  52. data/lib/lookbook/page_section.rb +2 -4
  53. data/lib/lookbook/panels.rb +15 -0
  54. data/lib/lookbook/params.rb +12 -0
  55. data/lib/lookbook/parser.rb +4 -1
  56. data/lib/lookbook/preview.rb +9 -11
  57. data/lib/lookbook/preview_example.rb +1 -1
  58. data/lib/lookbook/preview_group.rb +8 -0
  59. data/lib/lookbook/source_inspector.rb +9 -0
  60. data/lib/lookbook/store.rb +14 -2
  61. data/lib/lookbook/tag.rb +112 -0
  62. data/lib/lookbook/tags.rb +22 -0
  63. data/lib/lookbook/theme.rb +38 -9
  64. data/lib/lookbook/version.rb +1 -1
  65. data/lib/lookbook.rb +1 -0
  66. data/lib/tasks/lookbook_tasks.rake +1 -2
  67. data/public/lookbook-assets/css/lookbook.css +307 -150
  68. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  69. data/public/lookbook-assets/css/themes/blue.css +57 -36
  70. data/public/lookbook-assets/css/themes/blue.css.map +1 -1
  71. data/public/lookbook-assets/css/themes/indigo.css +57 -36
  72. data/public/lookbook-assets/css/themes/indigo.css.map +1 -1
  73. data/public/lookbook-assets/css/themes/zinc.css +57 -36
  74. data/public/lookbook-assets/css/themes/zinc.css.map +1 -1
  75. data/public/lookbook-assets/js/embed.js +193 -193
  76. data/public/lookbook-assets/js/lookbook.js +1151 -1308
  77. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  78. metadata +12 -4
@@ -6,14 +6,14 @@ module Lookbook
6
6
  class Config
7
7
  def initialize
8
8
  @options = Store.new
9
-
9
+
10
10
  @options.set({
11
11
  project_name: "Lookbook",
12
12
  log_level: 2,
13
13
  auto_refresh: true,
14
14
 
15
15
  components_path: "app/components",
16
-
16
+
17
17
  page_controller: "Lookbook::PageController",
18
18
  page_route: "pages",
19
19
  page_paths: ["test/components/docs"],
@@ -22,9 +22,9 @@ module Lookbook
22
22
 
23
23
  preview_paths: [],
24
24
  preview_display_params: {},
25
- preview_options: {},
26
- preview_srcdoc: false,
27
- sort_examples: true,
25
+ preview_srcdoc: nil,
26
+ preview_tags: {},
27
+ sort_examples: false,
28
28
 
29
29
  listen: Rails.env.development?,
30
30
  listen_paths: [],
@@ -39,11 +39,12 @@ module Lookbook
39
39
 
40
40
  ui_theme: "indigo",
41
41
  ui_theme_overrides: {},
42
+ ui_favicon: true,
42
43
 
43
44
  hooks: {
44
45
  after_initialize: [],
45
46
  before_exit: [],
46
- after_change: [],
47
+ after_change: []
47
48
  },
48
49
 
49
50
  debug_menu: Rails.env.development?,
@@ -57,7 +58,8 @@ module Lookbook
57
58
  partial: "lookbook/previews/panels/preview",
58
59
  hotkey: "v",
59
60
  panel_classes: "overflow-hidden",
60
- padded: false
61
+ padded: false,
62
+ system: true
61
63
  },
62
64
  output: {
63
65
  pane: :main,
@@ -65,7 +67,8 @@ module Lookbook
65
67
  partial: "lookbook/previews/panels/output",
66
68
  label: "HTML",
67
69
  hotkey: "h",
68
- padded: false
70
+ padded: false,
71
+ system: true
69
72
  },
70
73
  source: {
71
74
  pane: :drawer,
@@ -74,7 +77,8 @@ module Lookbook
74
77
  label: "Source",
75
78
  hotkey: "s",
76
79
  copy: ->(data) { data.examples.map { |e| e.source }.join("\n") },
77
- padded: false
80
+ padded: false,
81
+ system: true
78
82
  },
79
83
  notes: {
80
84
  pane: :drawer,
@@ -83,7 +87,8 @@ module Lookbook
83
87
  label: "Notes",
84
88
  hotkey: "n",
85
89
  disabled: ->(data) { data.examples.select { |e| e.notes.present? }.none? },
86
- padded: false
90
+ padded: false,
91
+ system: true
87
92
  },
88
93
  params: {
89
94
  pane: :drawer,
@@ -92,25 +97,10 @@ module Lookbook
92
97
  label: "Params",
93
98
  hotkey: "p",
94
99
  disabled: ->(data) { data.preview.params.none? },
95
- padded: false
100
+ padded: false,
101
+ system: true
96
102
  }
97
- },
98
-
99
- inspector_panel_defaults: {
100
- id: ->(data) { "inspector-panel-#{data.name}" },
101
- partial: "lookbook/previews/panels/content",
102
- content: nil,
103
- label: ->(data) { data.name.titleize },
104
- pane: :drawer,
105
- position: ->(data) { data.index_position },
106
- hotkey: nil,
107
- disabled: false,
108
- show: true,
109
- copy: nil,
110
- panel_classes: nil,
111
- locals: {},
112
- padded: true
113
- },
103
+ }
114
104
  })
115
105
  end
116
106
 
@@ -122,22 +112,33 @@ module Lookbook
122
112
  absolute_path(@options.components_path)
123
113
  end
124
114
 
115
+ def page_paths=(paths = [])
116
+ @options.page_paths += paths if paths.is_a? Array
117
+ end
118
+
125
119
  def page_paths
126
120
  normalize_paths(@options.page_paths)
127
121
  end
128
122
 
123
+ def preview_paths=(paths = [])
124
+ @options.preview_paths += paths if paths.is_a? Array
125
+ end
126
+
129
127
  def preview_paths
130
128
  normalize_paths(@options.preview_paths)
131
129
  end
132
130
 
131
+ def preview_srcdoc=(enable)
132
+ Lookbook.logger.warn "The `preview_srcdoc` config option is deprecated and will be removed in v2.0"
133
+ end
134
+
133
135
  def listen_paths
134
136
  normalize_paths(@options.listen_paths)
135
137
  end
136
138
 
137
- def listen_extensions
138
- @options.listen_extensions += ["rb", "html.*"]
139
+ def listen_extensions=(extensions = [])
140
+ @options.listen_extensions += extensions if extensions.is_a? Array
139
141
  @options.listen_extensions.uniq!
140
- @options.listen_extensions
141
142
  end
142
143
 
143
144
  def parser_registry_path
@@ -146,7 +147,7 @@ module Lookbook
146
147
 
147
148
  def inspector_panels(&block)
148
149
  panels = Store.new(@options.inspector_panels.select { |key, panel| panel != false })
149
- if block_given?
150
+ if block
150
151
  yield panels
151
152
  else
152
153
  panels
@@ -154,16 +155,13 @@ module Lookbook
154
155
  end
155
156
 
156
157
  def define_inspector_panel(name, opts = {})
158
+ pane = opts[:pane].presence || :drawer
159
+ siblings = inspector_panels.select { |key, panel| panel.pane == pane }
160
+ opts[:position] ||= siblings.size + 1
157
161
  @options.inspector_panels[name] = opts
158
- if opts[:position].present?
159
- pane = inspector_panels[name].pane.presence || :drawer
160
- siblings = inspector_panels.select do |key, panel|
161
- panel.pane == pane && key != name.to_sym
162
- end
163
- siblings.each do |key, panel|
164
- if panel.position >= opts[:position]
165
- panel.position += 1
166
- end
162
+ siblings.each do |key, panel|
163
+ if panel.position >= opts[:position]
164
+ panel.position += 1
167
165
  end
168
166
  end
169
167
  end
@@ -180,6 +178,24 @@ module Lookbook
180
178
  amend_inspector_panel(name, false)
181
179
  end
182
180
 
181
+ def inspector_panel_defaults
182
+ {
183
+ id: ->(data) { "inspector-panel-#{data.name}" },
184
+ partial: "lookbook/previews/panels/content",
185
+ content: nil,
186
+ label: ->(data) { data.name.titleize },
187
+ pane: :drawer,
188
+ position: ->(data) { data.index_position },
189
+ hotkey: nil,
190
+ disabled: false,
191
+ show: true,
192
+ copy: nil,
193
+ panel_classes: nil,
194
+ locals: {},
195
+ system: false
196
+ }
197
+ end
198
+
183
199
  def ui_theme=(name)
184
200
  name = name.to_s
185
201
  if Theme.valid_theme?(name)
@@ -190,7 +206,7 @@ module Lookbook
190
206
  end
191
207
 
192
208
  def ui_theme_overrides(&block)
193
- if block_given?
209
+ if block
194
210
  yield @options.ui_theme_overrides
195
211
  else
196
212
  @options.ui_theme_overrides
@@ -221,12 +237,14 @@ module Lookbook
221
237
  def to_json(*a)
222
238
  to_h.to_json(*a)
223
239
  end
224
-
240
+
225
241
  protected
226
242
 
227
243
  def normalize_paths(paths)
228
- paths.map! { |path| absolute_path(path) }
229
- paths.select! { |path| Dir.exist?(path) }
244
+ paths.map! do |path|
245
+ full_path = absolute_path(path)
246
+ full_path if Dir.exist?(full_path)
247
+ end.compact!
230
248
  paths
231
249
  end
232
250
 
@@ -237,5 +255,9 @@ module Lookbook
237
255
  def method_missing(name, *args)
238
256
  @options.send(name, *args)
239
257
  end
258
+
259
+ def respond_to_missing?(name, *)
260
+ to_h.key? name
261
+ end
240
262
  end
241
- end
263
+ end
@@ -0,0 +1,11 @@
1
+ module Lookbook
2
+ module Data
3
+ def data
4
+ @data ||= Store.new
5
+ end
6
+
7
+ def data=(props)
8
+ @data = Store.new(props)
9
+ end
10
+ end
11
+ end
@@ -2,12 +2,21 @@ require "rails"
2
2
  require "view_component"
3
3
  require "action_cable/engine"
4
4
  require "listen"
5
+ require "rake"
5
6
 
6
7
  module Lookbook
7
-
8
8
  autoload :Config, "lookbook/config"
9
-
9
+ autoload :Data, "lookbook/data"
10
+ autoload :Hooks, "lookbook/hooks"
11
+ autoload :Panels, "lookbook/panels"
12
+ autoload :Tags, "lookbook/tags"
13
+
10
14
  class << self
15
+ include Lookbook::Data
16
+ include Lookbook::Hooks
17
+ include Lookbook::Panels
18
+ include Lookbook::Tags
19
+
11
20
  def version
12
21
  Lookbook::VERSION
13
22
  end
@@ -48,38 +57,12 @@ module Lookbook
48
57
  Page.any?
49
58
  end
50
59
 
51
- def after_initialize(&block)
52
- add_hook(:after_initialize, block)
53
- end
54
-
55
- def before_exit(&block)
56
- add_hook(:before_exit, block)
57
- end
58
-
59
- def after_change(&block)
60
- add_hook(:after_change, block)
61
- end
62
-
63
- def define_panel(name, opts = {})
64
- config.define_inspector_panel(name, opts)
65
- end
66
-
67
- def amend_panel(name, opts = {})
68
- config.amend_inspector_panel(name, opts)
69
- end
70
-
71
- def remove_panel(name)
72
- config.remove_inspector_panel(name)
73
- end
74
-
75
60
  def broadcast(event_name, data = {})
76
61
  Engine.websocket&.broadcast(event_name.to_s, data)
77
62
  end
78
63
 
79
- protected
80
-
81
- def add_hook(event_name, block)
82
- config.hooks[event_name] << block
64
+ def theme
65
+ @theme ||= Lookbook::Theme.new(config.ui_theme, config.ui_theme_overrides)
83
66
  end
84
67
  end
85
68
 
@@ -89,14 +72,14 @@ module Lookbook
89
72
  config.lookbook = Lookbook.config
90
73
  config.autoload_paths << File.expand_path(Lookbook::Engine.root.join("app/components"))
91
74
 
92
- initializer "lookbook.viewcomponent.config" do
75
+ initializer "lookbook.viewcomponent.config" do
93
76
  config.lookbook.preview_paths += config.view_component.preview_paths
94
77
  config.lookbook.preview_controller ||= config.view_component.preview_controller
95
78
 
96
79
  config.lookbook.components_path = config.view_component.view_component_path if config.view_component.view_component_path.present?
97
80
 
98
81
  config.lookbook.listen_paths += config.lookbook.preview_paths
99
- config.lookbook.listen_paths << config.lookbook.components_path
82
+ config.lookbook.listen_paths << config.lookbook.components_path
100
83
  end
101
84
 
102
85
  initializer "lookbook.logging.development" do
@@ -104,7 +87,7 @@ module Lookbook
104
87
  end
105
88
 
106
89
  initializer "lookbook.parser.tags" do
107
- Lookbook::Parser.define_tags
90
+ Lookbook::Parser.define_tags(Lookbook.config.preview_tags)
108
91
  end
109
92
 
110
93
  initializer "lookbook.assets.serve" do
@@ -118,39 +101,20 @@ module Lookbook
118
101
  @preview_controller = Lookbook.config.preview_controller.constantize
119
102
  @preview_controller.include(Lookbook::PreviewController)
120
103
 
121
- if config.lookbook.listen
122
- Listen.logger = Lookbook.logger
123
-
124
- preview_listener = Listen.to(
125
- *config.lookbook.listen_paths,
126
- only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
127
- force_polling: config.lookbook.listen_use_polling
128
- ) do |modified, added, removed|
129
- changes = { modified: modified, added: added, removed: removed }
130
- begin
131
- parser.parse
132
- rescue
133
- end
134
- Lookbook::Preview.clear_cache
135
- Lookbook::Engine.reload_ui(changes)
136
- Lookbook::Engine.run_hooks(:after_change, changes)
104
+ if Gem::Version.new(Rails.version) >= Gem::Version.new("6.1.3.1")
105
+ # Rails.application.server is only available for newer Rails versions
106
+ Rails.application.server do
107
+ init_listeners
137
108
  end
138
- Lookbook::Engine.register_listener(preview_listener)
139
-
140
- page_listener = Listen.to(
141
- *config.lookbook.page_paths,
142
- only: /\.(html.*|md.*)$/,
143
- force_polling: config.lookbook.listen_use_polling
144
- ) do |modified, added, removed|
145
- changes = { modified: modified, added: added, removed: removed }
146
- Lookbook::Engine.reload_ui(changes)
147
- Lookbook::Engine.run_hooks(:after_change, changes)
109
+ else
110
+ # Fallback for older Rails versions - don't start listeners if running in a rake task.
111
+ unless File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
112
+ init_listeners
148
113
  end
149
- Lookbook::Engine.register_listener(page_listener)
150
114
  end
151
115
 
152
116
  if config.lookbook.runtime_parsing
153
- parser.parse
117
+ Lookbook::Engine.parser.parse
154
118
  else
155
119
  unless File.exist?(config.lookbook.parser_registry_path)
156
120
  Lookbook.logger.warn "
@@ -164,16 +128,48 @@ module Lookbook
164
128
  Lookbook::Engine.run_hooks(:after_initialize)
165
129
  end
166
130
 
131
+ def init_listeners
132
+ return unless config.lookbook.listen == true
133
+ Listen.logger = Lookbook.logger
134
+ Lookbook.logger.info "Initializing listeners"
135
+
136
+ preview_listener = Listen.to(
137
+ *config.lookbook.listen_paths,
138
+ only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
139
+ force_polling: config.lookbook.listen_use_polling
140
+ ) do |modified, added, removed|
141
+ changes = {modified: modified, added: added, removed: removed}
142
+ begin
143
+ Lookbook::Engine.parser.parse
144
+ rescue
145
+ end
146
+ Lookbook::Preview.clear_cache
147
+ Lookbook::Engine.reload_ui(changes)
148
+ Lookbook::Engine.run_hooks(:after_change, changes)
149
+ end
150
+ Lookbook::Engine.register_listener(preview_listener)
151
+
152
+ page_listener = Listen.to(
153
+ *config.lookbook.page_paths,
154
+ only: /\.(html.*|md.*)$/,
155
+ force_polling: config.lookbook.listen_use_polling
156
+ ) do |modified, added, removed|
157
+ changes = {modified: modified, added: added, removed: removed}
158
+ Lookbook::Engine.reload_ui(changes)
159
+ Lookbook::Engine.run_hooks(:after_change, changes)
160
+ end
161
+ Lookbook::Engine.register_listener(page_listener)
162
+ end
163
+
167
164
  at_exit do
168
- if config.lookbook.listen
165
+ if Lookbook::Engine.listeners.any?
169
166
  Lookbook.logger.debug "Stopping listeners"
170
- Lookbook::Engine.listeners.each { |listener| listener.stop }
167
+ Lookbook::Engine.listeners.each { |listener| listener.stop }
171
168
  end
172
169
  Lookbook::Engine.run_hooks(:before_exit)
173
170
  end
174
171
 
175
172
  class << self
176
-
177
173
  def websocket
178
174
  return @websocket unless @websocket.nil?
179
175
  if config.lookbook.auto_refresh
@@ -186,9 +182,9 @@ module Lookbook
186
182
  @websocket ||= if Rails.version.to_f >= 6.0
187
183
  ActionCable::Server::Base.new(config: cable)
188
184
  else
189
- @websocket ||= ActionCable::Server::Base.new
190
- @websocket.config = cable
191
- @websocket
185
+ ws = ActionCable::Server::Base.new
186
+ ws.config = cable
187
+ ws
192
188
  end
193
189
  end
194
190
  end
@@ -223,7 +219,7 @@ module Lookbook
223
219
  end
224
220
 
225
221
  def run_hooks(event_name, *args)
226
- Lookbook.config.hooks[event_name].each do |hook|
222
+ config.lookbook.hooks[event_name].each do |hook|
227
223
  hook.call(Lookbook, *args)
228
224
  end
229
225
  end
@@ -44,4 +44,4 @@ module Lookbook
44
44
 
45
45
  alias_method :url_path, :lookup_path
46
46
  end
47
- end
47
+ end
@@ -0,0 +1,21 @@
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
@@ -13,7 +13,7 @@ module Lookbook
13
13
  }
14
14
 
15
15
  def self.render(text)
16
- text&.gsub!(/\<\!\-\- (BEGIN|END) (.*) \-\-\>/, "")
16
+ text&.gsub!(/<!-- (BEGIN|END) (.*) -->/, "")
17
17
  markdown = Redcarpet::Markdown.new(Renderer, Lookbook.config.markdown_options)
18
18
  markdown.render(text).html_safe
19
19
  end
data/lib/lookbook/page.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Lookbook
2
2
  class Page < Entity
3
-
4
3
  FRONTMATTER_FIELDS = [
5
4
  :id,
6
5
  :label,
@@ -76,7 +75,7 @@ module Lookbook
76
75
  def type
77
76
  :page
78
77
  end
79
-
78
+
80
79
  def id
81
80
  options[:id]
82
81
  end
@@ -125,7 +124,7 @@ module Lookbook
125
124
  }))
126
125
  end
127
126
  @options = Lookbook.config.page_options.deep_merge(frontmatter).with_indifferent_access
128
- @options[:id] = @options[:id] ? generate_id(@options[:id]) : generate_id(lookup_path)
127
+ @options[:id] = generate_id(@options[:id] || lookup_path)
129
128
  @options[:label] ||= name.titleize
130
129
  @options[:title] ||= @options[:label]
131
130
  @options[:hidden] ||= false
@@ -159,7 +158,7 @@ module Lookbook
159
158
  end
160
159
 
161
160
  def all
162
- pages, sections =
161
+ pages, sections =
163
162
  Array(page_paths).flat_map do |dir|
164
163
  Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort.map do |path|
165
164
  create(path, dir)
@@ -172,7 +171,7 @@ module Lookbook
172
171
 
173
172
  page_dict = sorted_pages.index_by(&:path)
174
173
  sorted_sections = sections.sort_by { |section| [section.position, section.label] }
175
-
174
+
176
175
  sorted_sections.each do |section|
177
176
  page_dict[section.path].sections << section
178
177
  end
@@ -1,6 +1,5 @@
1
1
  module Lookbook
2
2
  class PageSection < Page
3
-
4
3
  def name
5
4
  return @name if @name.present?
6
5
  matches = full_path.to_s.match(%r{\[(?<name>\w+)\]})
@@ -24,8 +23,7 @@ module Lookbook
24
23
  end
25
24
 
26
25
  def lookup_path
27
- "#{super}/#{name}"
26
+ "#{super}/#{name}"
28
27
  end
29
-
30
28
  end
31
- end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Lookbook
2
+ module Panels
3
+ def define_panel(name, opts = {})
4
+ Lookbook.config.define_inspector_panel(name, opts)
5
+ end
6
+
7
+ def amend_panel(name, opts = {})
8
+ Lookbook.amend_inspector_panel(name, opts)
9
+ end
10
+
11
+ def remove_panel(name)
12
+ Lookbook.remove_inspector_panel(name)
13
+ end
14
+ end
15
+ end
@@ -63,6 +63,14 @@ module Lookbook
63
63
  result = []
64
64
  end
65
65
  result
66
+ when "datetime"
67
+ begin
68
+ result = DateTime.parse(value)
69
+ rescue Date::Error
70
+ Lookbook.logger.debug "Failed to parse '#{value}' into a DateTime"
71
+ result = DateTime.now
72
+ end
73
+ result
66
74
  else
67
75
  begin
68
76
  type_class = "ActiveModel::Type::#{type}".constantize
@@ -92,6 +100,8 @@ module Lookbook
92
100
  "Boolean"
93
101
  elsif default.is_a? Symbol
94
102
  "Symbol"
103
+ elsif ["date", "datetime-local"].include?(input&.downcase) || default.is_a?(DateTime)
104
+ "DateTime"
95
105
  else
96
106
  "String"
97
107
  end
@@ -99,6 +109,8 @@ module Lookbook
99
109
 
100
110
  def input_text?(input)
101
111
  [
112
+ "date",
113
+ "datetime-local",
102
114
  "email",
103
115
  "number",
104
116
  "tel",
@@ -24,13 +24,16 @@ module Lookbook
24
24
  end
25
25
 
26
26
  class << self
27
- def define_tags
27
+ def define_tags(custom = {})
28
28
  YARD::Tags::Library.define_tag("Hidden status", :hidden)
29
29
  YARD::Tags::Library.define_tag("Label", :label)
30
30
  YARD::Tags::Library.define_tag("Display", :display)
31
31
  YARD::Tags::Library.define_tag("Position", :position)
32
32
  YARD::Tags::Library.define_tag("ID", :id)
33
33
  YARD::Tags::Library.define_tag("Component", :component)
34
+ custom.each do |name, opts|
35
+ YARD::Tags::Library.define_tag(name.to_s.titleize, name)
36
+ end
34
37
  end
35
38
  end
36
39
  end
@@ -3,7 +3,7 @@ module Lookbook
3
3
  include Utils
4
4
 
5
5
  delegate :name, :render_args, to: :@preview
6
- delegate :position, :group, :notes, :hidden?, to: :@preview_inspector
6
+ delegate :position, :group, :notes, :hidden?, :tags, :tag, to: :@preview_inspector
7
7
 
8
8
  def initialize(preview)
9
9
  @preview = preview
@@ -97,7 +97,7 @@ module Lookbook
97
97
  end
98
98
 
99
99
  def components
100
- component_classes = @preview_inspector&.components.any? ? @preview_inspector&.components : [guess_component]
100
+ component_classes = @preview_inspector&.components&.any? ? @preview_inspector&.components : [guess_component]
101
101
  component_classes.map do |class_name|
102
102
  Component.new(class_name.to_s)
103
103
  end
@@ -106,11 +106,9 @@ module Lookbook
106
106
  protected
107
107
 
108
108
  def guess_component
109
- begin
110
- name.chomp("Preview").constantize
111
- rescue
112
- nil
113
- end
109
+ name.chomp("Preview").constantize
110
+ rescue
111
+ nil
114
112
  end
115
113
 
116
114
  class << self
@@ -156,7 +154,7 @@ module Lookbook
156
154
 
157
155
  def clear_cache
158
156
  cache_dir = File.dirname(cache_marker_path)
159
- FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
157
+ FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
160
158
  File.write(cache_marker_path, Time.now.to_i)
161
159
  end
162
160
 
@@ -167,7 +165,7 @@ module Lookbook
167
165
  end
168
166
 
169
167
  def cache_stale?
170
- return false if !File.exists?(cache_marker_path)
168
+ return false if !File.exist?(cache_marker_path)
171
169
  cache_timestamp = File.read(cache_marker_path).to_i
172
170
  if @last_cache_timestamp.nil? || cache_timestamp > @last_cache_timestamp
173
171
  @last_cache_timestamp = cache_timestamp
@@ -179,7 +177,7 @@ module Lookbook
179
177
 
180
178
  def mark_as_cached
181
179
  cache_dir = File.dirname(cache_marker_path)
182
- FileUtils.mkdir_p(cache_dir) unless File.exists?(cache_dir)
180
+ FileUtils.mkdir_p(cache_dir) unless File.exist?(cache_dir)
183
181
  File.write(cache_marker_path, Time.now)
184
182
  end
185
183
 
@@ -196,7 +194,7 @@ module Lookbook
196
194
  )
197
195
  end
198
196
  end
199
-
197
+
200
198
  def preview_files
201
199
  files = Array(Lookbook.config.preview_paths).map do |preview_path|
202
200
  Dir["#{preview_path}/**/*preview.rb"].map do |path|