lookbook 2.0.0.beta.2 → 2.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/lookbook/css/fonts.css +33 -0
- data/app/assets/lookbook/css/lookbook.css +7 -0
- data/app/assets/lookbook/css/themes/blue.css +4 -1
- data/app/assets/lookbook/css/themes/green.css +4 -1
- data/app/assets/lookbook/css/themes/indigo.css +4 -1
- data/app/assets/lookbook/css/themes/rose.css +4 -1
- data/app/assets/lookbook/css/themes/zinc.css +4 -1
- data/app/assets/lookbook/fonts/Inter-italic.var.woff2 +0 -0
- data/app/assets/lookbook/fonts/Inter-roman.var.woff2 +0 -0
- data/app/assets/lookbook/fonts/SourceCodeVariable-Italic.ttf.woff2 +0 -0
- data/app/assets/lookbook/fonts/SourceCodeVariable-Roman.ttf.woff2 +0 -0
- data/app/assets/lookbook/img/lucide-sprite.svg +869 -869
- data/app/assets/lookbook/js/lib/lookbook.js +12 -2
- data/app/components/lookbook/code/highlight_github.css +16 -17
- data/app/components/lookbook/dimensions_display/component.js +4 -7
- data/app/components/lookbook/file_source/component.html.erb +9 -0
- data/app/components/lookbook/file_source/component.rb +73 -0
- data/app/components/lookbook/header/component.html.erb +11 -8
- data/app/components/lookbook/icon/component.css +1 -1
- data/app/components/lookbook/icon/component.html.erb +1 -1
- data/app/components/lookbook/icon/component.rb +4 -1
- data/app/components/lookbook/logo/component.html.erb +6 -0
- data/app/components/lookbook/logo/component.rb +15 -0
- data/app/components/lookbook/message/component.css +33 -0
- data/app/components/lookbook/message/component.html.erb +26 -0
- data/app/components/lookbook/message/component.rb +13 -0
- data/app/components/lookbook/nav/entity/component.html.erb +2 -2
- data/app/components/lookbook/nav/entity/component.rb +1 -1
- data/app/components/lookbook/page_tabs/component.html.erb +2 -2
- data/app/components/lookbook/params/field/component.css +3 -3
- data/app/components/lookbook/prose/component.css +8 -1
- data/app/components/lookbook/prose/component.html.erb +6 -1
- data/app/components/lookbook/prose/component.rb +2 -2
- data/app/controllers/concerns/lookbook/targetable_concern.rb +2 -16
- data/app/controllers/lookbook/application_controller.rb +38 -14
- data/app/controllers/lookbook/embeds_controller.rb +3 -4
- data/app/controllers/lookbook/inspector_controller.rb +4 -12
- data/app/controllers/lookbook/pages_controller.rb +15 -27
- data/app/controllers/lookbook/preview_controller.rb +30 -2
- data/app/controllers/lookbook/previews_controller.rb +13 -15
- data/app/views/layouts/lookbook/application.html.erb +1 -0
- data/app/views/layouts/lookbook/skeleton.html.erb +2 -2
- data/app/views/lookbook/errors/default.html.erb +40 -0
- data/app/views/lookbook/errors/not_found.html.erb +10 -0
- data/app/views/lookbook/index.html.erb +29 -24
- data/app/views/lookbook/pages/show.html.erb +9 -8
- data/app/views/lookbook/partials/_blank_slate.html.erb +7 -0
- data/config/app.yml +8 -0
- data/config/routes.rb +2 -0
- data/lib/lookbook/engine.rb +12 -5
- data/lib/lookbook/entities/concerns/annotatable_entity.rb +26 -1
- data/lib/lookbook/entities/concerns/inspectable_entity.rb +17 -2
- data/lib/lookbook/entities/concerns/locatable_entity.rb +51 -7
- data/lib/lookbook/entities/concerns/navigable_entity.rb +14 -1
- data/lib/lookbook/entities/entity.rb +34 -12
- data/lib/lookbook/entities/page_entity.rb +68 -10
- data/lib/lookbook/entities/page_section_entity.rb +4 -0
- data/lib/lookbook/entities/preview_entity.rb +107 -17
- data/lib/lookbook/entities/renderable_entity.rb +47 -9
- data/lib/lookbook/entities/rendered_scenario_entity.rb +17 -6
- data/lib/lookbook/entities/scenario_entity.rb +77 -16
- data/lib/lookbook/entities/scenario_group_entity.rb +82 -9
- data/lib/lookbook/helpers/page_helper.rb +26 -1
- data/lib/lookbook/helpers/ui_elements_helper.rb +0 -24
- data/lib/lookbook/param.rb +1 -1
- data/lib/lookbook/services/markdown_renderer.rb +2 -4
- data/lib/lookbook/stores/config_store.rb +0 -12
- data/lib/lookbook/support/errors/config_error.rb +1 -1
- data/lib/lookbook/support/errors/error.rb +64 -0
- data/lib/lookbook/support/errors/parser_error.rb +1 -1
- data/lib/lookbook/support/errors/preview_template_error.rb +1 -1
- data/lib/lookbook/support/errors/routing_error.rb +7 -0
- data/lib/lookbook/support/errors/template_error.rb +7 -0
- data/lib/lookbook/version.rb +1 -1
- data/public/lookbook-assets/Inter-italic.var.69eb0fe1.woff2 +0 -0
- data/public/lookbook-assets/Inter-italic.var.736a7044.woff2 +0 -0
- data/public/lookbook-assets/Inter-roman.var.b695afbe.woff2 +0 -0
- data/public/lookbook-assets/Inter-roman.var.fbdd51d0.woff2 +0 -0
- data/public/lookbook-assets/SourceCodeVariable-Italic.cad97b83.otf +0 -0
- data/public/lookbook-assets/SourceCodeVariable-Italic.ttf.09b4354a.woff2 +0 -0
- data/public/lookbook-assets/SourceCodeVariable-Italic.ttf.fcd7e9f4.woff2 +0 -0
- data/public/lookbook-assets/SourceCodeVariable-Roman.185ddb17.otf +0 -0
- data/public/lookbook-assets/SourceCodeVariable-Roman.ttf.118e9f22.woff2 +0 -0
- data/public/lookbook-assets/SourceCodeVariable-Roman.ttf.91043609.woff2 +0 -0
- data/public/lookbook-assets/css/lookbook.css +417 -58
- data/public/lookbook-assets/css/lookbook.css.map +1 -1
- data/public/lookbook-assets/css/themes/blue.css +4 -1
- data/public/lookbook-assets/css/themes/blue.css.map +1 -1
- data/public/lookbook-assets/css/themes/green.css +4 -1
- data/public/lookbook-assets/css/themes/green.css.map +1 -1
- data/public/lookbook-assets/css/themes/indigo.css +4 -1
- data/public/lookbook-assets/css/themes/indigo.css.map +1 -1
- data/public/lookbook-assets/css/themes/rose.css +4 -1
- data/public/lookbook-assets/css/themes/rose.css.map +1 -1
- data/public/lookbook-assets/css/themes/zinc.css +4 -1
- data/public/lookbook-assets/css/themes/zinc.css.map +1 -1
- data/public/lookbook-assets/img/lucide-sprite.svg +869 -869
- data/public/lookbook-assets/js/index.js +173 -173
- data/public/lookbook-assets/js/index.js.map +1 -1
- data/public/lookbook-assets/js/lookbook-core.js +4 -2
- data/public/lookbook-assets/js/lookbook.js +4 -2
- metadata +31 -26
- data/app/views/layouts/lookbook/shell.html.erb +0 -25
- data/app/views/lookbook/404.html.erb +0 -15
- data/app/views/lookbook/error.html.erb +0 -46
- data/lib/lookbook/error.rb +0 -120
- data/lib/lookbook/support/errors/lookbook_error.rb +0 -21
- data/lib/tasks/lookbook_tasks.rake +0 -10
- data/public/lookbook-assets/css/app.css +0 -2341
- data/public/lookbook-assets/css/app.css.map +0 -11
- data/public/lookbook-assets/css/themes/zinc.css.map.91837.5 +0 -1
- data/public/lookbook-assets/feather-sprite.svg +0 -1
- data/public/lookbook-assets/js/app.js +0 -10862
- data/public/lookbook-assets/js/app.js.map +0 -2571
- data/public/lookbook-assets/js/embed.js +0 -1427
- data/public/lookbook-assets/js/embed.js.91837.6 +0 -0
- data/public/lookbook-assets/js/embed.js.map +0 -1
- data/public/lookbook-assets/js/lookbook-core.js.map +0 -1
- data/public/lookbook-assets/js/lookbook.js.map +0 -1
- data/public/lookbook-assets/lookbook-esm.js +0 -1427
- data/public/lookbook-assets/lookbook-esm.js.map +0 -1
- data/public/lookbook-assets/lookbook-global.js +0 -1427
- data/public/lookbook-assets/lookbook-global.js.map +0 -1
- data/public/lookbook-assets/lookbook.js +0 -1427
- data/public/lookbook-assets/lookbook.js.map +0 -1
@@ -1,40 +1,77 @@
|
|
1
1
|
module Lookbook
|
2
|
-
# @api private
|
3
2
|
module LocatableEntity
|
4
3
|
extend ActiveSupport::Concern
|
5
4
|
|
6
5
|
included do
|
7
|
-
|
8
|
-
|
6
|
+
# @!group Paths
|
7
|
+
|
8
|
+
# Full path to the entity file
|
9
|
+
#
|
10
|
+
# @return [Pathname] File patj
|
11
|
+
attr_reader :file_path
|
12
|
+
|
13
|
+
# @api private
|
14
|
+
attr_reader :base_directories
|
15
|
+
|
16
|
+
# Name of the entity file.
|
17
|
+
#
|
18
|
+
# Includes file extension unless the `strip_ext` argument is `true`.
|
19
|
+
#
|
20
|
+
# @param strip_ext [Boolean] Whether or not to remove the file extension
|
21
|
+
# @return [String] File name
|
9
22
|
def file_name(strip_ext = false)
|
10
23
|
basename = file_pathname.basename
|
11
24
|
(strip_ext ? basename.to_s.split(".").first : basename).to_s
|
12
25
|
end
|
13
26
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
27
|
+
# Extension of the entity file.
|
28
|
+
#
|
29
|
+
# @return [String] File extension
|
18
30
|
def file_extension
|
19
31
|
@_file_extension ||= file_pathname.extname
|
20
32
|
end
|
21
33
|
|
34
|
+
# Full directory path for the entity file.
|
35
|
+
#
|
36
|
+
# @return [Pathname] Directory path
|
22
37
|
def directory_path
|
23
38
|
@_directory_path ||= Pathname(file_pathname.dirname)
|
24
39
|
end
|
25
40
|
|
41
|
+
# Relative path to the entity file.
|
42
|
+
#
|
43
|
+
# Returned path is relative to the appropriate base directory
|
44
|
+
# (i.e. the preview directory for previews).
|
45
|
+
#
|
46
|
+
# @return [Pathname] Relative file path
|
26
47
|
def relative_file_path
|
27
48
|
@_relative_file_path ||= file_pathname.relative_path_from(base_directory)
|
28
49
|
end
|
29
50
|
|
51
|
+
# Relative directory path for the entity file.
|
52
|
+
#
|
53
|
+
# Returned path is relative to the appropriate base directory
|
54
|
+
# (i.e. the preview directory for previews).
|
55
|
+
#
|
56
|
+
# @return [Pathname] Relative directory path
|
30
57
|
def relative_directory_path
|
31
58
|
@_relative_directory_path ||= directory_path.relative_path_from(base_directory)
|
32
59
|
end
|
33
60
|
|
61
|
+
# Time that the entity file was last modified
|
62
|
+
#
|
63
|
+
# @return [Time] Time last modified
|
34
64
|
def last_modified
|
35
65
|
@_last_modified ||= File.mtime(file_path)
|
36
66
|
end
|
37
67
|
|
68
|
+
# 'Virtual' path to the entity.
|
69
|
+
#
|
70
|
+
# Determines where the entity is located in heirarchical trees.
|
71
|
+
# Can be altered using the `@logical_path` tag.
|
72
|
+
#
|
73
|
+
# @api private
|
74
|
+
# @return [String] The logical path
|
38
75
|
def logical_path
|
39
76
|
return @_logical_path if @_logical_path
|
40
77
|
|
@@ -42,6 +79,13 @@ module Lookbook
|
|
42
79
|
@_logical_path ||= PathUtils.to_path(directory, file_name_base)
|
43
80
|
end
|
44
81
|
|
82
|
+
# @!endgroup
|
83
|
+
|
84
|
+
# @api private
|
85
|
+
def file_name_base
|
86
|
+
@_file_name_slug ||= file_name(true)
|
87
|
+
end
|
88
|
+
|
45
89
|
alias_method :full_path, :file_path
|
46
90
|
alias_method :rel_path, :relative_file_path
|
47
91
|
alias_method :dir_path, :directory_path
|
@@ -1,17 +1,27 @@
|
|
1
1
|
module Lookbook
|
2
|
-
# @api private
|
3
2
|
module NavigableEntity
|
4
3
|
extend ActiveSupport::Concern
|
5
4
|
|
6
5
|
included do
|
6
|
+
# @!group Visibility
|
7
|
+
|
8
|
+
# Whether or not the entity is hidden (i.e. hidden from navigation)
|
9
|
+
#
|
10
|
+
# @return [Boolean] true if hidden
|
7
11
|
def hidden?
|
8
12
|
fetch_config(:hidden, false)
|
9
13
|
end
|
10
14
|
|
15
|
+
# Whether or not the entity is visible (i.e. present in navigation)
|
16
|
+
#
|
17
|
+
# @return [Boolean] true if visible
|
11
18
|
def visible?
|
12
19
|
!hidden?
|
13
20
|
end
|
14
21
|
|
22
|
+
# @!endgroup
|
23
|
+
|
24
|
+
# @api private
|
15
25
|
def priority
|
16
26
|
return @_priority if @_priority
|
17
27
|
|
@@ -24,14 +34,17 @@ module Lookbook
|
|
24
34
|
@_priority ||= pos.to_i
|
25
35
|
end
|
26
36
|
|
37
|
+
# @api private
|
27
38
|
def depth
|
28
39
|
lookup_path.split("/").size
|
29
40
|
end
|
30
41
|
|
42
|
+
# @api private
|
31
43
|
def default_priority
|
32
44
|
@default_priority || 10000
|
33
45
|
end
|
34
46
|
|
47
|
+
# @api private
|
35
48
|
def <=>(other)
|
36
49
|
if respond_to?(:sort_handler, true)
|
37
50
|
sort_handler(other)
|
@@ -1,27 +1,57 @@
|
|
1
1
|
module Lookbook
|
2
2
|
# Base entity class
|
3
3
|
#
|
4
|
-
# @api
|
4
|
+
# @api public
|
5
5
|
class Entity
|
6
6
|
include Comparable
|
7
7
|
send(:include, Lookbook::Engine.routes.url_helpers) # YARD parsing workaround: https://github.com/lsegal/yard/issues/546
|
8
8
|
|
9
|
+
# @api private
|
9
10
|
def initialize(lookup_path = nil)
|
10
11
|
@lookup_path = lookup_path
|
11
12
|
end
|
12
13
|
|
14
|
+
# @!group Identity
|
15
|
+
|
16
|
+
# Human-readable unique ID for the entity
|
17
|
+
#
|
18
|
+
# @return [String] The ID
|
13
19
|
def id
|
14
20
|
Utils.id(fetch_config(:id) { lookup_path.tr("/", "-") })
|
15
21
|
end
|
16
22
|
|
23
|
+
# Parameter-safe entity name.
|
24
|
+
#
|
25
|
+
# @return [String] The name
|
17
26
|
def name
|
18
27
|
@_name ||= Utils.name(File.basename(@lookup_path))
|
19
28
|
end
|
20
29
|
|
30
|
+
# Titlized name for use in navigation etc.
|
31
|
+
#
|
32
|
+
# Can be customized using the `@label` tag where supported.
|
33
|
+
#
|
34
|
+
# @return [String] The label
|
21
35
|
def label
|
22
36
|
@_label ||= fetch_config(:label) { name.titleize }
|
23
37
|
end
|
24
38
|
|
39
|
+
# Entity type identifier
|
40
|
+
#
|
41
|
+
# @return [Symbol] The entity type
|
42
|
+
def type
|
43
|
+
@_type ||= self.class.name.gsub("Entity", "").demodulize.underscore.downcase.to_sym
|
44
|
+
end
|
45
|
+
|
46
|
+
# @!endgroup
|
47
|
+
|
48
|
+
# @!group Paths
|
49
|
+
|
50
|
+
# Canonical reference path.
|
51
|
+
#
|
52
|
+
# Used for generating URL paths and looking up entities.
|
53
|
+
#
|
54
|
+
# @return [String] The lookup path
|
25
55
|
def lookup_path
|
26
56
|
return @_lookup_path if @_lookup_path
|
27
57
|
|
@@ -32,23 +62,15 @@ module Lookbook
|
|
32
62
|
@_lookup_path ||= PathUtils.strip_slashes(PathUtils.to_path(directory, name))
|
33
63
|
end
|
34
64
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
65
|
+
alias_method :path, :lookup_path
|
66
|
+
deprecate path: :lookup_path, deprecator: Deprecation
|
38
67
|
|
39
|
-
|
40
|
-
@_type ||= self.class.name.gsub("Entity", "").demodulize.underscore.downcase.to_sym
|
41
|
-
end
|
68
|
+
# @!endgroup
|
42
69
|
|
43
70
|
def <=>(other)
|
44
71
|
label <=> other.label
|
45
72
|
end
|
46
73
|
|
47
|
-
alias_method :path, :lookup_path
|
48
|
-
alias_method :logical_path, :lookup_path
|
49
|
-
|
50
|
-
deprecate path: :lookup_path, deprecator: Deprecation
|
51
|
-
|
52
74
|
protected
|
53
75
|
|
54
76
|
def fetch_config(key, fallback = nil, &block)
|
@@ -1,14 +1,18 @@
|
|
1
1
|
module Lookbook
|
2
2
|
# Represents a documentation page
|
3
3
|
#
|
4
|
-
# @ignore methods
|
5
4
|
# @api public
|
6
5
|
class PageEntity < Entity
|
7
6
|
include LocatableEntity
|
8
7
|
include NavigableEntity
|
9
8
|
|
10
|
-
|
9
|
+
# @api private
|
10
|
+
attr_reader :content
|
11
11
|
|
12
|
+
# @api private
|
13
|
+
attr_reader :sections
|
14
|
+
|
15
|
+
# @api private
|
12
16
|
def initialize(file_path)
|
13
17
|
@file_path = Pathname(file_path)
|
14
18
|
@base_directories = Engine.page_paths
|
@@ -18,50 +22,104 @@ module Lookbook
|
|
18
22
|
@sections = []
|
19
23
|
end
|
20
24
|
|
25
|
+
# @!group Identity
|
26
|
+
|
27
|
+
# Page title, as defined in frontmatter.
|
28
|
+
# Defaults to the page `label` if not provided.
|
29
|
+
#
|
30
|
+
# @return [String] The title
|
21
31
|
def title
|
22
32
|
@_title ||= fetch_config(:title, label)
|
23
33
|
end
|
24
34
|
|
35
|
+
# @!endgroup
|
36
|
+
|
37
|
+
# @!group Frontmatter
|
38
|
+
|
39
|
+
# Merged data hash. Combines `data` set in frontmatter
|
40
|
+
# with any global default values.
|
41
|
+
#
|
42
|
+
# @return [Hash] The resolved data hash
|
43
|
+
def data
|
44
|
+
return @_data if @_data
|
45
|
+
|
46
|
+
config_data = fetch_config(:data, {})
|
47
|
+
@_data ||= config_data.is_a?(Hash) ? Store.new(config_data) : config_data
|
48
|
+
end
|
49
|
+
|
50
|
+
# @!endgroup
|
51
|
+
|
52
|
+
# @!group Predicates
|
53
|
+
|
54
|
+
# Whether the page is the default landing page.
|
55
|
+
#
|
56
|
+
# Set via the `landing` frontmatter property.
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
25
59
|
def landing?
|
26
60
|
@_landing ||= fetch_config(:landing, false)
|
27
61
|
end
|
28
62
|
|
63
|
+
# Whether the page content should be rendered
|
64
|
+
# with the Markdown renderer.
|
65
|
+
#
|
66
|
+
# Set via the `markdown` frontmatter property.
|
67
|
+
#
|
68
|
+
# @return [Boolean]
|
29
69
|
def markdown?
|
30
70
|
@_markdown ||= fetch_config(:markdown) { file_path.to_s.match?(/(.*)\.md\.(.*)$/) }
|
31
71
|
end
|
32
72
|
|
73
|
+
# Whether the page header will be shown.
|
74
|
+
#
|
75
|
+
# Set via the `header` frontmatter property.
|
76
|
+
#
|
77
|
+
# @return [Boolean]
|
33
78
|
def header?
|
34
79
|
@_header ||= fetch_config(:header, true)
|
35
80
|
end
|
36
81
|
|
82
|
+
# Whether the page footer will be shown.
|
83
|
+
#
|
84
|
+
# Set via the `footer` frontmatter property.
|
85
|
+
#
|
86
|
+
# @return [Boolean]
|
37
87
|
def footer?
|
38
88
|
@_footer ||= fetch_config(:footer, true)
|
39
89
|
end
|
40
90
|
|
41
|
-
|
42
|
-
return @_data if @_data
|
91
|
+
# @!endgroup
|
43
92
|
|
44
|
-
|
45
|
-
|
93
|
+
# @!group URLs
|
94
|
+
|
95
|
+
# The docs URL path for this page.
|
96
|
+
#
|
97
|
+
# @return [String] URL path
|
98
|
+
def docs_path
|
99
|
+
lookbook_page_path(lookup_path)
|
46
100
|
end
|
47
101
|
|
102
|
+
alias_method :url_path, :docs_path
|
103
|
+
|
104
|
+
# @!endgroup
|
105
|
+
|
106
|
+
# @api private
|
48
107
|
def search_terms
|
49
108
|
label
|
50
109
|
end
|
51
110
|
|
52
|
-
|
53
|
-
lookbook_page_path(lookup_path)
|
54
|
-
end
|
55
|
-
|
111
|
+
# @api private
|
56
112
|
def add_section(section)
|
57
113
|
@sections << section
|
58
114
|
@sections.sort_by! { |section| [section.priority, section.label] }
|
59
115
|
end
|
60
116
|
|
117
|
+
# @api private
|
61
118
|
def method_missing(method_name, *args, &block)
|
62
119
|
method_name.to_s.end_with?("=") ? super : frontmatter.fetch(method_name, nil)
|
63
120
|
end
|
64
121
|
|
122
|
+
# @api private
|
65
123
|
def respond_to_missing?(method_name, include_private = false)
|
66
124
|
frontmatter.key?(method_name) || super
|
67
125
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Lookbook
|
2
2
|
# Represents a preview class
|
3
3
|
#
|
4
|
-
# @ignore methods
|
5
4
|
# @api public
|
6
5
|
class PreviewEntity < Entity
|
7
6
|
include AnnotatableEntity
|
@@ -10,8 +9,10 @@ module Lookbook
|
|
10
9
|
|
11
10
|
delegate :render_args, to: :preview_class
|
12
11
|
|
12
|
+
# @api private
|
13
13
|
attr_reader :preview_class
|
14
14
|
|
15
|
+
# @api private
|
15
16
|
def initialize(code_object)
|
16
17
|
@code_object = code_object
|
17
18
|
@preview_class = code_object.path.constantize
|
@@ -25,61 +26,150 @@ module Lookbook
|
|
25
26
|
@lookup_path = PathUtils.to_lookup_path(cleaned_path)
|
26
27
|
end
|
27
28
|
|
29
|
+
# @!group Scenarios
|
30
|
+
|
31
|
+
# Get all scenarios defined in the preview class.
|
32
|
+
#
|
33
|
+
# @example :ruby
|
34
|
+
# scenario_names = preview.scenarios.map(&:name)
|
35
|
+
#
|
36
|
+
# @return [Array<ScenarioEntity>] All scenarios for the preview
|
28
37
|
def scenarios
|
29
38
|
@_scenarios ||= ScenarioCollection.new(load_scenarios)
|
30
39
|
end
|
31
40
|
|
41
|
+
alias_method :examples, :scenarios
|
42
|
+
deprecate examples: :scenarios, deprecator: Deprecation
|
43
|
+
|
44
|
+
# Find a specific scenario by (i.e. method) name
|
45
|
+
#
|
46
|
+
# @example :ruby
|
47
|
+
# default_scenario_preview_path = preview.scenario(:default).preview_path
|
48
|
+
#
|
49
|
+
# @param scenario_name [Symbol, String] Name of the scenario
|
50
|
+
# @return [ScenarioEntity] The matching scenario, if found
|
51
|
+
# @return [nil] if no matching scenario was found
|
32
52
|
def scenario(scenario_name)
|
33
53
|
scenarios.find { |m| m.name == scenario_name.to_s }
|
34
54
|
end
|
35
55
|
|
56
|
+
alias_method :example, :scenario
|
57
|
+
deprecate example: :scenario, deprecator: Deprecation
|
58
|
+
|
59
|
+
# Get all scenarios defined in the preview class that
|
60
|
+
# have not been hidden (by using the `@hidden` tag).
|
61
|
+
#
|
62
|
+
# @example :ruby
|
63
|
+
# visible_scenario_names = preview.visible_scenarios.map(&:name)
|
64
|
+
#
|
65
|
+
# @return [Array<ScenarioEntity>] All visible scenarios for the preview
|
36
66
|
def visible_scenarios
|
37
67
|
@_visible_scenarios ||= ScenarioCollection.new(scenarios.select(&:visible?))
|
38
68
|
end
|
39
69
|
|
70
|
+
# Get all scenarios defined in the preview class
|
71
|
+
# that are hidden (using the `@hidden` tag) and so
|
72
|
+
# will not show up in the navigation.
|
73
|
+
#
|
74
|
+
# @example :ruby
|
75
|
+
# hidden_scenario_names = preview.hidden_scenarios.map(&:name)
|
76
|
+
#
|
77
|
+
# @return [Array<ScenarioEntity>] All hidden scenarios for the preview
|
78
|
+
def hidden_scenarios
|
79
|
+
@_hidden_scenarios ||= ScenarioCollection.new(scenarios.select(&:hidden?))
|
80
|
+
end
|
81
|
+
|
82
|
+
# The scenario used when a preview is rendered
|
83
|
+
# without explicity specifying a scenario.
|
84
|
+
#
|
85
|
+
# @example :ruby
|
86
|
+
# default_scenario_name = preview.default_scenario.name
|
87
|
+
#
|
88
|
+
# @return [ScenarioEntity] The default scenario for this preview
|
40
89
|
def default_scenario
|
41
90
|
visible_scenarios.first
|
42
91
|
end
|
43
92
|
|
93
|
+
# @!endgroup
|
94
|
+
|
95
|
+
# @!group Render Targets
|
96
|
+
|
97
|
+
# All 'render targets' (i.e. components or partials) that are known
|
98
|
+
# to be rendered within the scenarios defined within this preview.
|
99
|
+
#
|
100
|
+
# Render targets are guessed where possible (based on the preview class name)
|
101
|
+
# but can also be manually specified using the `@renders` tag.
|
102
|
+
#
|
103
|
+
# @example :ruby
|
104
|
+
# "This preview renders: #{preview.render_targets.map(&:label).join(", ")}"
|
105
|
+
#
|
106
|
+
# @return [Array<RenderableEntity>] All known render targets used in the preview
|
44
107
|
def render_targets
|
45
108
|
@_render_targets ||= RenderTargetCollection.new(scenarios.flat_map(&:render_targets).uniq(&:lookup_path))
|
46
109
|
end
|
47
110
|
|
111
|
+
alias_method :components, :render_targets
|
112
|
+
|
113
|
+
# @api private
|
48
114
|
def render_target
|
49
115
|
render_targets.first
|
50
116
|
end
|
51
117
|
|
52
|
-
|
53
|
-
|
54
|
-
global_options.deep_merge(fetch_config(:display_options, {}))
|
55
|
-
end
|
118
|
+
# @api private
|
119
|
+
alias_method :component, :render_target
|
56
120
|
|
57
|
-
|
58
|
-
preview_class.instance_variable_get(:@layout)
|
59
|
-
end
|
121
|
+
# @!endgroup
|
60
122
|
|
61
|
-
|
123
|
+
# @!group URLs
|
124
|
+
|
125
|
+
# The inspector URL path for this preview
|
126
|
+
#
|
127
|
+
# @return [String] URL path
|
128
|
+
def inspect_path
|
62
129
|
lookbook_inspect_path(lookup_path)
|
63
130
|
end
|
64
131
|
|
132
|
+
alias_method :url_path, :inspect_path
|
133
|
+
|
134
|
+
# The standalone preview URL path for this preview
|
135
|
+
#
|
136
|
+
# @return [String] URL path
|
137
|
+
def preview_path
|
138
|
+
lookbook_preview_path(lookup_path)
|
139
|
+
end
|
140
|
+
|
141
|
+
# @!endgroup
|
142
|
+
|
143
|
+
# The name of the associated preview class
|
144
|
+
#
|
145
|
+
# @return [String] Class name
|
65
146
|
def preview_class_name
|
66
147
|
preview_class.name
|
67
148
|
end
|
68
149
|
|
150
|
+
# @api private
|
151
|
+
def file_name_base
|
152
|
+
@_file_name_slug ||= file_name(true).gsub(/(_component_preview|component_preview|preview)$/, "")
|
153
|
+
end
|
154
|
+
|
155
|
+
# @api private
|
156
|
+
def display_options
|
157
|
+
global_options = Lookbook.config.preview_display_options
|
158
|
+
global_options.deep_merge(fetch_config(:display_options, {}))
|
159
|
+
end
|
160
|
+
|
161
|
+
# @api private
|
162
|
+
def layout
|
163
|
+
preview_class.instance_variable_get(:@layout)
|
164
|
+
end
|
165
|
+
|
166
|
+
# @api private
|
69
167
|
def guess_render_targets
|
70
168
|
[preview_class.name.chomp("Preview").constantize&.name]
|
71
169
|
rescue
|
72
170
|
[]
|
73
171
|
end
|
74
172
|
|
75
|
-
alias_method :components, :render_targets
|
76
|
-
alias_method :component, :render_target
|
77
|
-
alias_method :examples, :scenarios
|
78
|
-
alias_method :example, :scenario
|
79
|
-
|
80
|
-
deprecate examples: :scenarios, deprecator: Deprecation
|
81
|
-
deprecate example: :scenario, deprecator: Deprecation
|
82
|
-
|
83
173
|
protected
|
84
174
|
|
85
175
|
def load_scenarios
|
@@ -2,49 +2,87 @@ module Lookbook
|
|
2
2
|
# Represents the component or view template partial
|
3
3
|
# that is being rendered in a preview.
|
4
4
|
#
|
5
|
-
# @ignore methods
|
6
5
|
# @api public
|
7
6
|
class RenderableEntity < Entity
|
8
7
|
include LocatableEntity
|
9
8
|
|
9
|
+
# @api private
|
10
10
|
def initialize(identifier)
|
11
11
|
@identifier = identifier
|
12
12
|
@base_directories = Engine.component_paths
|
13
13
|
@file_path = PathUtils.determine_full_path(component? ? "#{name}.rb" : identifier, @base_directories)
|
14
14
|
unless @file_path && File.exist?(@file_path)
|
15
|
-
raise
|
15
|
+
raise Lookbook::Error, "The render target #{@identifier} was not found."
|
16
16
|
end
|
17
17
|
@lookup_path = PathUtils.to_lookup_path(relative_file_path)
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
@identifier.constantize if component?
|
22
|
-
end
|
20
|
+
# @!group Identity
|
23
21
|
|
22
|
+
# Parameter-safe entity name.
|
23
|
+
#
|
24
|
+
# @return [String]
|
24
25
|
def name
|
25
26
|
component? ? component_class.name.underscore : @identifier
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
# Entity type identifier.
|
30
|
+
# Returns `:component` for components and
|
31
|
+
# `:template` for view templates/partials.
|
32
|
+
#
|
33
|
+
# @return [Symbol] The entity type
|
34
|
+
def type
|
35
|
+
component? ? :component : :template
|
36
|
+
end
|
37
|
+
|
38
|
+
# @!endgroup
|
39
|
+
|
40
|
+
# @!group Components
|
41
|
+
|
42
|
+
# The associated component class (if the renderable is a component).
|
43
|
+
#
|
44
|
+
# @return [Class] The component class
|
45
|
+
def component_class
|
46
|
+
@identifier.constantize if component?
|
30
47
|
end
|
31
48
|
|
49
|
+
# Whether or not the renderable is a component without a template.
|
50
|
+
#
|
51
|
+
# @return [Boolean] True if no template is present
|
32
52
|
def inline?
|
33
53
|
component? ? template_file_path.present? : false
|
34
54
|
end
|
35
55
|
|
56
|
+
# Whether or not the renderable is a component
|
57
|
+
# (as opposed to a view template/partial).
|
58
|
+
#
|
59
|
+
# @return [Boolean] True if component
|
36
60
|
def component?
|
37
61
|
@identifier.first.upcase == @identifier.first &&
|
38
62
|
!@identifier.include?(".") &&
|
39
63
|
!@identifier.include?("/")
|
40
64
|
end
|
41
65
|
|
66
|
+
# Whether or not the renderable is a view template/partial
|
67
|
+
# (as opposed to a component).
|
68
|
+
#
|
69
|
+
# @return [Boolean] True if component
|
42
70
|
def template?
|
43
71
|
!component?
|
44
72
|
end
|
45
73
|
|
46
|
-
|
47
|
-
|
74
|
+
# @!endgroup
|
75
|
+
|
76
|
+
# @!group Paths
|
77
|
+
|
78
|
+
# Full path to the component template (if present)
|
79
|
+
# or view template/partial.
|
80
|
+
#
|
81
|
+
# @return [Class] The component class
|
82
|
+
def template_file_path
|
83
|
+
component? ? Dir.glob("#{directory_path}/#{file_name(true)}.*.erb").first : file_path
|
48
84
|
end
|
85
|
+
|
86
|
+
# @!endgroup
|
49
87
|
end
|
50
88
|
end
|
@@ -1,31 +1,42 @@
|
|
1
1
|
module Lookbook
|
2
|
-
# Represents a **rendered** preview scenario
|
2
|
+
# Represents a **rendered** preview scenario.
|
3
|
+
#
|
4
|
+
# Extends ScenarioEntity with an `output`
|
5
|
+
# method that returns the rendered HTML output.
|
6
|
+
#
|
7
|
+
# See the [ScenarioEntity](./scenario_entity) docs for other available methods.
|
3
8
|
#
|
4
|
-
# @ignore methods
|
5
9
|
# @api public
|
6
10
|
class RenderedScenarioEntity
|
7
11
|
delegate_missing_to :scenario
|
8
12
|
|
13
|
+
# @api private
|
9
14
|
attr_reader :scenario
|
10
15
|
|
16
|
+
# @api private
|
11
17
|
def initialize(scenario, output, params)
|
12
18
|
@scenario = scenario
|
13
19
|
@params = params
|
14
20
|
@output = output
|
15
21
|
end
|
16
22
|
|
23
|
+
# HTML output of the rendered scenario.
|
24
|
+
#
|
25
|
+
# @return [String] Rendered output
|
26
|
+
def output
|
27
|
+
@_output ||= CodeBeautifier.call(@output)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @api private
|
17
31
|
def source
|
18
32
|
has_custom_template? ? template_source(template) : scenario.source
|
19
33
|
end
|
20
34
|
|
35
|
+
# @api private
|
21
36
|
def source_lang
|
22
37
|
has_custom_template? ? template_lang(template) : scenario.source_lang
|
23
38
|
end
|
24
39
|
|
25
|
-
def output
|
26
|
-
@_output ||= CodeBeautifier.call(@output)
|
27
|
-
end
|
28
|
-
|
29
40
|
protected
|
30
41
|
|
31
42
|
attr_reader :params
|