lookbook 1.5.2 → 2.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -24
- data/app/assets/lookbook/css/lookbook.css +9 -0
- data/app/assets/lookbook/css/themes/blue.css +7 -0
- data/app/assets/lookbook/css/themes/green.css +7 -0
- data/app/assets/lookbook/css/themes/indigo.css +7 -0
- data/app/assets/lookbook/css/themes/rose.css +7 -0
- data/app/assets/lookbook/css/themes/zinc.css +7 -0
- data/app/assets/lookbook/css/tooltip.css +9 -6
- data/app/assets/lookbook/img/lucide-sprite.svg +4960 -0
- data/app/assets/lookbook/js/app.js +22 -4
- data/app/assets/lookbook/js/helpers/dom.js +4 -7
- data/app/assets/lookbook/js/helpers/string.js +4 -11
- data/app/assets/lookbook/js/{embed.js → iframe.js} +0 -0
- data/app/assets/lookbook/js/index.js +61 -0
- data/app/assets/lookbook/js/lib/lookbook.js +113 -0
- data/app/assets/lookbook/js/lib/tippy.js +1 -0
- data/app/assets/lookbook/js/lookbook-core.js +1 -0
- data/app/assets/lookbook/js/lookbook.js +2 -61
- data/app/components/lookbook/base_component.rb +3 -1
- data/app/components/lookbook/button/component.html.erb +13 -24
- data/app/components/lookbook/button/component.js +13 -3
- data/app/components/lookbook/button/component.rb +16 -25
- data/app/components/lookbook/code/component.rb +0 -2
- data/app/components/lookbook/copy_button/component.html.erb +4 -4
- data/app/components/lookbook/copy_button/component.rb +6 -3
- data/app/components/lookbook/debug_menu/component.html.erb +1 -0
- data/app/components/lookbook/debug_menu/component.rb +12 -1
- data/app/components/lookbook/display_options/editor/component.html.erb +1 -1
- data/app/components/lookbook/display_options/field/component.css +0 -26
- data/app/components/lookbook/display_options/field/component.html.erb +1 -1
- data/app/components/lookbook/embed/component.html.erb +6 -51
- data/app/components/lookbook/embed/component.rb +17 -16
- data/app/components/lookbook/embed/inspector/component.html.erb +102 -0
- data/app/components/lookbook/embed/inspector/component.js +46 -0
- data/app/components/lookbook/embed/inspector/component.rb +64 -0
- data/app/components/lookbook/embed_code_dropdown/component.css +12 -0
- data/app/components/lookbook/embed_code_dropdown/component.html.erb +19 -0
- data/app/components/lookbook/embed_code_dropdown/component.js +26 -0
- data/app/components/lookbook/embed_code_dropdown/component.rb +41 -0
- data/app/components/lookbook/header/component.html.erb +6 -5
- data/app/components/lookbook/header/component.rb +5 -1
- data/app/components/lookbook/icon/component.html.erb +1 -1
- data/app/components/lookbook/icon_button/component.html.erb +20 -0
- data/app/components/lookbook/icon_button/component.rb +46 -0
- data/app/components/lookbook/nav/component.html.erb +0 -1
- data/app/components/lookbook/nav/entity/component.rb +2 -2
- data/app/components/lookbook/nav/item/component.rb +1 -1
- data/app/components/lookbook/params/editor/component.rb +1 -0
- data/app/components/lookbook/prose/component.rb +1 -3
- data/app/components/lookbook/tabs/component.html.erb +2 -2
- data/app/components/lookbook/tabs/component.js +1 -1
- data/app/components/lookbook/tag_component.rb +2 -1
- data/app/components/lookbook/text_button/component.html.erb +26 -0
- data/app/components/lookbook/text_button/component.rb +42 -0
- data/app/components/lookbook/toolbar/component.html.erb +1 -1
- data/app/components/lookbook/viewport/component.rb +0 -4
- data/app/controllers/concerns/lookbook/targetable_concern.rb +24 -19
- data/app/controllers/concerns/lookbook/with_panels_concern.rb +30 -0
- data/app/controllers/concerns/lookbook/with_preview_controller_concern.rb +4 -3
- data/app/controllers/lookbook/application_controller.rb +9 -12
- data/app/controllers/lookbook/embeds_controller.rb +148 -0
- data/app/controllers/lookbook/inspector_controller.rb +3 -22
- data/app/controllers/lookbook/page_controller.rb +7 -6
- data/app/controllers/lookbook/pages_controller.rb +3 -4
- data/app/controllers/lookbook/preview_controller.rb +17 -0
- data/app/controllers/lookbook/previews_controller.rb +21 -20
- data/app/helpers/lookbook/application_helper.rb +3 -19
- data/app/views/layouts/lookbook/application.html.erb +85 -60
- data/app/views/layouts/lookbook/embed.html.erb +16 -0
- data/app/views/layouts/lookbook/shell.html.erb +1 -1
- data/app/views/layouts/lookbook/skeleton.html.erb +13 -8
- data/app/views/lookbook/embeds/show.html.erb +12 -0
- data/app/views/lookbook/inspector/panels/_notes.html.erb +1 -1
- data/app/views/lookbook/inspector/panels/_output.html.erb +3 -3
- data/app/views/lookbook/inspector/panels/_source.html.erb +6 -6
- data/app/views/lookbook/inspector/show.html.erb +130 -123
- data/app/views/lookbook/pages/show.html.erb +81 -34
- data/app/views/lookbook/partials/_iframe_content_scripts.html.erb +1 -0
- data/app/views/lookbook/partials/_user_styles.html.erb +5 -0
- data/app/views/lookbook/{preview.html.erb → previews/group.html.erb} +7 -7
- data/app/views/lookbook/previews/preview.html.erb +5 -0
- data/app/views/lookbook/previews/show.html.erb +1 -0
- data/config/app.yml +31 -16
- data/config/panels.yml +23 -25
- data/config/routes.rb +3 -1
- data/config/tags.yml +6 -2
- data/lib/lookbook/cable/cable.rb +53 -0
- data/{app/channels/lookbook → lib/lookbook/cable}/connection.rb +0 -0
- data/{app/channels/lookbook → lib/lookbook/cable}/reload_channel.rb +0 -0
- data/lib/lookbook/engine.rb +109 -87
- data/lib/lookbook/entities/collections/entity_collection.rb +11 -6
- data/lib/lookbook/entities/collections/page_collection.rb +33 -8
- data/lib/lookbook/entities/collections/preview_collection.rb +42 -17
- data/lib/lookbook/entities/collections/render_target_collection.rb +4 -0
- data/lib/lookbook/entities/collections/scenario_collection.rb +4 -0
- data/lib/lookbook/entities/concerns/{annotatable.rb → annotatable_entity.rb} +7 -6
- data/lib/lookbook/entities/concerns/{inspectable.rb → inspectable_entity.rb} +2 -1
- data/lib/lookbook/entities/concerns/{locatable.rb → locatable_entity.rb} +8 -14
- data/lib/lookbook/entities/concerns/navigable_entity.rb +44 -0
- data/lib/lookbook/entities/entity.rb +7 -2
- data/lib/lookbook/entities/{page.rb → page_entity.rb} +10 -6
- data/lib/lookbook/entities/{page_section.rb → page_section_entity.rb} +1 -1
- data/lib/lookbook/entities/preview_entity.rb +99 -0
- data/lib/lookbook/entities/renderable_entity.rb +50 -0
- data/lib/lookbook/entities/rendered_scenario_entity.rb +53 -0
- data/lib/lookbook/entities/scenario_entity.rb +116 -0
- data/lib/lookbook/entities/scenario_group_entity.rb +57 -0
- data/lib/lookbook/error.rb +5 -5
- data/lib/lookbook/file_watcher.rb +19 -35
- data/lib/lookbook/helpers/class_names_helper.rb +28 -0
- data/lib/lookbook/helpers/page_helper.rb +18 -0
- data/{app/helpers/lookbook → lib/lookbook/helpers}/preview_helper.rb +3 -0
- data/lib/lookbook/helpers/ui_elements_helper.rb +115 -0
- data/lib/lookbook/preview.rb +79 -0
- data/lib/lookbook/preview_controller_actions.rb +45 -0
- data/lib/lookbook/preview_parser.rb +4 -2
- data/lib/lookbook/reloaders.rb +71 -0
- data/lib/lookbook/runtime_context.rb +49 -0
- data/lib/lookbook/services/data/resolvers/data_resolver.rb +4 -6
- data/lib/lookbook/services/entities/entity_tree_builder.rb +6 -6
- data/lib/lookbook/services/list_resolver.rb +35 -0
- data/lib/lookbook/services/markdown_renderer.rb +12 -2
- data/lib/lookbook/services/priority_prefix_parser.rb +16 -0
- data/lib/lookbook/services/urls/search_param_encoder.rb +16 -0
- data/lib/lookbook/services/urls/search_param_parser.rb +7 -6
- data/lib/lookbook/stores/config_store.rb +16 -16
- data/lib/lookbook/stores/input_store.rb +1 -3
- data/lib/lookbook/stores/panel_store.rb +28 -50
- data/lib/lookbook/support/deprecation.rb +5 -0
- data/lib/lookbook/support/errors/preview_template_error.rb +7 -0
- data/lib/lookbook/support/evented_file_update_checker.rb +69 -0
- data/lib/lookbook/support/null_websocket.rb +9 -0
- data/lib/lookbook/support/store.rb +9 -0
- data/lib/lookbook/support/tree_node.rb +7 -7
- data/lib/lookbook/support/utils/path_utils.rb +7 -1
- data/lib/lookbook/support/utils/utils.rb +8 -0
- data/lib/lookbook/tags/{position_tag.rb → priority_tag.rb} +4 -4
- data/lib/lookbook/tags/renders_tag.rb +4 -0
- data/lib/lookbook/tags/tag_provider.rb +3 -0
- data/lib/lookbook/tags/type_tag.rb +7 -0
- data/lib/lookbook/tags/yard_tag.rb +1 -2
- data/lib/lookbook/version.rb +1 -1
- data/lib/lookbook/websocket.rb +6 -53
- data/lib/lookbook.rb +179 -53
- data/public/lookbook-assets/css/lookbook.css +137 -83
- data/public/lookbook-assets/css/lookbook.css.map +1 -1
- data/public/lookbook-assets/css/themes/blue.css +7 -0
- data/public/lookbook-assets/css/themes/blue.css.map +1 -1
- data/public/lookbook-assets/css/themes/green.css +7 -0
- data/public/lookbook-assets/css/themes/green.css.map +1 -1
- data/public/lookbook-assets/css/themes/indigo.css +7 -0
- data/public/lookbook-assets/css/themes/indigo.css.map +1 -1
- data/public/lookbook-assets/css/themes/rose.css +7 -0
- data/public/lookbook-assets/css/themes/rose.css.map +1 -1
- data/public/lookbook-assets/css/themes/zinc.css +7 -0
- data/public/lookbook-assets/css/themes/zinc.css.map +1 -1
- data/public/lookbook-assets/img/lucide-sprite.svg +4960 -0
- data/public/lookbook-assets/js/embed.js +1363 -842
- data/public/lookbook-assets/js/embed.js.map +1 -1
- data/public/lookbook-assets/js/iframe.js +906 -0
- data/public/lookbook-assets/js/iframe.js.map +1 -0
- data/public/lookbook-assets/js/index.js +13567 -0
- data/public/lookbook-assets/js/index.js.map +1 -0
- data/public/lookbook-assets/js/lookbook-core.js +85 -0
- data/public/lookbook-assets/js/lookbook-core.js.map +1 -0
- data/public/lookbook-assets/js/lookbook.js +143 -12733
- data/public/lookbook-assets/js/lookbook.js.map +1 -1
- data/public/lookbook-assets/lookbook-esm.js +1427 -0
- data/public/lookbook-assets/lookbook-esm.js.map +1 -0
- data/public/lookbook-assets/lookbook-global.js +1427 -0
- data/public/lookbook-assets/lookbook-global.js.map +1 -0
- data/public/lookbook-assets/lookbook.js +1427 -0
- data/public/lookbook-assets/lookbook.js.map +1 -0
- metadata +80 -72
- data/app/components/lookbook/embed/component.js +0 -39
- data/app/helpers/lookbook/component_helper.rb +0 -84
- data/app/helpers/lookbook/output_helper.rb +0 -19
- data/app/helpers/lookbook/page_helper.rb +0 -34
- data/app/views/layouts/lookbook/inspector.html.erb +0 -7
- data/app/views/layouts/lookbook/page.html.erb +0 -53
- data/app/views/layouts/lookbook/standalone.html.erb +0 -5
- data/lib/lookbook/entities/collections/component_collection.rb +0 -4
- data/lib/lookbook/entities/collections/preview_example_collection.rb +0 -4
- data/lib/lookbook/entities/component.rb +0 -31
- data/lib/lookbook/entities/concerns/navigable.rb +0 -43
- data/lib/lookbook/entities/preview.rb +0 -87
- data/lib/lookbook/entities/preview_example.rb +0 -104
- data/lib/lookbook/entities/preview_group.rb +0 -52
- data/lib/lookbook/preview_actions.rb +0 -43
- data/lib/lookbook/process.rb +0 -21
- data/lib/lookbook/rendered_example.rb +0 -37
- data/lib/lookbook/services/position_prefix_parser.rb +0 -16
- data/lib/lookbook/services/urls/search_param_builder.rb +0 -13
- data/lib/lookbook/tags/component_tag.rb +0 -13
@@ -1,84 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
module ComponentHelper
|
3
|
-
COMPONENT_CLASSES = {} # cache for constantized references
|
4
|
-
|
5
|
-
def icon(name, **attrs)
|
6
|
-
lookbook_render :icon, name: name, **attrs
|
7
|
-
end
|
8
|
-
|
9
|
-
def code(language = :html, **attrs, &block)
|
10
|
-
attrs[:language] ||= language
|
11
|
-
lookbook_render :code, **attrs, &block
|
12
|
-
end
|
13
|
-
|
14
|
-
def lookbook_tag(tag = :div, **attrs, &block)
|
15
|
-
lookbook_render :tag, tag: tag, **attrs, &block
|
16
|
-
end
|
17
|
-
|
18
|
-
def lookbook_render(ref, **attrs, &block)
|
19
|
-
comp = if ref.is_a? ViewComponent::Base
|
20
|
-
ref
|
21
|
-
else
|
22
|
-
klass = component_class(ref)
|
23
|
-
attrs.key?(:content) ? klass.new(**attrs.except(:content)).with_content(attrs[:content]) : klass.new(**attrs)
|
24
|
-
end
|
25
|
-
if block && !attrs.key?(:content)
|
26
|
-
public_send render_method_name, comp, &block
|
27
|
-
else
|
28
|
-
public_send render_method_name, comp
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
unless respond_to? :class_names
|
33
|
-
def class_names(*args)
|
34
|
-
tokens = build_tag_values(*args).flat_map { |value| value.to_s.split(/\s+/) }.uniq
|
35
|
-
|
36
|
-
safe_join(tokens, " ")
|
37
|
-
end
|
38
|
-
|
39
|
-
def build_tag_values(*args)
|
40
|
-
tag_values = []
|
41
|
-
|
42
|
-
args.each do |tag_value|
|
43
|
-
case tag_value
|
44
|
-
when Hash
|
45
|
-
tag_value.each do |key, val|
|
46
|
-
tag_values << key.to_s if val && key.present?
|
47
|
-
end
|
48
|
-
when Array
|
49
|
-
tag_values.concat build_tag_values(*tag_value)
|
50
|
-
else
|
51
|
-
tag_values << tag_value.to_s if tag_value.present?
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
tag_values
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def render_method_name
|
62
|
-
if Rails.application.config.view_component.render_monkey_patch_enabled || Rails.version.to_f >= 6.1
|
63
|
-
:render
|
64
|
-
else
|
65
|
-
:render_component
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def component_class(ref)
|
70
|
-
klass = COMPONENT_CLASSES[ref]
|
71
|
-
if klass.nil?
|
72
|
-
ref = ref.to_s.tr("-", "_")
|
73
|
-
class_namespace = ref.camelize
|
74
|
-
begin
|
75
|
-
klass = "Lookbook::#{class_namespace}::Component".constantize
|
76
|
-
rescue
|
77
|
-
klass = "Lookbook::#{class_namespace}Component".constantize
|
78
|
-
end
|
79
|
-
COMPONENT_CLASSES[ref] = klass
|
80
|
-
end
|
81
|
-
klass
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
module OutputHelper
|
3
|
-
def markdown(text = nil, &block)
|
4
|
-
MarkdownRenderer.call(block ? capture(&block) : text, Lookbook.config.markdown_options)
|
5
|
-
end
|
6
|
-
|
7
|
-
def highlight(*args, **opts)
|
8
|
-
CodeHighlighter.call(*args, **opts)
|
9
|
-
end
|
10
|
-
|
11
|
-
def beautify(*args, **opts)
|
12
|
-
CodeBeautifier.call(*args, **opts)
|
13
|
-
end
|
14
|
-
|
15
|
-
def pretty_json(obj)
|
16
|
-
JSON.pretty_generate(obj)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
module PageHelper
|
3
|
-
def page_path(id)
|
4
|
-
page = id.is_a?(Page) ? id : Lookbook.pages.find_by_id(id)
|
5
|
-
if page.present?
|
6
|
-
lookbook_page_path page.lookup_path
|
7
|
-
else
|
8
|
-
Lookbook.logger.warn "Could not find page with id ':#{id}'"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def embed(*args, params: {}, type: :preview, max_height: nil, **opts)
|
13
|
-
return unless args.any?
|
14
|
-
|
15
|
-
@embed_counter ||= 0
|
16
|
-
|
17
|
-
preview = if args.first.is_a?(Symbol)
|
18
|
-
Lookbook.previews.find_by_path(args.first)
|
19
|
-
else
|
20
|
-
Lookbook.previews.find_by_preview_class(args.first)
|
21
|
-
end
|
22
|
-
|
23
|
-
example = args[1] ? preview&.example(args[1]) : preview&.default_example
|
24
|
-
embed_id = "#{url_for}/embed/#{example.lookup_path}".delete_prefix("/").tr("/", "-")
|
25
|
-
|
26
|
-
lookbook_render :embed,
|
27
|
-
id: embed_id,
|
28
|
-
example: example,
|
29
|
-
params: params,
|
30
|
-
max_height: max_height,
|
31
|
-
opts: opts
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
<%= content_for :main do %>
|
2
|
-
<div
|
3
|
-
class="h-[calc(100vh_-_40px)]"
|
4
|
-
x-data="{}"
|
5
|
-
@navigation:complete.window="$refs.scroller.scrollTop = 0">
|
6
|
-
|
7
|
-
<div class="h-full bg-lookbook-page-bg relative">
|
8
|
-
<% unless @error %>
|
9
|
-
|
10
|
-
<div class="absolute top-0 right-0 pt-1 pr-0 pl-1 pb-1 rounded-bl-md">
|
11
|
-
<div class="bg-lookbook-page-bg opacity-90 absolute inset-0 w-full h-full z-0"></div>
|
12
|
-
<div class="relative z-10 flex items-center">
|
13
|
-
|
14
|
-
<% if @previous_page %>
|
15
|
-
<%= lookbook_render :button,
|
16
|
-
size: :lg,
|
17
|
-
icon: :chevron_left,
|
18
|
-
tooltip: "Previous page",
|
19
|
-
href: lookbook_page_path(@previous_page.path),
|
20
|
-
class: "pr-0.5 bg-transparent" %>
|
21
|
-
<% else %>
|
22
|
-
<%= lookbook_render :button,
|
23
|
-
size: :lg,
|
24
|
-
icon: :chevron_left,
|
25
|
-
disabled: true,
|
26
|
-
class: "opacity-50 !cursor-default pr-0.5 bg-transparent" %>
|
27
|
-
<% end %>
|
28
|
-
|
29
|
-
<% if @next_page %>
|
30
|
-
<%= lookbook_render :button,
|
31
|
-
size: :lg,
|
32
|
-
icon: :chevron_right,
|
33
|
-
tooltip: "Next page",
|
34
|
-
href: lookbook_page_path(@next_page.path),
|
35
|
-
class: "pl-0.5 bg-transparent" %>
|
36
|
-
<% else %>
|
37
|
-
<%= lookbook_render :button,
|
38
|
-
size: :lg,
|
39
|
-
icon: :chevron_right,
|
40
|
-
disabled: true,
|
41
|
-
class: "opacity-50 !cursor-default pl-0.5 bg-transparent" %>
|
42
|
-
<% end %>
|
43
|
-
</div>
|
44
|
-
</div>
|
45
|
-
<% end %>
|
46
|
-
|
47
|
-
<%= yield %>
|
48
|
-
</div>
|
49
|
-
|
50
|
-
</div>
|
51
|
-
<% end %>
|
52
|
-
|
53
|
-
<%= render template: "layouts/lookbook/application" %>
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class Component < Entity
|
3
|
-
include Locatable
|
4
|
-
|
5
|
-
attr_reader :component_class
|
6
|
-
|
7
|
-
def initialize(component_class)
|
8
|
-
@component_class = component_class
|
9
|
-
@file_path = "#{Engine.component_paths.first}/#{name.underscore}.rb"
|
10
|
-
@base_directories = Engine.component_paths
|
11
|
-
@lookup_path = PathUtils.to_lookup_path(relative_file_path)
|
12
|
-
end
|
13
|
-
|
14
|
-
def name
|
15
|
-
component_class.name
|
16
|
-
end
|
17
|
-
|
18
|
-
def template_file_path
|
19
|
-
Dir.glob("#{directory_path}/#{file_name(true)}.*.erb").first
|
20
|
-
end
|
21
|
-
|
22
|
-
def inline?
|
23
|
-
template_file_path.present?
|
24
|
-
end
|
25
|
-
|
26
|
-
def template_path
|
27
|
-
Lookbook.logger.warn "The `template_path` method has been deprecated - use `template_file_path` instead. `template_file_path` will be removed in v2.0"
|
28
|
-
template_file_path
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
module Navigable
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
def hidden?
|
7
|
-
fetch_config(:hidden, false)
|
8
|
-
end
|
9
|
-
|
10
|
-
def visible?
|
11
|
-
!hidden?
|
12
|
-
end
|
13
|
-
|
14
|
-
def position
|
15
|
-
return @_position if @_position
|
16
|
-
|
17
|
-
pos = if @position_prefixes && respond_to?(:file_name)
|
18
|
-
PositionPrefixParser.call(file_name).first || default_position
|
19
|
-
else
|
20
|
-
fetch_config(:position, default_position)
|
21
|
-
end
|
22
|
-
|
23
|
-
@_position ||= pos.to_i
|
24
|
-
end
|
25
|
-
|
26
|
-
def depth
|
27
|
-
path.split("/").size
|
28
|
-
end
|
29
|
-
|
30
|
-
def default_position
|
31
|
-
@default_position || 10000
|
32
|
-
end
|
33
|
-
|
34
|
-
def <=>(other)
|
35
|
-
if respond_to?(:sort_handler, true)
|
36
|
-
sort_handler(other)
|
37
|
-
else
|
38
|
-
[position, label] <=> [other.position, other.label]
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class Preview < Entity
|
3
|
-
include Annotatable
|
4
|
-
include Locatable
|
5
|
-
include Navigable
|
6
|
-
|
7
|
-
delegate :render_args, to: :preview_class
|
8
|
-
|
9
|
-
attr_reader :preview_class
|
10
|
-
|
11
|
-
def initialize(code_object)
|
12
|
-
@code_object = code_object
|
13
|
-
@preview_class = code_object.path.constantize
|
14
|
-
@file_path = Pathname(code_object.file)
|
15
|
-
@base_directories = Engine.preview_paths
|
16
|
-
|
17
|
-
cleaned_path = relative_file_path.to_s
|
18
|
-
.gsub(/\/(component_preview|preview)(\..*)$/, "")
|
19
|
-
.gsub(/(_component_preview|_preview)(\..*)$/, "")
|
20
|
-
|
21
|
-
@lookup_path = PathUtils.to_lookup_path(cleaned_path)
|
22
|
-
end
|
23
|
-
|
24
|
-
def examples
|
25
|
-
@_examples ||= PreviewExampleCollection.new(load_examples)
|
26
|
-
end
|
27
|
-
|
28
|
-
def example(example_name)
|
29
|
-
examples.find { |m| m.name == example_name.to_s }
|
30
|
-
end
|
31
|
-
|
32
|
-
def visible_examples
|
33
|
-
@_visible_examples ||= PreviewExampleCollection.new(examples.select(&:visible?))
|
34
|
-
end
|
35
|
-
|
36
|
-
def default_example
|
37
|
-
visible_examples.first
|
38
|
-
end
|
39
|
-
|
40
|
-
def components
|
41
|
-
@_components ||= ComponentCollection.new(examples.flat_map(&:components).uniq(&:path))
|
42
|
-
end
|
43
|
-
|
44
|
-
def component
|
45
|
-
components.first
|
46
|
-
end
|
47
|
-
|
48
|
-
def display_options
|
49
|
-
global_options = Lookbook.config.preview_display_options
|
50
|
-
global_options.deep_merge(fetch_config(:display_options, {}))
|
51
|
-
end
|
52
|
-
|
53
|
-
def layout
|
54
|
-
preview_class.instance_variable_get(:@layout)
|
55
|
-
end
|
56
|
-
|
57
|
-
def url_path
|
58
|
-
lookbook_inspect_path(path)
|
59
|
-
end
|
60
|
-
|
61
|
-
def preview_class_name
|
62
|
-
preview_class.name
|
63
|
-
end
|
64
|
-
|
65
|
-
def guess_components
|
66
|
-
[preview_class.name.chomp("Preview").constantize]
|
67
|
-
rescue
|
68
|
-
[]
|
69
|
-
end
|
70
|
-
|
71
|
-
protected
|
72
|
-
|
73
|
-
def load_examples
|
74
|
-
return example_entities unless code_object.groups.any?
|
75
|
-
|
76
|
-
example_entities.group_by(&:group).flat_map do |group_name, grouped_examples|
|
77
|
-
group_name.nil? ? grouped_examples : PreviewGroup.new(group_name.presence || label.pluralize, grouped_examples, self)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def example_entities
|
82
|
-
public_methods = preview_class.public_instance_methods(false)
|
83
|
-
method_objects = code_object.meths.select { |m| public_methods.include?(m.name) }
|
84
|
-
method_objects.map.with_index { |code_object, i| PreviewExample.new(code_object, self, position: i) }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class PreviewExample < Entity
|
3
|
-
include Inspectable
|
4
|
-
include Annotatable
|
5
|
-
include Navigable
|
6
|
-
|
7
|
-
delegate :group, to: :code_object
|
8
|
-
|
9
|
-
attr_reader :preview
|
10
|
-
|
11
|
-
def initialize(code_object, preview, position: nil)
|
12
|
-
@code_object = code_object
|
13
|
-
@preview = preview
|
14
|
-
@default_position = position
|
15
|
-
@lookup_path = "#{parent.lookup_path}/#{name}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def id
|
19
|
-
@_id ||= Utils.id(fetch_config(:id) { "#{parent.id}-#{code_object.name}" })
|
20
|
-
end
|
21
|
-
|
22
|
-
def name
|
23
|
-
@_name ||= Utils.name(code_object.name)
|
24
|
-
end
|
25
|
-
|
26
|
-
def display_options
|
27
|
-
parent.display_options.merge(fetch_config(:display_options, {}))
|
28
|
-
end
|
29
|
-
|
30
|
-
def components
|
31
|
-
@_components ||= ComponentCollection.new(load_components)
|
32
|
-
end
|
33
|
-
|
34
|
-
def component
|
35
|
-
components.first
|
36
|
-
end
|
37
|
-
|
38
|
-
def examples
|
39
|
-
[self]
|
40
|
-
end
|
41
|
-
|
42
|
-
def template_source(template_path)
|
43
|
-
source_path = template_file_path(template_path)
|
44
|
-
source_path ? File.read(source_path) : nil
|
45
|
-
end
|
46
|
-
|
47
|
-
def template_lang(template_path)
|
48
|
-
path = template_file_path(template_path)
|
49
|
-
Lookbook::Lang.guess(path) || Lookbook::Lang.find(:html)
|
50
|
-
end
|
51
|
-
|
52
|
-
def search_terms
|
53
|
-
[parent.label, label]
|
54
|
-
end
|
55
|
-
|
56
|
-
def url_path
|
57
|
-
lookbook_inspect_path(path)
|
58
|
-
end
|
59
|
-
|
60
|
-
def preview_path
|
61
|
-
lookbook_preview_path(path)
|
62
|
-
end
|
63
|
-
|
64
|
-
def type
|
65
|
-
:example
|
66
|
-
end
|
67
|
-
|
68
|
-
alias_method :parent, :preview
|
69
|
-
alias_method :lang, :source_lang
|
70
|
-
|
71
|
-
protected
|
72
|
-
|
73
|
-
def sort_handler(other_entity)
|
74
|
-
if Lookbook.config.sort_examples
|
75
|
-
label <=> other_entity.label
|
76
|
-
else
|
77
|
-
[position, label] <=> [other_entity.position, other_entity.label]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def format_source(source)
|
82
|
-
source.sub(/^def \w+\s?(\([^)]+\))?/m, "").split("\n")[0..-2].join("\n")
|
83
|
-
end
|
84
|
-
|
85
|
-
def template_file_path(template_path)
|
86
|
-
return full_template_path(template_path) if respond_to?(:full_template_path, true)
|
87
|
-
|
88
|
-
template_path = template_path.to_s.sub(/\..*$/, "")
|
89
|
-
base_path = Engine.preview_paths.detect do |p|
|
90
|
-
Dir["#{p}/#{template_path}.html.*"].first
|
91
|
-
end
|
92
|
-
path = Dir["#{base_path}/#{template_path}.html.*"].first
|
93
|
-
Pathname(path) if path
|
94
|
-
end
|
95
|
-
|
96
|
-
def load_components
|
97
|
-
component_classes = [*fetch_config(:components, []), *preview.send(:fetch_config, :components, [])]
|
98
|
-
component_classes = preview.guess_components if component_classes.empty?
|
99
|
-
|
100
|
-
components = component_classes.map { |klass| Component.new(klass) }
|
101
|
-
components.uniq(&:path)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class PreviewGroup < Entity
|
3
|
-
include Navigable
|
4
|
-
|
5
|
-
attr_reader :examples, :preview
|
6
|
-
|
7
|
-
def initialize(name, examples, preview)
|
8
|
-
@name = Utils.name(name)
|
9
|
-
@examples = PreviewExampleCollection.new(examples)
|
10
|
-
@preview = preview
|
11
|
-
@lookup_path = "#{parent.lookup_path}/#{@name}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def display_options
|
15
|
-
merged = {}
|
16
|
-
examples.to_a.reverse.map do |example|
|
17
|
-
merged.merge!(example.display_options)
|
18
|
-
end
|
19
|
-
merged
|
20
|
-
end
|
21
|
-
|
22
|
-
def components
|
23
|
-
@_components ||= ComponentCollection.new(examples.flat_map(&:components).uniq(&:path))
|
24
|
-
end
|
25
|
-
|
26
|
-
def search_terms
|
27
|
-
[parent.label, label]
|
28
|
-
end
|
29
|
-
|
30
|
-
def tags(tag_name = nil)
|
31
|
-
examples.flat_map { |example| example.tags(tag_name) }
|
32
|
-
end
|
33
|
-
|
34
|
-
def tag(tag_name = nil)
|
35
|
-
tags(tag_name).first
|
36
|
-
end
|
37
|
-
|
38
|
-
def url_path
|
39
|
-
lookbook_inspect_path(path)
|
40
|
-
end
|
41
|
-
|
42
|
-
def preview_path
|
43
|
-
lookbook_preview_path(path)
|
44
|
-
end
|
45
|
-
|
46
|
-
def type
|
47
|
-
:group
|
48
|
-
end
|
49
|
-
|
50
|
-
alias_method :parent, :preview
|
51
|
-
end
|
52
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
module PreviewActions
|
3
|
-
def self.included(klass)
|
4
|
-
klass.helper Lookbook::PreviewHelper
|
5
|
-
end
|
6
|
-
|
7
|
-
def render_example_to_string(preview, example_name)
|
8
|
-
prepend_application_view_paths
|
9
|
-
prepend_preview_examples_view_path
|
10
|
-
@preview = preview
|
11
|
-
@example_name = example_name
|
12
|
-
@render_args = @preview.render_args(@example_name, params: params.permit!)
|
13
|
-
template = @render_args[:template]
|
14
|
-
locals = @render_args[:locals]
|
15
|
-
opts = {}
|
16
|
-
opts[:layout] = nil
|
17
|
-
opts[:locals] = locals if locals.present?
|
18
|
-
|
19
|
-
with_optional_action_view_annotations do
|
20
|
-
render html: render_to_string(template, **opts)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def render_in_layout_to_string(template, locals, opts = {})
|
25
|
-
append_view_path Lookbook::Engine.root.join("app/views")
|
26
|
-
|
27
|
-
with_optional_action_view_annotations do
|
28
|
-
html = render_to_string(template, locals: locals, **determine_layout(opts[:layout]))
|
29
|
-
if opts[:append_html].present?
|
30
|
-
html += opts[:append_html]
|
31
|
-
end
|
32
|
-
render html: html
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
def with_optional_action_view_annotations(&block)
|
39
|
-
disable = Lookbook.config.preview_disable_action_view_annotations
|
40
|
-
ActionViewAnnotationsHandler.call(disable_annotations: disable, &block)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/lookbook/process.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class Process
|
3
|
-
attr_reader :env
|
4
|
-
|
5
|
-
def initialize(env: Rails.env)
|
6
|
-
@env = env
|
7
|
-
end
|
8
|
-
|
9
|
-
def supports_listening?
|
10
|
-
!rake_task? && !Rails.const_defined?(:Console)
|
11
|
-
end
|
12
|
-
|
13
|
-
def rake_task?
|
14
|
-
if defined?(Rake) && Rake.respond_to?(:application)
|
15
|
-
File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
|
16
|
-
else
|
17
|
-
false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class RenderedExample
|
3
|
-
delegate_missing_to :example
|
4
|
-
|
5
|
-
attr_reader :output, :example
|
6
|
-
|
7
|
-
def initialize(example, output, params)
|
8
|
-
@example = example
|
9
|
-
@params = params
|
10
|
-
@output = output
|
11
|
-
end
|
12
|
-
|
13
|
-
def source
|
14
|
-
has_custom_template? ? template_source(template) : example.source
|
15
|
-
end
|
16
|
-
|
17
|
-
def source_lang
|
18
|
-
has_custom_template? ? template_lang(template) : example.source_lang
|
19
|
-
end
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
attr_reader :params
|
24
|
-
|
25
|
-
def render_args
|
26
|
-
@_render_args ||= preview.render_args(example.name, params: params)
|
27
|
-
end
|
28
|
-
|
29
|
-
def template
|
30
|
-
render_args[:template]
|
31
|
-
end
|
32
|
-
|
33
|
-
def has_custom_template?
|
34
|
-
template != "view_components/preview" && !custom_source?
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Lookbook
|
2
|
-
class PositionPrefixParser < Service
|
3
|
-
POSITION_PREFIX_REGEX = /^(\d+?)[-_]/
|
4
|
-
|
5
|
-
attr_reader :input
|
6
|
-
|
7
|
-
def initialize(input)
|
8
|
-
@input = String(input)
|
9
|
-
end
|
10
|
-
|
11
|
-
def call
|
12
|
-
matches = input.match(POSITION_PREFIX_REGEX)
|
13
|
-
matches ? [matches[1].to_i, input.gsub(POSITION_PREFIX_REGEX, "")] : [nil, input]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|