lookbook 0.9.8 → 1.0.0.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -849
- data/app/assets/lookbook/css/lookbook.css +55 -0
- data/app/assets/lookbook/css/themes/blue.css +42 -0
- data/app/assets/lookbook/css/themes/indigo.css +42 -0
- data/app/assets/lookbook/css/themes/zinc.css +42 -0
- data/app/assets/lookbook/css/{tooltip_theme.css → tooltip.css} +14 -8
- data/app/assets/lookbook/js/app.js +64 -63
- data/app/assets/lookbook/js/components/clipboard.js +47 -0
- data/app/assets/lookbook/js/components/tooltip.js +30 -0
- data/app/assets/lookbook/js/config.js +7 -4
- data/app/assets/lookbook/js/helpers/build.js +22 -0
- data/app/assets/lookbook/js/helpers/dom.js +45 -0
- data/app/assets/lookbook/js/helpers/layout.js +21 -0
- data/app/assets/lookbook/js/helpers/request.js +16 -0
- data/app/assets/lookbook/js/helpers/string.js +11 -0
- data/app/assets/lookbook/js/lib/socket.js +4 -3
- data/app/assets/lookbook/js/lib/tippy.js +8 -0
- data/app/assets/lookbook/js/lookbook.js +61 -0
- data/app/assets/lookbook/js/plugins/logger.js +39 -0
- data/app/assets/lookbook/js/stores/filter.js +2 -2
- data/app/assets/lookbook/js/stores/inspector.js +22 -16
- data/app/assets/lookbook/js/stores/layout.js +101 -5
- data/app/assets/lookbook/js/stores/nav.js +17 -16
- data/app/assets/lookbook/js/stores/pages.js +4 -2
- data/app/assets/lookbook/js/stores/settings.js +7 -0
- data/app/assets/lookbook/js/stores/workbench.js +29 -0
- data/app/components/lookbook/button/component.html.erb +28 -0
- data/app/components/lookbook/button/component.js +55 -0
- data/app/components/lookbook/button/component.rb +39 -0
- data/app/components/lookbook/button_group/component.html.erb +3 -0
- data/app/components/lookbook/button_group/component.rb +18 -0
- data/app/components/lookbook/code/component.css +57 -0
- data/app/components/lookbook/code/component.html.erb +10 -0
- data/app/components/lookbook/code/component.js +3 -0
- data/app/components/lookbook/code/component.rb +56 -0
- data/app/components/lookbook/code/highlight_github_light.css +217 -0
- data/app/components/lookbook/component.rb +41 -0
- data/app/components/lookbook/copy_button/component.html.erb +11 -0
- data/app/components/lookbook/copy_button/component.js +16 -0
- data/app/components/lookbook/copy_button/component.rb +23 -0
- data/app/components/lookbook/dimensions_display/component.html.erb +10 -0
- data/app/components/lookbook/dimensions_display/component.js +30 -0
- data/app/components/lookbook/dimensions_display/component.rb +18 -0
- data/app/components/lookbook/embed/component.html.erb +50 -0
- data/app/components/lookbook/embed/component.js +39 -0
- data/app/components/lookbook/embed/component.rb +22 -0
- data/app/components/lookbook/filter/component.html.erb +17 -0
- data/app/components/lookbook/filter/component.js +21 -0
- data/app/components/lookbook/filter/component.rb +15 -0
- data/app/components/lookbook/header/component.html.erb +79 -0
- data/app/components/lookbook/header/component.rb +9 -0
- data/app/components/lookbook/icon/component.css +11 -0
- data/app/components/lookbook/icon/component.html.erb +5 -0
- data/app/components/lookbook/icon/component.js +5 -0
- data/app/components/lookbook/icon/component.rb +23 -0
- data/app/components/lookbook/nav/component.html.erb +33 -0
- data/app/components/lookbook/nav/component.js +52 -0
- data/app/components/lookbook/nav/component.rb +37 -0
- data/app/components/lookbook/nav/item/component.html.erb +23 -0
- data/app/components/lookbook/nav/item/component.js +66 -0
- data/app/components/lookbook/nav/item/component.rb +84 -0
- data/app/components/lookbook/params_editor/component.html.erb +3 -0
- data/app/components/lookbook/params_editor/component.js +12 -0
- data/app/components/lookbook/params_editor/component.rb +11 -0
- data/app/components/lookbook/params_editor/field/component.html.erb +50 -0
- data/app/components/lookbook/params_editor/field/component.js +36 -0
- data/app/components/lookbook/params_editor/field/component.rb +41 -0
- data/app/components/lookbook/prose/component.css +12 -0
- data/app/components/lookbook/prose/component.html.erb +3 -0
- data/app/components/lookbook/prose/component.rb +26 -0
- data/app/components/lookbook/split_layout/component.html.erb +13 -0
- data/app/components/lookbook/split_layout/component.js +151 -0
- data/app/components/lookbook/split_layout/component.rb +11 -0
- data/app/components/lookbook/tabbed_content/component.html.erb +5 -0
- data/app/components/lookbook/tabbed_content/component.js +21 -0
- data/app/components/lookbook/tabbed_content/component.rb +20 -0
- data/app/components/lookbook/tabbed_content/section/component.html.erb +8 -0
- data/app/components/lookbook/tabbed_content/section/component.rb +9 -0
- data/app/components/lookbook/tabs/component.css +8 -0
- data/app/components/lookbook/tabs/component.html.erb +14 -0
- data/app/components/lookbook/tabs/component.js +107 -0
- data/app/components/lookbook/tabs/component.rb +30 -0
- data/app/components/lookbook/tabs/dropdown_tab/component.html.erb +14 -0
- data/app/components/lookbook/tabs/dropdown_tab/component.rb +16 -0
- data/app/components/lookbook/tabs/tab/component.html.erb +18 -0
- data/app/components/lookbook/tabs/tab/component.rb +16 -0
- data/app/components/lookbook/tag_component.rb +29 -0
- data/app/components/lookbook/toolbar/component.css +16 -0
- data/app/components/lookbook/toolbar/component.html.erb +5 -0
- data/app/components/lookbook/toolbar/component.rb +26 -0
- data/app/components/lookbook/viewport/component.css +11 -0
- data/app/components/lookbook/viewport/component.html.erb +57 -0
- data/app/{assets/lookbook/js/components/preview-window.js → components/lookbook/viewport/component.js} +57 -14
- data/app/components/lookbook/viewport/component.rb +21 -0
- data/app/controllers/lookbook/application_controller.rb +16 -9
- data/app/controllers/lookbook/pages_controller.rb +18 -11
- data/app/controllers/lookbook/previews_controller.rb +62 -25
- data/app/helpers/lookbook/application_helper.rb +7 -3
- data/app/helpers/lookbook/component_helper.rb +22 -10
- data/app/helpers/lookbook/output_helper.rb +8 -4
- data/app/helpers/lookbook/page_helper.rb +13 -21
- data/app/views/layouts/lookbook/application.html.erb +76 -28
- data/app/views/layouts/lookbook/inspector.html.erb +7 -0
- data/app/views/layouts/lookbook/page.html.erb +53 -0
- data/app/views/layouts/lookbook/shell.html.erb +64 -0
- data/app/views/layouts/lookbook/skeleton.html.erb +27 -10
- data/app/views/layouts/lookbook/standalone.html.erb +5 -0
- data/app/views/lookbook/404.html.erb +15 -0
- data/app/views/lookbook/error.html.erb +34 -34
- data/app/views/lookbook/index.html.erb +11 -6
- data/app/views/lookbook/pages/show.html.erb +29 -93
- data/app/views/{layouts/lookbook → lookbook}/preview.html.erb +3 -5
- data/app/views/lookbook/previews/panels/_notes.html.erb +19 -25
- data/app/views/lookbook/previews/panels/_output.html.erb +7 -18
- data/app/views/lookbook/previews/panels/_params.html.erb +13 -15
- data/app/views/lookbook/previews/panels/_preview.html.erb +6 -52
- data/app/views/lookbook/previews/panels/_source.html.erb +7 -16
- data/app/views/lookbook/previews/show.html.erb +130 -24
- data/config/routes.rb +7 -7
- data/lib/lookbook/code_formatter.rb +37 -13
- data/lib/lookbook/collection.rb +19 -16
- data/lib/lookbook/config.rb +125 -0
- data/lib/lookbook/engine.rb +74 -87
- data/lib/lookbook/entity.rb +47 -0
- data/lib/lookbook/error.rb +1 -2
- data/lib/lookbook/features.rb +1 -1
- data/lib/lookbook/markdown.rb +3 -5
- data/lib/lookbook/page.rb +26 -43
- data/lib/lookbook/page_collection.rb +8 -0
- data/lib/lookbook/params.rb +14 -15
- data/lib/lookbook/parser.rb +4 -0
- data/lib/lookbook/preview.rb +16 -7
- data/lib/lookbook/preview_collection.rb +8 -0
- data/lib/lookbook/preview_controller.rb +6 -2
- data/lib/lookbook/preview_example.rb +5 -6
- data/lib/lookbook/preview_group.rb +4 -9
- data/lib/lookbook/{code_inspector.rb → source_inspector.rb} +2 -2
- data/lib/lookbook/theme.rb +22 -0
- data/lib/lookbook/utils.rb +11 -3
- data/lib/lookbook/version.rb +1 -1
- data/lib/lookbook.rb +4 -1
- data/lib/tasks/lookbook_tasks.rake +13 -1
- data/public/lookbook-assets/css/app.css +2340 -1
- data/public/lookbook-assets/css/app.css.map +11 -1
- data/public/lookbook-assets/css/lookbook.css +3040 -0
- data/public/lookbook-assets/css/lookbook.css.map +1 -0
- data/public/lookbook-assets/css/themes/blue.css +44 -0
- data/public/lookbook-assets/css/themes/blue.css.map +1 -0
- data/public/lookbook-assets/css/themes/indigo.css +44 -0
- data/public/lookbook-assets/css/themes/indigo.css.map +1 -0
- data/public/lookbook-assets/css/themes/zinc.css +44 -0
- data/public/lookbook-assets/css/themes/zinc.css.map +1 -0
- data/public/lookbook-assets/js/app.js +10861 -1
- data/public/lookbook-assets/js/app.js.map +2571 -1
- data/public/lookbook-assets/js/embed.js +895 -1
- data/public/lookbook-assets/js/embed.js.map +1 -1
- data/public/lookbook-assets/js/lookbook.js +13529 -0
- data/public/lookbook-assets/js/lookbook.js.map +1 -0
- metadata +128 -116
- data/app/assets/lookbook/css/app.css +0 -161
- data/app/assets/lookbook/css/code_theme.css +0 -214
- data/app/assets/lookbook/js/components/app.js +0 -55
- data/app/assets/lookbook/js/components/code.js +0 -5
- data/app/assets/lookbook/js/components/copy.js +0 -20
- data/app/assets/lookbook/js/components/embed.js +0 -89
- data/app/assets/lookbook/js/components/filter.js +0 -35
- data/app/assets/lookbook/js/components/inspector.js +0 -66
- data/app/assets/lookbook/js/components/nav-group.js +0 -47
- data/app/assets/lookbook/js/components/nav-item.js +0 -29
- data/app/assets/lookbook/js/components/nav.js +0 -28
- data/app/assets/lookbook/js/components/page-tabs.js +0 -9
- data/app/assets/lookbook/js/components/page.js +0 -25
- data/app/assets/lookbook/js/components/param.js +0 -34
- data/app/assets/lookbook/js/components/sidebar.js +0 -18
- data/app/assets/lookbook/js/components/sizes.js +0 -16
- data/app/assets/lookbook/js/components/splitter.js +0 -25
- data/app/assets/lookbook/js/components/tabs.js +0 -52
- data/app/assets/lookbook/js/lib/split.js +0 -15
- data/app/assets/lookbook/js/stores/sidebar.js +0 -26
- data/app/views/layouts/lookbook/basic.html.erb +0 -7
- data/app/views/lookbook/components/_branding.html.erb +0 -8
- data/app/views/lookbook/components/_code.html.erb +0 -17
- data/app/views/lookbook/components/_copy_button.html.erb +0 -11
- data/app/views/lookbook/components/_drawer.html.erb +0 -112
- data/app/views/lookbook/components/_embed.html.erb +0 -39
- data/app/views/lookbook/components/_errors.html.erb +0 -13
- data/app/views/lookbook/components/_filter.html.erb +0 -18
- data/app/views/lookbook/components/_header.html.erb +0 -6
- data/app/views/lookbook/components/_icon.html.erb +0 -5
- data/app/views/lookbook/components/_nav.html.erb +0 -16
- data/app/views/lookbook/components/_nav_collection.html.erb +0 -5
- data/app/views/lookbook/components/_nav_group.html.erb +0 -14
- data/app/views/lookbook/components/_nav_item.html.erb +0 -24
- data/app/views/lookbook/components/_nav_page.html.erb +0 -22
- data/app/views/lookbook/components/_nav_preview.html.erb +0 -13
- data/app/views/lookbook/components/_not_found.html.erb +0 -11
- data/app/views/lookbook/components/_param.html.erb +0 -21
- data/app/views/lookbook/components/_preview.html.erb +0 -77
- data/app/views/lookbook/components/_sidebar.html.erb +0 -69
- data/app/views/lookbook/pages/not_found.html.erb +0 -15
- data/app/views/lookbook/previews/error.html.erb +0 -1
- data/app/views/lookbook/previews/inputs/_select.html.erb +0 -7
- data/app/views/lookbook/previews/inputs/_text.html.erb +0 -8
- data/app/views/lookbook/previews/inputs/_textarea.html.erb +0 -8
- data/app/views/lookbook/previews/inputs/_toggle.html.erb +0 -13
- data/app/views/lookbook/previews/not_found.html.erb +0 -23
data/lib/lookbook/engine.rb
CHANGED
@@ -2,71 +2,53 @@ require "rails"
|
|
2
2
|
require "view_component"
|
3
3
|
require "action_cable/engine"
|
4
4
|
require "listen"
|
5
|
-
require "rake"
|
6
5
|
|
7
6
|
module Lookbook
|
7
|
+
|
8
|
+
autoload :Config, "lookbook/config"
|
9
|
+
|
8
10
|
class << self
|
9
11
|
def config
|
10
|
-
@config ||=
|
12
|
+
@config ||= Config.new
|
11
13
|
end
|
12
14
|
|
13
15
|
def logger
|
14
|
-
@logger ||= Rails.logger
|
16
|
+
@logger ||= Rails.env.development? ? Logger.new($stdout) : Rails.logger
|
15
17
|
end
|
16
18
|
|
17
19
|
def version
|
18
20
|
Lookbook::VERSION
|
19
21
|
end
|
22
|
+
|
23
|
+
def debug_data
|
24
|
+
{
|
25
|
+
version: version,
|
26
|
+
env: Rails.env.to_s,
|
27
|
+
config: config
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure
|
32
|
+
yield(config)
|
33
|
+
end
|
20
34
|
end
|
21
35
|
|
22
36
|
class Engine < Rails::Engine
|
23
37
|
isolate_namespace Lookbook
|
24
38
|
|
25
|
-
config.lookbook =
|
26
|
-
config.
|
27
|
-
config.lookbook.listen_extensions ||= []
|
28
|
-
config.lookbook.preview_paths ||= []
|
29
|
-
config.lookbook.page_paths ||= ["test/components/docs"]
|
30
|
-
|
31
|
-
initializer "view_component.set_configs" do
|
32
|
-
options = config.lookbook
|
33
|
-
vc_options = config.view_component
|
34
|
-
|
35
|
-
options.project_name ||= options.project_name == false ? nil : options.project_name || "Lookbook"
|
36
|
-
options.auto_refresh = true if options.auto_refresh.nil?
|
37
|
-
options.sort_examples = false if options.sort_examples.nil?
|
38
|
-
options.debug = false unless options.debug == true
|
39
|
-
|
40
|
-
options.preview_paths = options.preview_paths.map(&:to_s)
|
41
|
-
options.preview_paths += vc_options.preview_paths
|
42
|
-
|
43
|
-
options.page_paths = options.page_paths.map(&:to_s)
|
44
|
-
options.page_controller = "Lookbook::PageController" if options.page_controller.nil?
|
45
|
-
options.page_route ||= "pages"
|
46
|
-
options.page_options ||= {}.with_indifferent_access
|
47
|
-
|
48
|
-
options.markdown_options = Markdown::DEFAULT_OPTIONS.merge(options.markdown_options || {})
|
39
|
+
config.lookbook = Lookbook.config
|
40
|
+
config.autoload_paths << File.expand_path(Lookbook::Engine.root.join("app/components"))
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
initializer "lookbook.viewcomponent.config" do
|
43
|
+
config.lookbook.preview_paths += config.view_component.preview_paths
|
44
|
+
config.lookbook.preview_controller ||= config.view_component.preview_controller
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
options.listen_paths << (vc_options.view_component_path || Rails.root.join("app/components"))
|
58
|
-
options.listen_paths.select! { |path| Dir.exist? path }
|
59
|
-
|
60
|
-
options.listen_extensions += ["rb", "html.*"]
|
61
|
-
options.listen_extensions.uniq!
|
62
|
-
|
63
|
-
options.cable_mount_path ||= "/lookbook-cable"
|
64
|
-
options.cable_logger ||= Rails.logger
|
65
|
-
|
66
|
-
options.runtime_parsing = !Rails.env.production? if options.runtime_parsing.nil?
|
67
|
-
options.parser_registry_path ||= Rails.root.join("tmp/storage/.yardoc")
|
46
|
+
config.lookbook.listen_paths += config.lookbook.preview_paths
|
47
|
+
config.lookbook.listen_paths << (config.view_component.view_component_path.presence || "app/components")
|
48
|
+
end
|
68
49
|
|
69
|
-
|
50
|
+
initializer "lookbook.logging.development" do
|
51
|
+
Lookbook.logger.level = Lookbook.config.log_level if Rails.env.development?
|
70
52
|
end
|
71
53
|
|
72
54
|
initializer "lookbook.parser.tags" do
|
@@ -84,20 +66,34 @@ module Lookbook
|
|
84
66
|
@preview_controller = Lookbook.config.preview_controller.constantize
|
85
67
|
@preview_controller.include(Lookbook::PreviewController)
|
86
68
|
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
69
|
+
if config.lookbook.listen
|
70
|
+
Listen.logger = Lookbook.logger
|
71
|
+
preview_listener = Listen.to(
|
72
|
+
*config.lookbook.listen_paths,
|
73
|
+
only: /\.(rb|html.*)$/,
|
74
|
+
force_polling: Lookbook.config.listen_use_polling
|
75
|
+
) do |modified, added, removed|
|
76
|
+
begin
|
77
|
+
parser.parse
|
78
|
+
rescue
|
79
|
+
end
|
80
|
+
Lookbook::Preview.clear_cache
|
81
|
+
Lookbook::Engine.websocket&.broadcast("reload", {})
|
91
82
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
83
|
+
Lookbook::Engine.register_listener(preview_listener)
|
84
|
+
|
85
|
+
page_listener = Listen.to(
|
86
|
+
*config.lookbook.page_paths,
|
87
|
+
only: /\.(html.*|md.*)$/,
|
88
|
+
force_polling: Lookbook.config.listen_use_polling
|
89
|
+
) do |modified, added, removed|
|
90
|
+
Lookbook::Engine.websocket&.broadcast("reload", {})
|
96
91
|
end
|
92
|
+
Lookbook::Engine.register_listener(page_listener)
|
97
93
|
end
|
98
94
|
|
99
95
|
if config.lookbook.runtime_parsing
|
100
|
-
|
96
|
+
parser.parse
|
101
97
|
else
|
102
98
|
unless File.exist?(config.lookbook.parser_registry_path)
|
103
99
|
Lookbook.logger.warn "
|
@@ -109,43 +105,17 @@ module Lookbook
|
|
109
105
|
end
|
110
106
|
end
|
111
107
|
|
112
|
-
|
108
|
+
at_exit do
|
113
109
|
if config.lookbook.listen
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
rescue
|
118
|
-
end
|
119
|
-
Lookbook::Preview.clear_cache
|
120
|
-
Lookbook::Engine.websocket&.broadcast("reload", {
|
121
|
-
modified: modified,
|
122
|
-
removed: removed,
|
123
|
-
added: added
|
124
|
-
})
|
125
|
-
end
|
126
|
-
@preview_listener.start
|
127
|
-
|
128
|
-
if Lookbook::Features.enabled?(:pages)
|
129
|
-
@page_listener = Listen.to(*config.lookbook.page_paths.select { |dir| Dir.exist? dir }, only: /\.(html.*|md.*)$/) do |modified, added, removed|
|
130
|
-
Lookbook::Engine.websocket&.broadcast("reload", {
|
131
|
-
modified: modified,
|
132
|
-
removed: removed,
|
133
|
-
added: added
|
134
|
-
})
|
135
|
-
end
|
136
|
-
@page_listener.start
|
110
|
+
Lookbook.logger.debug "Stopping listeners"
|
111
|
+
Lookbook::Engine.listeners.each do |listener|
|
112
|
+
listener.stop
|
137
113
|
end
|
138
114
|
end
|
139
115
|
end
|
140
116
|
|
141
|
-
at_exit do
|
142
|
-
@preview_listener&.stop
|
143
|
-
@page_listener&.stop
|
144
|
-
end
|
145
|
-
|
146
117
|
class << self
|
147
118
|
def websocket
|
148
|
-
return @websocket unless @websocket.nil?
|
149
119
|
if config.lookbook.auto_refresh
|
150
120
|
cable = ActionCable::Server::Configuration.new
|
151
121
|
cable.cable = {adapter: "async"}.with_indifferent_access
|
@@ -156,9 +126,9 @@ module Lookbook
|
|
156
126
|
@websocket ||= if Rails.version.to_f >= 6.0
|
157
127
|
ActionCable::Server::Base.new(config: cable)
|
158
128
|
else
|
159
|
-
|
160
|
-
|
161
|
-
|
129
|
+
websocket ||= ActionCable::Server::Base.new
|
130
|
+
websocket.config = cable
|
131
|
+
websocket
|
162
132
|
end
|
163
133
|
end
|
164
134
|
end
|
@@ -175,6 +145,23 @@ module Lookbook
|
|
175
145
|
@parser ||= Lookbook::Parser.new(config.lookbook.preview_paths, config.lookbook.parser_registry_path)
|
176
146
|
end
|
177
147
|
|
148
|
+
def log_level
|
149
|
+
Lookbook.logger.level
|
150
|
+
end
|
151
|
+
|
152
|
+
def app_name
|
153
|
+
Rails.application.class.module_parent_name.underscore
|
154
|
+
end
|
155
|
+
|
156
|
+
def register_listener(listener)
|
157
|
+
listener.start
|
158
|
+
listeners << listener
|
159
|
+
end
|
160
|
+
|
161
|
+
def listeners
|
162
|
+
@listeners ||= []
|
163
|
+
end
|
164
|
+
|
178
165
|
attr_reader :preview_controller
|
179
166
|
end
|
180
167
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Lookbook
|
2
|
+
class Entity
|
3
|
+
include Utils
|
4
|
+
|
5
|
+
def initialize(reference_path)
|
6
|
+
@refpath = reference_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
generate_id(lookup_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def label
|
14
|
+
lookup_path.split("/").last.titleize
|
15
|
+
end
|
16
|
+
|
17
|
+
def type
|
18
|
+
:item
|
19
|
+
end
|
20
|
+
|
21
|
+
def path
|
22
|
+
@refpath
|
23
|
+
end
|
24
|
+
|
25
|
+
def lookup_path
|
26
|
+
@lookup_path ||= to_lookup_path(@refpath)
|
27
|
+
end
|
28
|
+
|
29
|
+
def hierarchy_depth
|
30
|
+
@refpath.present? ? @refpath.split("/").size : 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def position
|
34
|
+
0
|
35
|
+
end
|
36
|
+
|
37
|
+
def hidden?
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
def matchers
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method :url_path, :lookup_path
|
46
|
+
end
|
47
|
+
end
|
data/lib/lookbook/error.rb
CHANGED
data/lib/lookbook/features.rb
CHANGED
data/lib/lookbook/markdown.rb
CHANGED
@@ -12,7 +12,6 @@ module Lookbook
|
|
12
12
|
}
|
13
13
|
|
14
14
|
def self.render(text)
|
15
|
-
text&.gsub!("<!-- BEGIN inline template -->", "")&.gsub!("<!-- END inline template -->", "")
|
16
15
|
markdown = Redcarpet::Markdown.new(Renderer, Lookbook.config.markdown_options)
|
17
16
|
markdown.render(text).html_safe
|
18
17
|
end
|
@@ -20,12 +19,11 @@ module Lookbook
|
|
20
19
|
class Renderer < Redcarpet::Render::HTML
|
21
20
|
def block_code(code, language = "ruby")
|
22
21
|
line_numbers = language.to_s.end_with? "-numbered"
|
23
|
-
ApplicationController.render
|
24
|
-
|
22
|
+
ApplicationController.render(Lookbook::Code::Component.new(**{
|
23
|
+
source: code,
|
25
24
|
language: language.to_s.chomp("-numbered"),
|
26
25
|
line_numbers: line_numbers
|
27
|
-
},
|
28
|
-
layout: nil
|
26
|
+
}), layout: nil)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
data/lib/lookbook/page.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Lookbook
|
2
|
-
class Page
|
3
|
-
include Utils
|
2
|
+
class Page < Entity
|
4
3
|
|
5
4
|
FRONTMATTER_FIELDS = [
|
6
5
|
:id,
|
@@ -16,26 +15,19 @@ module Lookbook
|
|
16
15
|
]
|
17
16
|
|
18
17
|
attr_reader :errors
|
19
|
-
attr_accessor :tabs
|
20
18
|
|
21
19
|
def initialize(path, base_path)
|
22
20
|
@pathname = Pathname.new path
|
23
|
-
@base_path =
|
21
|
+
@base_path = base_path
|
24
22
|
@options = nil
|
25
23
|
@errors = []
|
26
|
-
@tabs = []
|
27
|
-
end
|
28
|
-
|
29
|
-
def path
|
30
24
|
rel_path = @pathname.relative_path_from(@base_path)
|
31
|
-
|
32
|
-
|
33
|
-
_path.gsub!("[#{tab}]", "") if tab?
|
34
|
-
_path
|
25
|
+
page_path = (rel_path.dirname.to_s == "." ? name : "#{rel_path.dirname}/#{name}")
|
26
|
+
super(page_path)
|
35
27
|
end
|
36
28
|
|
37
|
-
def
|
38
|
-
|
29
|
+
def url_path
|
30
|
+
page_path lookup_path
|
39
31
|
end
|
40
32
|
|
41
33
|
def full_path
|
@@ -74,25 +66,28 @@ module Lookbook
|
|
74
66
|
normalize_matchers(label)
|
75
67
|
end
|
76
68
|
|
77
|
-
def hierarchy_depth
|
78
|
-
path.split("/").size
|
79
|
-
end
|
80
|
-
|
81
69
|
def parent_collections_names
|
82
70
|
File.dirname(path).split("/")
|
83
71
|
end
|
84
72
|
|
85
73
|
def type
|
86
|
-
|
74
|
+
:page
|
87
75
|
end
|
88
76
|
|
89
|
-
def
|
90
|
-
|
91
|
-
matches ? remove_position_prefix(matches[:tab]) : nil
|
77
|
+
def id
|
78
|
+
options[:id]
|
92
79
|
end
|
93
80
|
|
94
|
-
def
|
95
|
-
|
81
|
+
def position
|
82
|
+
options[:position]
|
83
|
+
end
|
84
|
+
|
85
|
+
def hidden
|
86
|
+
options[:hidden]
|
87
|
+
end
|
88
|
+
|
89
|
+
def label
|
90
|
+
options[:label]
|
96
91
|
end
|
97
92
|
|
98
93
|
def method_missing(method_name, *args, &block)
|
@@ -128,7 +123,7 @@ module Lookbook
|
|
128
123
|
end
|
129
124
|
@options = Lookbook.config.page_options.deep_merge(frontmatter).with_indifferent_access
|
130
125
|
@options[:id] = @options[:id] ? generate_id(@options[:id]) : generate_id(lookup_path)
|
131
|
-
@options[:label] ||=
|
126
|
+
@options[:label] ||= name.titleize
|
132
127
|
@options[:title] ||= @options[:label]
|
133
128
|
@options[:hidden] ||= false
|
134
129
|
@options[:landing] ||= false
|
@@ -157,29 +152,17 @@ module Lookbook
|
|
157
152
|
end
|
158
153
|
|
159
154
|
def all
|
160
|
-
pages
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
165
|
-
end.partition { |page| page.type == :page }
|
166
|
-
|
167
|
-
sorted_pages = pages
|
168
|
-
.uniq { |page| page.path }
|
169
|
-
.sort_by { |page| [page.position, page.label] }
|
170
|
-
|
171
|
-
page_dict = sorted_pages.index_by(&:path)
|
172
|
-
sorted_tabs = tabs.sort_by { |tab| [tab.position, tab.label] }
|
173
|
-
|
174
|
-
sorted_tabs.each do |tab|
|
175
|
-
page_dict[tab.path].tabs << tab
|
155
|
+
pages = Array(page_paths).map do |dir|
|
156
|
+
Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort.map do |page|
|
157
|
+
Lookbook::Page.new(page, dir)
|
158
|
+
end
|
176
159
|
end
|
177
|
-
|
160
|
+
sorted_pages = pages.flatten.uniq { |p| p.path }.sort_by { |page| [page.position, page.label] }
|
178
161
|
PageCollection.new(sorted_pages)
|
179
162
|
end
|
180
163
|
|
181
164
|
def page_paths
|
182
|
-
Lookbook.config.page_paths.
|
165
|
+
Lookbook.config.page_paths.filter { |dir| Dir.exist? dir }
|
183
166
|
end
|
184
167
|
end
|
185
168
|
end
|
data/lib/lookbook/params.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
+
require "active_model"
|
2
|
+
|
1
3
|
module Lookbook
|
2
4
|
module Params
|
3
5
|
class << self
|
4
|
-
def build_param(param, default)
|
6
|
+
def build_param(param, default: nil, **opts)
|
5
7
|
input, options_str = param.text.present? ? param.text.split(" ", 2) : [nil, ""]
|
6
8
|
type = param.types&.first
|
7
|
-
options =
|
9
|
+
options = if options_str.present? && options_str.end_with?(".json")
|
10
|
+
json_path = if options_str.start_with?(".")
|
11
|
+
File.expand_path(options_str, File.dirname(param.object.files.first[0]))
|
12
|
+
else
|
13
|
+
Rails.root.join(options_str)
|
14
|
+
end
|
15
|
+
JSON.parse(File.read(json_path))
|
16
|
+
else
|
17
|
+
YAML.safe_load(options_str || "~")
|
18
|
+
end
|
8
19
|
input ||= guess_input(type, default)
|
9
20
|
type ||= guess_type(input, default)
|
10
21
|
{
|
@@ -52,14 +63,6 @@ module Lookbook
|
|
52
63
|
result = []
|
53
64
|
end
|
54
65
|
result
|
55
|
-
when "datetime"
|
56
|
-
begin
|
57
|
-
result = DateTime.parse(value)
|
58
|
-
rescue Date::Error
|
59
|
-
Lookbook.logger.debug "Failed to parse '#{value}' into a DateTime"
|
60
|
-
result = DateTime.now
|
61
|
-
end
|
62
|
-
result
|
63
66
|
else
|
64
67
|
begin
|
65
68
|
type_class = "ActiveModel::Type::#{type}".constantize
|
@@ -89,8 +92,6 @@ module Lookbook
|
|
89
92
|
"Boolean"
|
90
93
|
elsif default.is_a? Symbol
|
91
94
|
"Symbol"
|
92
|
-
elsif ["date", "datetime-local"].include?(input&.downcase) || default.is_a?(DateTime)
|
93
|
-
"DateTime"
|
94
95
|
else
|
95
96
|
"String"
|
96
97
|
end
|
@@ -98,14 +99,12 @@ module Lookbook
|
|
98
99
|
|
99
100
|
def input_text?(input)
|
100
101
|
[
|
101
|
-
"date",
|
102
|
-
"datetime-local",
|
103
102
|
"email",
|
104
103
|
"number",
|
105
104
|
"tel",
|
106
105
|
"text",
|
107
106
|
"url"
|
108
|
-
].include? input
|
107
|
+
].include? input.to_s
|
109
108
|
end
|
110
109
|
|
111
110
|
def safe_parse_yaml(value, fallback)
|
data/lib/lookbook/parser.rb
CHANGED
data/lib/lookbook/preview.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Lookbook
|
2
|
-
class Preview
|
2
|
+
class Preview < Collection
|
3
3
|
include Utils
|
4
4
|
|
5
5
|
delegate :name, :render_args, to: :@preview
|
@@ -7,7 +7,8 @@ module Lookbook
|
|
7
7
|
|
8
8
|
def initialize(preview)
|
9
9
|
@preview = preview
|
10
|
-
@preview_inspector =
|
10
|
+
@preview_inspector = SourceInspector.new(@preview.name)
|
11
|
+
super(preview_class_name(preview_class_basename(@preview.name)))
|
11
12
|
end
|
12
13
|
|
13
14
|
def id
|
@@ -33,7 +34,7 @@ module Lookbook
|
|
33
34
|
def examples
|
34
35
|
return @examples if @examples.present?
|
35
36
|
public_methods = @preview.public_instance_methods(false)
|
36
|
-
public_method_objects = @preview_inspector&.methods&.
|
37
|
+
public_method_objects = @preview_inspector&.methods&.filter { |m| public_methods.include?(m.name) }
|
37
38
|
examples = (public_method_objects || []).map { |m| PreviewExample.new(m.name.to_s, self) }
|
38
39
|
sorted = Lookbook.config.sort_examples ? examples.sort_by(&:label) : examples
|
39
40
|
@examples = []
|
@@ -52,12 +53,12 @@ module Lookbook
|
|
52
53
|
@examples = @examples.compact
|
53
54
|
end
|
54
55
|
|
55
|
-
def
|
56
|
-
examples.
|
56
|
+
def items
|
57
|
+
examples.reject { |i| i.hidden? }
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
-
|
60
|
+
def default_example
|
61
|
+
examples.first
|
61
62
|
end
|
62
63
|
|
63
64
|
def full_path
|
@@ -67,6 +68,10 @@ module Lookbook
|
|
67
68
|
Pathname.new(Dir["#{base_path}/#{name.underscore}.rb"].first)
|
68
69
|
end
|
69
70
|
|
71
|
+
def url_path
|
72
|
+
inspect_path lookup_path
|
73
|
+
end
|
74
|
+
|
70
75
|
def preview_paths
|
71
76
|
ViewComponent::Base.preview_paths
|
72
77
|
end
|
@@ -87,6 +92,10 @@ module Lookbook
|
|
87
92
|
Lookbook.config.preview_display_params.deep_merge(@preview_inspector&.display_params)
|
88
93
|
end
|
89
94
|
|
95
|
+
def collapsible?
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
90
99
|
class << self
|
91
100
|
def find(path)
|
92
101
|
all.find { |p| p.lookup_path == path }
|
@@ -4,10 +4,18 @@ module Lookbook
|
|
4
4
|
generate_id("preview-collection", lookup_path || "root")
|
5
5
|
end
|
6
6
|
|
7
|
+
def label
|
8
|
+
"Previews"
|
9
|
+
end
|
10
|
+
|
7
11
|
def find_example(path)
|
8
12
|
Lookbook::PreviewExample.all.find { |e| e.lookup_path == path }
|
9
13
|
end
|
10
14
|
|
15
|
+
def type
|
16
|
+
:preview_collection
|
17
|
+
end
|
18
|
+
|
11
19
|
def self.describe_as
|
12
20
|
"previews"
|
13
21
|
end
|
@@ -14,9 +14,13 @@ module Lookbook
|
|
14
14
|
render html: render_to_string(template, **opts)
|
15
15
|
end
|
16
16
|
|
17
|
-
def render_in_layout_to_string(template, locals,
|
17
|
+
def render_in_layout_to_string(template, locals, **opts)
|
18
18
|
append_view_path Lookbook::Engine.root.join("app/views")
|
19
|
-
|
19
|
+
html = render_to_string(template, locals: locals, **determine_layout(opts[:layout]))
|
20
|
+
if opts[:append_html].present?
|
21
|
+
html += opts[:append_html]
|
22
|
+
end
|
23
|
+
render html: html
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
@@ -1,22 +1,21 @@
|
|
1
1
|
module Lookbook
|
2
|
-
class PreviewExample
|
3
|
-
include Utils
|
4
|
-
|
2
|
+
class PreviewExample < Entity
|
5
3
|
attr_reader :name, :preview
|
6
4
|
delegate :params, :position, :group, :notes, :hidden?, :source, to: :@example_inspector
|
7
5
|
|
8
6
|
def initialize(name, preview)
|
9
7
|
@name = name
|
10
8
|
@preview = preview
|
11
|
-
@example_inspector =
|
9
|
+
@example_inspector = SourceInspector.new("#{@preview.name}##{name}")
|
10
|
+
super("#{@preview.path}/#{name}")
|
12
11
|
end
|
13
12
|
|
14
13
|
def id
|
15
14
|
generate_id(@preview.id, name)
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def url_path
|
18
|
+
inspect_path lookup_path
|
20
19
|
end
|
21
20
|
|
22
21
|
def label
|
@@ -1,21 +1,16 @@
|
|
1
1
|
module Lookbook
|
2
|
-
class PreviewGroup
|
3
|
-
include Utils
|
4
|
-
|
2
|
+
class PreviewGroup < Entity
|
5
3
|
attr_reader :name, :examples, :preview
|
6
4
|
|
7
5
|
def initialize(name, preview, examples)
|
8
6
|
@name = name
|
9
7
|
@preview = preview
|
10
8
|
@examples = examples
|
9
|
+
super("#{@preview.path}/#{name}")
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def path
|
18
|
-
"#{@preview.path}/#{name}"
|
12
|
+
def url_path
|
13
|
+
inspect_path lookup_path
|
19
14
|
end
|
20
15
|
|
21
16
|
def label
|