lookbook 1.3.4 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -11
- data/app/assets/lookbook/css/themes/blue.css +1 -1
- data/app/assets/lookbook/css/themes/green.css +1 -1
- data/app/assets/lookbook/css/themes/indigo.css +1 -1
- data/app/assets/lookbook/css/themes/rose.css +1 -1
- data/app/assets/lookbook/css/themes/zinc.css +1 -1
- data/app/components/lookbook/code/component.rb +2 -4
- data/app/components/lookbook/header/component.html.erb +1 -1
- data/app/components/lookbook/inspector_panel/component.rb +1 -1
- data/app/components/lookbook/nav/component.rb +8 -15
- data/app/components/lookbook/nav/directory/component.html.erb +26 -0
- data/app/components/lookbook/nav/directory/component.rb +4 -0
- data/app/components/lookbook/nav/{item → entity}/component.html.erb +5 -7
- data/app/components/lookbook/nav/entity/component.rb +49 -0
- data/app/components/lookbook/nav/item/component.css +15 -0
- data/app/components/lookbook/nav/item/component.js +4 -0
- data/app/components/lookbook/nav/item/component.rb +13 -56
- data/app/controllers/concerns/lookbook/targetable_concern.rb +13 -38
- data/app/controllers/lookbook/application_controller.rb +9 -7
- data/app/controllers/lookbook/page_controller.rb +2 -2
- data/app/controllers/lookbook/pages_controller.rb +9 -15
- data/app/helpers/lookbook/application_helper.rb +1 -1
- data/app/helpers/lookbook/page_helper.rb +7 -4
- data/app/views/layouts/lookbook/application.html.erb +3 -4
- data/app/views/layouts/lookbook/page.html.erb +2 -2
- data/app/views/layouts/lookbook/shell.html.erb +2 -2
- data/app/views/layouts/lookbook/skeleton.html.erb +7 -7
- data/app/views/lookbook/index.html.erb +3 -3
- data/app/views/lookbook/inspector/panels/_params.html.erb +2 -2
- data/config/languages.yml +41 -0
- data/config/panels.yml +1 -1
- data/config/tags.yml +4 -0
- data/lib/lookbook/engine.rb +65 -43
- data/lib/lookbook/entities/collections/component_collection.rb +4 -0
- data/lib/lookbook/entities/collections/concerns/hierarchical_collection.rb +27 -0
- data/lib/lookbook/entities/collections/entity_collection.rb +66 -0
- data/lib/lookbook/entities/collections/page_collection.rb +30 -0
- data/lib/lookbook/entities/collections/preview_collection.rb +35 -0
- data/lib/lookbook/entities/collections/preview_example_collection.rb +9 -0
- data/lib/lookbook/entities/component.rb +31 -0
- data/lib/lookbook/entities/concerns/annotatable.rb +58 -0
- data/lib/lookbook/entities/concerns/inspectable.rb +44 -0
- data/lib/lookbook/entities/concerns/locatable.rb +73 -0
- data/lib/lookbook/entities/concerns/navigable.rb +27 -0
- data/lib/lookbook/entities/entity.rb +48 -0
- data/lib/lookbook/entities/page.rb +80 -0
- data/lib/lookbook/entities/page_section.rb +43 -0
- data/lib/lookbook/entities/preview.rb +87 -0
- data/lib/lookbook/entities/preview_example.rb +91 -0
- data/lib/lookbook/entities/preview_group.rb +48 -0
- data/lib/lookbook/file_watcher.rb +1 -1
- data/lib/lookbook/lang.rb +12 -35
- data/lib/lookbook/param.rb +2 -2
- data/lib/lookbook/preview_parser.rb +1 -1
- data/lib/lookbook/rendered_example.rb +37 -0
- data/lib/lookbook/services/code/code_indenter.rb +14 -0
- data/lib/lookbook/services/data/resolvers/data_resolver.rb +2 -2
- data/lib/lookbook/services/data/resolvers/method_resolver.rb +1 -1
- data/lib/lookbook/services/entities/entity_tree_builder.rb +45 -0
- data/lib/lookbook/services/position_prefix_parser.rb +16 -0
- data/lib/lookbook/support/store.rb +0 -33
- data/lib/lookbook/support/tree_node.rb +83 -0
- data/lib/lookbook/support/utils/path_utils.rb +26 -2
- data/lib/lookbook/support/utils/utils.rb +24 -0
- data/lib/lookbook/tags/component_tag.rb +6 -0
- data/lib/lookbook/tags/custom_tag.rb +2 -0
- data/lib/lookbook/tags/id_tag.rb +1 -1
- data/lib/lookbook/tags/logical_path_tag.rb +3 -0
- data/lib/lookbook/tags/param_tag.rb +2 -0
- data/lib/lookbook/tags/source_tag.rb +7 -0
- data/lib/lookbook/tags/yard_tag.rb +35 -7
- data/lib/lookbook/version.rb +1 -1
- data/lib/lookbook.rb +11 -7
- data/public/lookbook-assets/css/lookbook.css +33 -21
- data/public/lookbook-assets/css/lookbook.css.map +1 -1
- data/public/lookbook-assets/js/lookbook.js +64 -63
- data/public/lookbook-assets/js/lookbook.js.map +1 -1
- metadata +35 -18
- data/lib/lookbook/collection.rb +0 -161
- data/lib/lookbook/component.rb +0 -34
- data/lib/lookbook/entity.rb +0 -47
- data/lib/lookbook/page.rb +0 -194
- data/lib/lookbook/page_collection.rb +0 -19
- data/lib/lookbook/page_section.rb +0 -29
- data/lib/lookbook/preview.rb +0 -181
- data/lib/lookbook/preview_collection.rb +0 -23
- data/lib/lookbook/preview_example.rb +0 -93
- data/lib/lookbook/preview_group.rb +0 -58
- data/lib/lookbook/source_inspector.rb +0 -76
- data/lib/lookbook/support/utils/attribute_utils.rb +0 -14
- data/lib/lookbook/utils.rb +0 -65
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a8ca9a9db0798d392083b4470397bf94260811a1f82f8b89dee0e5646fca156
|
|
4
|
+
data.tar.gz: 24fe83948823edd7387b11ca2ee5628f778a15034173491bfdfd20347d6b1484
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1463db9307bc67d9224a4a96f21ee404902fe0e266b40b0456c84e551a26b96a779e816f2780b5c1ea30189b8d94e3e5dfc16ab6d2f0b3df3a0e06d8f2705282
|
|
7
|
+
data.tar.gz: ea867f97d2cb0d532e59c3c62de31405dca1fe29e7f9ade020fe6b7eb2cb3d2b04d16d7b110e3479eaa54316d6df9ba3328594c73c659e37f6c513867325ad54
|
data/README.md
CHANGED
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
A tool to help browse, develop, test & document [ViewComponents](https://viewcomponent.org/) in Ruby on Rails apps.
|
|
5
5
|
|
|
6
6
|
[](https://rubygems.org/gems/lookbook)
|
|
7
|
-
[](https://github.com/ViewComponent/lookbook/actions/workflows/ci.yml)
|
|
8
8
|
<br>
|
|
9
9
|
|
|
10
10
|
## Documentation
|
|
11
11
|
|
|
12
12
|
✨ **Lookbook guide and API docs**: [lookbook.build](https://lookbook.build)
|
|
13
13
|
|
|
14
|
-
> _Looking for pre-v1.0 documentation? [Head over here](https://github.com/
|
|
14
|
+
> _Looking for pre-v1.0 documentation? [Head over here](https://github.com/ViewComponent/lookbook/tree/0.9.x)._
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
## Demo
|
|
18
18
|
|
|
19
19
|
✨ **Online Demo**: [lookbook-demo-app.herokuapp.com/lookbook](https://lookbook-demo-app.herokuapp.com/lookbook)
|
|
20
20
|
|
|
21
|
-
✨ **Demo repo**: [github.com/
|
|
21
|
+
✨ **Demo repo**: [github.com/ViewComponent/lookbook-demo](https://github.com/ViewComponent/lookbook-demo)
|
|
22
22
|
|
|
23
23
|
[](https://lookbook-demo-app.herokuapp.com/lookbook/)
|
|
24
24
|
|
|
@@ -29,10 +29,10 @@ Lookbook is implemented as an isolated [Rails Engine](https://guides.rubyonrails
|
|
|
29
29
|
|
|
30
30
|
This repository contains:
|
|
31
31
|
|
|
32
|
-
* The Lookbook source code ([`/app`](https://github.com/
|
|
33
|
-
* A '[workbench](#workbench)' app used for Lookbook component development ([`/workbench`](https://github.com/
|
|
34
|
-
* The Lookbook [documentation site](#docs-site) source code and content ([`/docs`](https://github.com/
|
|
35
|
-
* A [test suite](#testing) with a 'runable' dummy app ([`/spec`](https://github.com/
|
|
32
|
+
* The Lookbook source code ([`/app`](https://github.com/ViewComponent/lookbook/tree/main/app), [`/lib`](https://github.com/ViewComponent/lookbook/tree/main/lib), [`/config`](https://github.com/ViewComponent/lookbook/tree/main/config), etc)
|
|
33
|
+
* A '[workbench](#workbench)' app used for Lookbook component development ([`/workbench`](https://github.com/ViewComponent/lookbook/tree/main/workbench)).
|
|
34
|
+
* The Lookbook [documentation site](#docs-site) source code and content ([`/docs`](https://github.com/ViewComponent/lookbook/tree/main/docs)).
|
|
35
|
+
* A [test suite](#testing) with a 'runable' dummy app ([`/spec`](https://github.com/ViewComponent/lookbook/tree/main/spec)).
|
|
36
36
|
|
|
37
37
|
### Workbench
|
|
38
38
|
|
|
@@ -69,16 +69,16 @@ The dummy app that the tests are being run against can be viewed by running the
|
|
|
69
69
|
|
|
70
70
|
Lookbook is an un-funded open source project and contributions of all types and sizes are most welcome!
|
|
71
71
|
|
|
72
|
-
Please take the time to read over the [Contributing](./CONTRIBUTING.md) guide before making your first contribution and if anything isn't clear then [start a discussion](https://github.com/
|
|
72
|
+
Please take the time to read over the [Contributing](./CONTRIBUTING.md) guide before making your first contribution and if anything isn't clear then [start a discussion](https://github.com/ViewComponent/lookbook/discussions) and we will do our best to help you out.
|
|
73
73
|
|
|
74
74
|
## Contributors
|
|
75
75
|
|
|
76
76
|
Lookbook was created by [Mark Perkins](https://github.com/allmarkedup) and continues to grow
|
|
77
|
-
& improve thanks to the ideas, suggestions and hard work of all of [these excellent humans](https://github.com/
|
|
77
|
+
& improve thanks to the ideas, suggestions and hard work of all of [these excellent humans](https://github.com/ViewComponent/lookbook/graphs/contributors):
|
|
78
78
|
<br>
|
|
79
79
|
<br>
|
|
80
|
-
<a href="https://github.com/
|
|
81
|
-
<img src="https://contrib.rocks/image?repo=
|
|
80
|
+
<a href="https://github.com/ViewComponent/lookbook/graphs/contributors">
|
|
81
|
+
<img src="https://contrib.rocks/image?repo=ViewComponent/lookbook&columns=14" width="800" />
|
|
82
82
|
</a>
|
|
83
83
|
|
|
84
84
|
## License
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require "active_model"
|
|
2
|
-
|
|
3
1
|
module Lookbook
|
|
4
2
|
class Code::Component < Lookbook::BaseComponent
|
|
5
3
|
include Lookbook::OutputHelper
|
|
@@ -56,8 +54,8 @@ module Lookbook
|
|
|
56
54
|
end
|
|
57
55
|
|
|
58
56
|
def before_render
|
|
59
|
-
@theme ||=
|
|
60
|
-
@dark ||=
|
|
57
|
+
@theme ||= Lookbook.config.highlighter_options.fetch(:theme, :github).to_sym
|
|
58
|
+
@dark ||= !!Lookbook.config.highlighter_options.fetch(:dark, false)
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
protected
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
<% menu = lookbook_render :debug_menu,
|
|
26
26
|
version: Lookbook::VERSION,
|
|
27
27
|
docs_url: "https://lookbook.build/guide",
|
|
28
|
-
repo_url: "https://github.com/
|
|
28
|
+
repo_url: "https://github.com/ViewComponent/lookbook" do %>
|
|
29
29
|
<%= helpers.pretty_json(Lookbook.debug_data) %>
|
|
30
30
|
<% end %>
|
|
31
31
|
<% button.dropdown({}).with_content(menu) %>
|
|
@@ -3,25 +3,18 @@ module Lookbook
|
|
|
3
3
|
renders_one :filter, Lookbook::Filter::Component
|
|
4
4
|
renders_one :toolbar, Lookbook::Toolbar::Component
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@id = id.presence || "#{collection.id}-nav"
|
|
12
|
-
@collection = collection.as_tree
|
|
13
|
-
@item_args = {
|
|
14
|
-
collapse_singles: collapse_singles
|
|
15
|
-
}
|
|
6
|
+
attr_reader :id, :tree
|
|
7
|
+
|
|
8
|
+
def initialize(tree:, id: nil, **attrs)
|
|
9
|
+
@id = id
|
|
10
|
+
@tree = tree
|
|
16
11
|
super(**attrs, id: id)
|
|
17
12
|
end
|
|
18
13
|
|
|
19
14
|
def items
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
depth: 1,
|
|
24
|
-
**@item_args
|
|
15
|
+
tree.map do |node|
|
|
16
|
+
item_class = (node.type == :directory) ? Nav::Directory::Component : Nav::Entity::Component
|
|
17
|
+
lookbook_render item_class.new node, nav_id: id
|
|
25
18
|
end
|
|
26
19
|
end
|
|
27
20
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<%= render_component_tag :li,
|
|
2
|
+
id: id,
|
|
3
|
+
class: "list-none",
|
|
4
|
+
"x-show": "!filteredOut",
|
|
5
|
+
data: { "entity-type": :directory },
|
|
6
|
+
cloak: true do %>
|
|
7
|
+
<%= lookbook_tag :button,
|
|
8
|
+
class: "nav-action",
|
|
9
|
+
style: "padding-left: #{left_pad}px",
|
|
10
|
+
"x-bind": "bindings.toggle" do %>
|
|
11
|
+
<div class="nav-action-inner">
|
|
12
|
+
<%= icon nil,
|
|
13
|
+
size: 3,
|
|
14
|
+
class: "nav-toggle-icon",
|
|
15
|
+
"x-effect": "iconName = open ? 'chevron-down' : 'chevron-right'" if children? %>
|
|
16
|
+
<%= icon nav_icon, size: 3.5, class: "mr-1.5 text-lookbook-nav-icon-stroke" %>
|
|
17
|
+
<span class="truncate"><%= label %></span>
|
|
18
|
+
</div>
|
|
19
|
+
<% end %>
|
|
20
|
+
|
|
21
|
+
<% if children? %>
|
|
22
|
+
<ul x-ref="items" x-show="open" x-cloak>
|
|
23
|
+
<%= safe_join(children) %>
|
|
24
|
+
</ul>
|
|
25
|
+
<% end %>
|
|
26
|
+
<% end %>
|
|
@@ -2,22 +2,20 @@
|
|
|
2
2
|
id: id,
|
|
3
3
|
class: "list-none",
|
|
4
4
|
"x-show": "!filteredOut",
|
|
5
|
-
data: {
|
|
6
|
-
"entity-type": item.type
|
|
7
|
-
},
|
|
5
|
+
data: { "entity-type": type },
|
|
8
6
|
cloak: true do %>
|
|
9
7
|
<%= lookbook_tag href.present? ? :a : :button,
|
|
10
8
|
href: href,
|
|
11
|
-
class: "
|
|
9
|
+
class: "nav-action",
|
|
12
10
|
style: "padding-left: #{left_pad}px",
|
|
13
11
|
"x-bind": "bindings.#{href.present? ? "link" : "toggle"}" do %>
|
|
14
|
-
<div class="
|
|
12
|
+
<div class="nav-action-inner">
|
|
15
13
|
<%= icon nil,
|
|
16
14
|
size: 3,
|
|
17
|
-
class: "
|
|
15
|
+
class: "nav-toggle-icon",
|
|
18
16
|
"x-effect": "iconName = open ? 'chevron-down' : 'chevron-right'" if children? %>
|
|
19
17
|
<%= icon nav_icon, size: 3.5, class: "mr-1.5 text-lookbook-nav-icon-stroke" %>
|
|
20
|
-
<span class="truncate <% if
|
|
18
|
+
<span class="truncate <% if node.type == :preview %>font-bold<% end %>"><%= label %></span>
|
|
21
19
|
</div>
|
|
22
20
|
<% end %>
|
|
23
21
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module Lookbook
|
|
2
|
+
class Nav::Entity::Component < Nav::Item::Component
|
|
3
|
+
ICONS = {
|
|
4
|
+
page: :file,
|
|
5
|
+
preview: :layers,
|
|
6
|
+
example: :eye,
|
|
7
|
+
group: :eye
|
|
8
|
+
}.freeze
|
|
9
|
+
|
|
10
|
+
def nav_icon
|
|
11
|
+
ICONS[type] || :file
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def href
|
|
15
|
+
if collapsed?
|
|
16
|
+
node.first.url_path
|
|
17
|
+
elsif type != :preview
|
|
18
|
+
node.url_path
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def children
|
|
23
|
+
collapsed? ? [] : super
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def type
|
|
27
|
+
collapsed? ? :example : node.type
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def collapsed?
|
|
31
|
+
node.type == :preview && node.children.one?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def search_terms
|
|
35
|
+
matchers = if collapsed?
|
|
36
|
+
node.first.search_terms
|
|
37
|
+
else
|
|
38
|
+
node.respond_to?(:search_terms) ? Array(node.search_terms) : []
|
|
39
|
+
end
|
|
40
|
+
matchers.flatten.map { |m| m.gsub(/\s/, "").downcase }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
protected
|
|
44
|
+
|
|
45
|
+
def alpine_data
|
|
46
|
+
alpine_encode({id: node.id, matchers: search_terms})
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
[data-component="nav"] {
|
|
3
|
+
.nav-action {
|
|
4
|
+
@apply flex w-full items-center py-1 select-none cursor-pointer text-lookbook-nav-text hover:bg-lookbook-nav-item-hover transition;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.nav-action-inner {
|
|
8
|
+
@apply relative flex items-center w-full;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.nav-toggle-icon {
|
|
12
|
+
@apply mr-1 text-lookbook-nav-toggle absolute -left-4;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,87 +1,44 @@
|
|
|
1
1
|
module Lookbook
|
|
2
2
|
class Nav::Item::Component < Lookbook::BaseComponent
|
|
3
|
-
|
|
4
|
-
page: :file,
|
|
5
|
-
page_collection: :folder,
|
|
6
|
-
preview_collection: :folder,
|
|
7
|
-
preview: :layers,
|
|
8
|
-
example: :eye,
|
|
9
|
-
group: :eye,
|
|
10
|
-
collection: :folder
|
|
11
|
-
}.freeze
|
|
3
|
+
delegate :label, :depth, to: :node
|
|
12
4
|
|
|
13
|
-
|
|
5
|
+
attr_reader :node, :nav_id
|
|
14
6
|
|
|
15
|
-
def initialize(
|
|
16
|
-
|
|
17
|
-
nav_id:,
|
|
18
|
-
depth: 1,
|
|
19
|
-
collapse_singles: false,
|
|
20
|
-
**html_attrs
|
|
21
|
-
)
|
|
7
|
+
def initialize(node, nav_id:, **html_attrs)
|
|
8
|
+
@node = node
|
|
22
9
|
@nav_id = nav_id
|
|
23
|
-
@item = item
|
|
24
|
-
@depth = depth
|
|
25
|
-
@collapse_singles = collapse_singles
|
|
26
10
|
super(**html_attrs)
|
|
27
11
|
end
|
|
28
12
|
|
|
29
13
|
def id
|
|
30
|
-
"#{
|
|
14
|
+
"#{nav_id}-#{node.id}"
|
|
31
15
|
end
|
|
32
16
|
|
|
33
17
|
def left_pad
|
|
34
|
-
((
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def href
|
|
38
|
-
if collapsed?
|
|
39
|
-
item.url_path
|
|
40
|
-
elsif !collection?
|
|
41
|
-
item.url_path
|
|
42
|
-
end
|
|
18
|
+
((depth - 1) * 12) + 24
|
|
43
19
|
end
|
|
44
20
|
|
|
45
21
|
def children
|
|
46
|
-
@children ||=
|
|
47
|
-
item.non_empty_items.map do |item|
|
|
48
|
-
lookbook_render Lookbook::Nav::Item::Component.new item,
|
|
49
|
-
nav_id: @nav_id,
|
|
50
|
-
depth: (@depth + 1),
|
|
51
|
-
collapse_singles: @collapse_singles
|
|
52
|
-
end
|
|
53
|
-
else
|
|
54
|
-
[]
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def item
|
|
59
|
-
collapsed? ? @item.first : @item
|
|
22
|
+
@children ||= node.map { |node| render_item(node) }
|
|
60
23
|
end
|
|
61
24
|
|
|
62
25
|
def nav_icon
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def collection?
|
|
67
|
-
@item.is_a? Lookbook::Collection
|
|
26
|
+
:folder
|
|
68
27
|
end
|
|
69
28
|
|
|
70
29
|
def children?
|
|
71
|
-
children.any?
|
|
30
|
+
children.any?
|
|
72
31
|
end
|
|
73
32
|
|
|
74
|
-
def
|
|
75
|
-
|
|
33
|
+
def render_item(node)
|
|
34
|
+
item_class = (node.type == :directory) ? Nav::Directory::Component : Nav::Entity::Component
|
|
35
|
+
lookbook_render item_class.new node, nav_id: nav_id
|
|
76
36
|
end
|
|
77
37
|
|
|
78
38
|
protected
|
|
79
39
|
|
|
80
40
|
def alpine_data
|
|
81
|
-
alpine_encode({
|
|
82
|
-
id: @item.id,
|
|
83
|
-
matchers: item.is_a?(Lookbook::Collection) ? nil : item.matchers
|
|
84
|
-
})
|
|
41
|
+
alpine_encode({id: node.id, matchers: []})
|
|
85
42
|
end
|
|
86
43
|
|
|
87
44
|
def alpine_component
|
|
@@ -14,19 +14,19 @@ module Lookbook
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def lookup_entities
|
|
17
|
-
@target = Lookbook.previews.
|
|
17
|
+
@target = Lookbook.previews.find_example_by_path(params[:path])
|
|
18
18
|
if @target.present?
|
|
19
19
|
@preview = @target.preview
|
|
20
|
-
if params[:path] == @preview&.
|
|
21
|
-
redirect_to lookbook_inspect_path
|
|
20
|
+
if params[:path] == @preview&.path
|
|
21
|
+
redirect_to lookbook_inspect_path("#{params[:path]}/#{@preview.default_example.name}", params.permit!)
|
|
22
22
|
end
|
|
23
23
|
else
|
|
24
|
-
@preview = Lookbook.previews.
|
|
24
|
+
@preview = Lookbook.previews.find_by_path(params[:path])
|
|
25
25
|
if @preview.present?
|
|
26
|
-
|
|
27
|
-
redirect_to lookbook_inspect_path(
|
|
26
|
+
default_example = @preview.default_example
|
|
27
|
+
redirect_to lookbook_inspect_path(default_example.path, params.permit!) if default_example
|
|
28
28
|
else
|
|
29
|
-
@preview = Lookbook.previews.
|
|
29
|
+
@preview = Lookbook.previews.find_by_path(path_segments.slice(0, path_segments.size - 1).join("/"))
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
end
|
|
@@ -89,46 +89,21 @@ module Lookbook
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
preview_controller.params.permit!
|
|
92
|
-
@preview_params = preview_controller.params.to_h.select do |key, value|
|
|
93
|
-
!!@params.find { |param_tag| param_tag.name == key.to_s }
|
|
94
|
-
end
|
|
95
92
|
end
|
|
96
93
|
|
|
97
94
|
def inspector_data
|
|
98
95
|
return @inspector_data if @inspector_data.present?
|
|
99
96
|
|
|
100
|
-
|
|
101
|
-
preview_params: @preview_params,
|
|
102
|
-
path: params[:path]
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
preview = @preview
|
|
106
|
-
target_examples = (@target.type == :group) ? @target.examples : [@target]
|
|
107
|
-
|
|
108
|
-
examples = target_examples.map do |example|
|
|
109
|
-
render_args = @preview.render_args(example.name, params: preview_controller.params)
|
|
110
|
-
has_template = render_args[:template] != "view_components/preview"
|
|
97
|
+
rendered_examples = @target.examples.map do |example|
|
|
111
98
|
output = preview_controller.process(:render_example_to_string, @preview, example.name)
|
|
112
|
-
|
|
113
|
-
source_lang = has_template ? example.template_lang(render_args[:template]) : example.lang
|
|
114
|
-
|
|
115
|
-
example.define_singleton_method(:output, proc { output })
|
|
116
|
-
example.define_singleton_method(:source, proc { source })
|
|
117
|
-
example.define_singleton_method(:source_lang, proc { source_lang })
|
|
118
|
-
example
|
|
99
|
+
RenderedExample.new(example, output, preview_controller.params)
|
|
119
100
|
end
|
|
120
101
|
|
|
121
|
-
target = (@target.type == :group) ? @target : examples.find { |e| e.lookup_path == @target.lookup_path }
|
|
122
|
-
|
|
123
|
-
params_ref = @params
|
|
124
|
-
preview.define_singleton_method(:params, proc { params_ref })
|
|
125
|
-
|
|
126
102
|
@inspector_data ||= Lookbook::Store.new({
|
|
127
|
-
context:
|
|
128
|
-
preview: preview,
|
|
129
|
-
examples:
|
|
130
|
-
|
|
131
|
-
target: target,
|
|
103
|
+
context: Store.new({params: @params, path: params[:path]}),
|
|
104
|
+
preview: @preview,
|
|
105
|
+
examples: rendered_examples,
|
|
106
|
+
target: @target,
|
|
132
107
|
data: Lookbook.data,
|
|
133
108
|
app: Lookbook
|
|
134
109
|
})
|
|
@@ -9,16 +9,16 @@ module Lookbook
|
|
|
9
9
|
helper Lookbook::ComponentHelper
|
|
10
10
|
|
|
11
11
|
before_action :generate_theme_overrides
|
|
12
|
-
before_action :
|
|
12
|
+
before_action :assign_instance_vars
|
|
13
13
|
|
|
14
14
|
def self.controller_path
|
|
15
15
|
"lookbook"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def index
|
|
19
|
-
landing = Lookbook.pages.find(&:landing) || Lookbook.pages.first
|
|
19
|
+
landing = Lookbook.pages.find(&:landing?) || Lookbook.pages.first
|
|
20
20
|
if landing.present?
|
|
21
|
-
redirect_to lookbook_page_path(landing.
|
|
21
|
+
redirect_to lookbook_page_path(landing.path)
|
|
22
22
|
else
|
|
23
23
|
render "lookbook/index"
|
|
24
24
|
end
|
|
@@ -30,9 +30,11 @@ module Lookbook
|
|
|
30
30
|
@theme_overrides ||= Lookbook.theme.to_css
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
def
|
|
34
|
-
@previews =
|
|
35
|
-
@pages =
|
|
33
|
+
def assign_instance_vars
|
|
34
|
+
@previews = Lookbook.previews
|
|
35
|
+
@pages = Lookbook.pages
|
|
36
|
+
@config = Lookbook.config
|
|
37
|
+
@engine = Lookbook.engine
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def feature_enabled?(feature)
|
|
@@ -48,7 +50,7 @@ module Lookbook
|
|
|
48
50
|
error_params = {}
|
|
49
51
|
if exception.is_a?(ViewComponent::PreviewTemplateError)
|
|
50
52
|
error_params = {
|
|
51
|
-
file_path: @preview&.
|
|
53
|
+
file_path: @preview&.file_path,
|
|
52
54
|
line_number: 0,
|
|
53
55
|
source_code: @target&.source
|
|
54
56
|
}
|
|
@@ -11,8 +11,8 @@ module Lookbook
|
|
|
11
11
|
def render_page(page, locals = {})
|
|
12
12
|
@page = page
|
|
13
13
|
@pages = Lookbook.pages
|
|
14
|
-
@next_page = @pages.
|
|
15
|
-
@previous_page = @pages.
|
|
14
|
+
@next_page = @pages.next(@page)
|
|
15
|
+
@previous_page = @pages.previous(@page)
|
|
16
16
|
|
|
17
17
|
content = ActionViewAnnotationsHandler.call(disable_annotations: true) do
|
|
18
18
|
render_to_string inline: @page.content, locals: {
|
|
@@ -9,9 +9,9 @@ module Lookbook
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def index
|
|
12
|
-
landing = Lookbook.pages.find(&:landing) || Lookbook.pages.first
|
|
12
|
+
landing = Lookbook.pages.find(&:landing?) || Lookbook.pages.first
|
|
13
13
|
if landing.present?
|
|
14
|
-
redirect_to lookbook_page_path
|
|
14
|
+
redirect_to lookbook_page_path(landing.path)
|
|
15
15
|
else
|
|
16
16
|
show_404
|
|
17
17
|
end
|
|
@@ -20,21 +20,15 @@ module Lookbook
|
|
|
20
20
|
def show
|
|
21
21
|
@page = @pages.find_by_path(params[:path])
|
|
22
22
|
if @page
|
|
23
|
-
@next_page = @pages.
|
|
24
|
-
@previous_page = @pages.
|
|
25
|
-
|
|
23
|
+
@next_page = @pages.next(@page)
|
|
24
|
+
@previous_page = @pages.previous(@page)
|
|
25
|
+
begin
|
|
26
|
+
@page_content = page_controller.render_page(@page)
|
|
27
|
+
@title = @page.title
|
|
28
|
+
rescue => exception
|
|
26
29
|
render_in_layout "lookbook/error",
|
|
27
30
|
layout: "lookbook/page",
|
|
28
|
-
error: @page.
|
|
29
|
-
else
|
|
30
|
-
begin
|
|
31
|
-
@page_content = page_controller.render_page(@page)
|
|
32
|
-
@title = @page.title
|
|
33
|
-
rescue => exception
|
|
34
|
-
render_in_layout "lookbook/error",
|
|
35
|
-
layout: "lookbook/page",
|
|
36
|
-
error: Lookbook::Error.new(exception, file_path: @page.full_path, source_code: @page.content)
|
|
37
|
-
end
|
|
31
|
+
error: Lookbook::Error.new(exception, file_path: @page.file_path, source_code: @page.content)
|
|
38
32
|
end
|
|
39
33
|
else
|
|
40
34
|
show_404
|
|
@@ -3,7 +3,7 @@ module Lookbook
|
|
|
3
3
|
include Utils
|
|
4
4
|
|
|
5
5
|
def page_path(id)
|
|
6
|
-
page = id.is_a?(Page) ? id : Lookbook.pages.
|
|
6
|
+
page = id.is_a?(Page) ? id : Lookbook.pages.find_by_id(id)
|
|
7
7
|
if page.present?
|
|
8
8
|
lookbook_page_path page.lookup_path
|
|
9
9
|
else
|
|
@@ -16,10 +16,13 @@ module Lookbook
|
|
|
16
16
|
|
|
17
17
|
@embed_counter ||= 0
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
preview = if args.first.is_a?(Symbol)
|
|
20
|
+
Lookbook.previews.find_by_path(args.first)
|
|
21
|
+
else
|
|
22
|
+
Lookbook.previews.find_by_preview_class(args.first)
|
|
23
|
+
end
|
|
22
24
|
|
|
25
|
+
example = args[1] ? preview&.example(args[1]) : preview&.default_example
|
|
23
26
|
embed_id = "#{url_for}/embed/#{example.lookup_path}".delete_prefix("/").tr("/", "-")
|
|
24
27
|
|
|
25
28
|
lookbook_render :embed,
|