lookbook 1.0.0.rc.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -54
- data/app/components/lookbook/embed/component.html.erb +5 -5
- data/app/components/lookbook/embed/component.rb +1 -1
- data/app/components/lookbook/header/component.html.erb +4 -4
- data/app/components/lookbook/icon/component.html.erb +1 -1
- data/app/components/lookbook/inspector_panel/component.rb +1 -2
- data/app/controllers/lookbook/previews_controller.rb +20 -18
- data/app/helpers/lookbook/component_helper.rb +4 -0
- data/app/views/lookbook/index.html.erb +1 -1
- data/app/views/lookbook/previews/show.html.erb +2 -2
- data/config/routes.rb +1 -1
- data/lib/lookbook/component.rb +4 -0
- data/lib/lookbook/engine.rb +74 -52
- data/lib/lookbook/page.rb +4 -4
- data/lib/lookbook/preview.rb +6 -2
- data/lib/lookbook/version.rb +1 -1
- data/public/lookbook-assets/js/lookbook.js +53 -53
- data/public/lookbook-assets/js/lookbook.js.map +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3f13cba228b6a66ef0c31377116296e1eb1c8b53e3fd5b54ca257780cb30498
|
4
|
+
data.tar.gz: 3c9e509969d78ea297e39649b43d4a8613f97c7be8e0845603b313524bff316b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afeead86c2ccbb4cfd6e9afc20641474dbd5ab153916b5602f374750a41aaaec329516b36b39a964740701a536dd52683f9322e039fde3d4f9c83d7101290720
|
7
|
+
data.tar.gz: 54046d3840469aac423eef1b9c9dd88132e7282cda794b5e1ebd9ab8518a05a8184b3d037915e8c2a1dc9c61b5644a314735a05c5de8de8c0fdda6c23acebe55
|
data/README.md
CHANGED
@@ -1,83 +1,52 @@
|
|
1
|
-
# Lookbook
|
1
|
+
# Lookbook
|
2
2
|
|
3
3
|
<div>
|
4
|
-
<a href="https://rubygems.org/gems/lookbook"><img src="https://img.shields.io/gem/v/lookbook
|
5
|
-
<img src="https://github.com/allmarkedup/lookbook/actions/workflows/ci.yml/badge.svg?branch=
|
4
|
+
<a href="https://rubygems.org/gems/lookbook"><img src="https://img.shields.io/gem/v/lookbook" alt="Gem version"></a>
|
5
|
+
<a href="https://github.com/allmarkedup/lookbook/actions/workflows/ci.yml"><img src="https://github.com/allmarkedup/lookbook/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI status"></a>
|
6
6
|
</div>
|
7
7
|
<br>
|
8
8
|
|
9
|
-
|
10
|
-
>_For code and documentation for the current stable release see the [main branch](https://github.com/allmarkedup/lookbook/tree/main)._
|
9
|
+
A tool to help browse, develop, test & document [ViewComponents](https://viewcomponent.org/) in Ruby on Rails apps.
|
11
10
|
|
11
|
+
## Documentation
|
12
12
|
|
13
|
-
|
13
|
+
**Lookbook (v1.x)** documentation: **[https://lookbook.build](https://lookbook.build)**
|
14
14
|
|
15
|
-
|
15
|
+
> _Looking for v0.9.x docs? [Head over here](https://github.com/allmarkedup/lookbook/tree/0.9.x)._
|
16
16
|
|
17
|
-
```ruby
|
18
|
-
gem "lookbook", ">= 1.0.0.beta.8"
|
19
|
-
```
|
20
17
|
|
21
|
-
|
18
|
+
## Demo
|
22
19
|
|
20
|
+
**Online Demo:** [https://lookbook-demo-app.herokuapp.com/lookbook](https://lookbook-demo-app.herokuapp.com/lookbook)
|
23
21
|
|
24
|
-
|
22
|
+
[![Lookbook UI](.github/assets/lookbook_screenshot_v1.0_beta.png)](https://lookbook-demo-app.herokuapp.com/lookbook/)
|
25
23
|
|
26
|
-
* 👉 <a href="https://beta.lookbook.build/">v1.0 docs</a>
|
27
|
-
* 👉 <a href="https://lookbook-demo-app-v1-0-beta.herokuapp.com/lookbook">v1.0 demo app</a> <em>(The repo for the demo <a href="https://github.com/allmarkedup/lookbook-demo/tree/v1.0-beta">is here</a> if you want to dig in further)</em>
|
28
24
|
|
25
|
+
## Development
|
29
26
|
|
30
|
-
|
31
|
-
## Changes and new features in v1.0
|
32
|
-
|
33
|
-
Lookbook v1.0 includes a completely re-written UI, many under-the hood improvements and a some exciting new customisation options.
|
34
|
-
|
35
|
-
### Frontend changes:
|
36
|
-
|
37
|
-
* Completely re-written UI - now built with ViewComponents
|
38
|
-
* New [UI themes and customisation options](https://beta.lookbook.build/guide/themes/)
|
39
|
-
* Improved small-screen/mobile view
|
40
|
-
* Debug menu
|
41
|
-
* ...and many other small visual and usability improvements
|
42
|
-
|
43
|
-
### New options for extending Lookbook:
|
44
|
-
|
45
|
-
* Define [custom tags](https://beta.lookbook.build/guide/extend/tags/) for preview file annotations
|
46
|
-
* Create [your own tab panels](https://beta.lookbook.build/guide/extend/panels/) - with complete control over content/layout and access to all Lookbook data
|
47
|
-
* Use [lifecycle hooks](https://beta.lookbook.build/guide/extend/hooks/) to run your own code when Lookbook starts up, when files change or at shutdown
|
48
|
-
|
49
|
-
### Other changes
|
50
|
-
|
51
|
-
* 'Workbench' app for developing Lookbook's UI components in Lookbook
|
52
|
-
* New Rspec-based test suite and dummy app
|
53
|
-
* All new documentation site built using [Bridgetown](https://www.bridgetownrb.com/)
|
54
|
-
|
55
|
-
|
56
|
-
[![Lookbook UI](.github/assets/lookbook_screenshot_v1.0_beta.png)](https://lookbook-demo-app-v1-0-beta.herokuapp.com/lookbook/)
|
57
|
-
|
58
|
-
## Workbench
|
59
|
-
|
60
|
-
As of this release, Lookbook's UI is itself built using ViewComponent components. To help with development it is possible to preview these components (in a Lookbook instance!) by running the included 'Workbench" app, as follows:
|
27
|
+
Lookbook's UI is itself built using ViewComponents. To preview these components in a Lookbook instance you can run the included `workbench` app:
|
61
28
|
|
62
29
|
1. Clone this repo
|
63
30
|
2. Install dependencies: `bundle install & npm install`
|
64
|
-
3. Start the
|
65
|
-
4.
|
31
|
+
3. Start the app: `bin/workbench`
|
32
|
+
4. Visit http://localhost:4545/lookbook to view the Lookbook instance
|
33
|
+
|
34
|
+
The `workbench` app will be started in development mode and any changes to Lookbook's views or assets will immediately be reflected in the UI.
|
66
35
|
|
67
|
-
|
36
|
+
### Docs site
|
68
37
|
|
38
|
+
The [Lookbook docs site](https://lookbook.build) is built using [Bridgetown](https://www.bridgetownrb.com/) and the source files can be found in the `./docs` directory.
|
69
39
|
|
70
|
-
|
40
|
+
To see a local version of the site run `bin/docs` from the root of this repo and then visit http://localhost:4000 in your browser.
|
71
41
|
|
72
|
-
|
42
|
+
### Testing
|
73
43
|
|
74
|
-
|
44
|
+
Lookbook uses RSpec for testing.
|
75
45
|
|
76
|
-
|
77
|
-
- The dummy app that the tests are being run against can be viewed by running the `rake lookbook:test:serve` command and then browsing to http://localhost:9292/lookbook
|
46
|
+
Tests can be run using the `rake spec` or `bundle exec rspec` commands.
|
78
47
|
|
48
|
+
The dummy app that the tests are being run against can be viewed by running the `bin/dummy` command and then browsing to http://localhost:9292/lookbook
|
79
49
|
|
80
|
-
---
|
81
50
|
|
82
51
|
## License
|
83
52
|
|
@@ -1,19 +1,19 @@
|
|
1
|
-
<% if @
|
1
|
+
<% if @target.present? %>
|
2
2
|
<%= render_component_tag class: "not-prose border-b border-lookbook-divider rounded-sm overflow-hidden", "@navigation:start.window": "cleanup" do %>
|
3
3
|
|
4
4
|
<%= render_component :toolbar, class: "border border-b-0 border-lookbook-divider" do |toolbar| %>
|
5
5
|
<% toolbar.section padded: true do %>
|
6
6
|
<h3>
|
7
|
-
<%= @
|
7
|
+
<%= @target.preview.label %> (<%= @target.label %>)
|
8
8
|
</h3>
|
9
9
|
<% end %>
|
10
10
|
<% toolbar.section align: :right, divide: :left do %>
|
11
11
|
<%= render_component :button_group do |group| %>
|
12
12
|
<% group.button icon: :eye,
|
13
|
-
href: lookbook_inspect_path(@
|
13
|
+
href: lookbook_inspect_path(@target.path, @params),
|
14
14
|
tooltip: "View in Inspector" %>
|
15
15
|
<% group.button icon: :external_link,
|
16
|
-
href: lookbook_preview_path(@
|
16
|
+
href: lookbook_preview_path(@target.path, @params),
|
17
17
|
tooltip: "Open in new window",
|
18
18
|
target: "_blank" %>
|
19
19
|
<% end %>
|
@@ -28,7 +28,7 @@
|
|
28
28
|
@viewport:resize-complete="resizeIframe"
|
29
29
|
@tabs:change.window="resizeIframe">
|
30
30
|
<%= render_component :viewport,
|
31
|
-
src: lookbook_preview_path(@
|
31
|
+
src: lookbook_preview_path(@target.path, @params.merge(lookbook_embed: true)),
|
32
32
|
alpine_data: "store",
|
33
33
|
resize_height: false,
|
34
34
|
max_height: @max_height,
|
@@ -46,11 +46,11 @@
|
|
46
46
|
<span class="opacity-70 mr-1">Lookbook</span>
|
47
47
|
<span class="mr-6">v<%= Lookbook::VERSION %></span>
|
48
48
|
<div class="flex items-center space-x-2">
|
49
|
-
|
50
|
-
<%= icon
|
51
|
-
</a
|
49
|
+
<a href="https://lookbook.build/guide" target="_blank" class="ml-auto opacity-70" title="Documentation">
|
50
|
+
<%= icon :book, size: 3 %>
|
51
|
+
</a>
|
52
52
|
<a href="https://github.com/allmarkedup/lookbook" target="_blank" class="ml-auto opacity-70" title="Github">
|
53
|
-
<%= icon
|
53
|
+
<%= icon :github, size: 3 %>
|
54
54
|
</a>
|
55
55
|
</div>
|
56
56
|
</div>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= render_component_tag :i, style: "height: #{size_rems}; width: #{size_rems}" do %>
|
1
|
+
<%= render_component_tag :i, style: "height: #{size_rems}; width: #{size_rems}; #{@html_attrs[:style]}" do %>
|
2
2
|
<svg>
|
3
3
|
<use :href="`/lookbook-assets/feather-sprite.svg#${iconName}`" x-cloak />
|
4
4
|
</svg>
|
@@ -25,9 +25,8 @@ module Lookbook
|
|
25
25
|
css_parser.each_selector do |selector, declarations, specificity|
|
26
26
|
@panel_styles += "##{id} #{selector} { #{declarations} }\n"
|
27
27
|
end
|
28
|
-
style_tag.unlink
|
29
28
|
end
|
30
|
-
@panel_html =
|
29
|
+
@panel_html = content.gsub(/<style(?:\s[^>]*)?>.*<\/style>/, "").html_safe
|
31
30
|
end
|
32
31
|
end
|
33
32
|
@panel_html ||= content
|
@@ -13,7 +13,7 @@ module Lookbook
|
|
13
13
|
before_action :set_params
|
14
14
|
|
15
15
|
def preview
|
16
|
-
if @
|
16
|
+
if @target
|
17
17
|
begin
|
18
18
|
opts = {layout: @preview.layout}
|
19
19
|
if params[:lookbook_embed] == "true"
|
@@ -32,7 +32,7 @@ module Lookbook
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def show
|
35
|
-
if @
|
35
|
+
if @target
|
36
36
|
begin
|
37
37
|
@main_panels = main_panels
|
38
38
|
@drawer_panels = drawer_panels
|
@@ -52,9 +52,9 @@ module Lookbook
|
|
52
52
|
private
|
53
53
|
|
54
54
|
def lookup_entities
|
55
|
-
@
|
56
|
-
if @
|
57
|
-
@preview = @
|
55
|
+
@target = Lookbook.previews.find_example(params[:path])
|
56
|
+
if @target.present?
|
57
|
+
@preview = @target.preview
|
58
58
|
if params[:path] == @preview&.lookup_path
|
59
59
|
redirect_to lookbook_inspect_path "#{params[:path]}/#{@preview.default_example.name}"
|
60
60
|
end
|
@@ -85,17 +85,17 @@ module Lookbook
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def target_examples
|
88
|
-
@
|
88
|
+
@target.type == :group ? @target.examples : [@target]
|
89
89
|
end
|
90
90
|
|
91
91
|
def set_title
|
92
|
-
@title = @
|
92
|
+
@title = @target.present? ? [@target&.label, @preview&.label].compact.join(" :: ") : "Not found"
|
93
93
|
end
|
94
94
|
|
95
95
|
def set_params
|
96
|
-
if @
|
96
|
+
if @target
|
97
97
|
# cast known params to type
|
98
|
-
@
|
98
|
+
@target.params.each do |param|
|
99
99
|
if preview_controller.params.key?(param[:name])
|
100
100
|
preview_controller.params[param[:name]] = Lookbook::Params.cast(preview_controller.params[param[:name]], param[:type])
|
101
101
|
end
|
@@ -103,7 +103,7 @@ module Lookbook
|
|
103
103
|
# set display and data params
|
104
104
|
preview_controller.params.merge!({
|
105
105
|
lookbook: {
|
106
|
-
display: @
|
106
|
+
display: @target.display_params,
|
107
107
|
data: Lookbook.data
|
108
108
|
}
|
109
109
|
})
|
@@ -113,7 +113,7 @@ module Lookbook
|
|
113
113
|
def preview_params
|
114
114
|
preview_controller.params.permit!
|
115
115
|
preview_controller.params.to_h.select do |key, value|
|
116
|
-
!!@
|
116
|
+
!!@target.params.find { |param| param[:name] == key }
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -125,12 +125,7 @@ module Lookbook
|
|
125
125
|
path: params[:path]
|
126
126
|
}
|
127
127
|
|
128
|
-
example = @example
|
129
128
|
preview = @preview
|
130
|
-
preview.define_singleton_method(:params, proc {
|
131
|
-
example.params
|
132
|
-
})
|
133
|
-
|
134
129
|
examples = target_examples.map do |example|
|
135
130
|
render_args = @preview.render_args(example.name, params: preview_controller.params)
|
136
131
|
has_template = render_args[:template] != "view_components/preview"
|
@@ -144,11 +139,18 @@ module Lookbook
|
|
144
139
|
example
|
145
140
|
end
|
146
141
|
|
142
|
+
target = @target.type == :group ? @target : examples.find { |e| e.lookup_path == @target.lookup_path }
|
143
|
+
|
144
|
+
preview.define_singleton_method(:params, proc {
|
145
|
+
target.params
|
146
|
+
})
|
147
|
+
|
147
148
|
@inspector_data ||= Lookbook::Store.new({
|
148
149
|
context: context_data,
|
149
150
|
preview: preview,
|
150
151
|
examples: examples,
|
151
|
-
example:
|
152
|
+
example: examples.first,
|
153
|
+
target: target,
|
152
154
|
data: Lookbook.data,
|
153
155
|
app: Lookbook
|
154
156
|
})
|
@@ -198,7 +200,7 @@ module Lookbook
|
|
198
200
|
{
|
199
201
|
file_path: @preview&.full_path,
|
200
202
|
line_number: 0,
|
201
|
-
source_code: @
|
203
|
+
source_code: @target&.source
|
202
204
|
}
|
203
205
|
elsif exception.is_a?(ActionView::Template::Error) & exception.message.include?("implements a reserved method")
|
204
206
|
message_parts = exception.message.split("\n").first.split
|
@@ -6,6 +6,10 @@ module Lookbook
|
|
6
6
|
render Lookbook::Icon::Component.new(name: name, **attrs)
|
7
7
|
end
|
8
8
|
|
9
|
+
def code(**attrs, &block)
|
10
|
+
render Lookbook::Code::Component.new(**attrs), &block
|
11
|
+
end
|
12
|
+
|
9
13
|
def render_component(ref, **attrs, &block)
|
10
14
|
klass = component_class(ref)
|
11
15
|
comp = attrs.key?(:content) ? klass.new(**attrs.except(:content)).with_content(attrs[:content]) : klass.new(**attrs)
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<% if Lookbook.previews? %>
|
8
8
|
<p>Select a preview from the nav to get started.</p>
|
9
9
|
<% else %>
|
10
|
-
<p><a class="underline" href="https://
|
10
|
+
<p><a class="underline" href="https://lookbook.build/guide/previews" target="_blank">Create a preview</a> to get started.</p>
|
11
11
|
<% end %>
|
12
12
|
</div>
|
13
13
|
</div>
|
@@ -29,7 +29,7 @@
|
|
29
29
|
<% group.button icon: :code,
|
30
30
|
tooltip: "Copy page embed code",
|
31
31
|
copy: true do %>
|
32
|
-
<%= embed <%= @preview.preview_class %>, :<%= @
|
32
|
+
<%= embed <%= @preview.preview_class %>, :<%= @target.name %>, params: <%= request.query_parameters.deep_symbolize_keys.to_s %> %>
|
33
33
|
<% end %>
|
34
34
|
<% end %>
|
35
35
|
|
@@ -38,7 +38,7 @@
|
|
38
38
|
"@click.stop": "startSpin(); $dispatch('viewport:reload'); stopSpin(500);" %>
|
39
39
|
|
40
40
|
<% group.button icon: :external_link,
|
41
|
-
href: lookbook_preview_path(@
|
41
|
+
href: lookbook_preview_path(@target.lookup_path, request.query_parameters),
|
42
42
|
tooltip: "Open preview in new window",
|
43
43
|
target: "_blank" %>
|
44
44
|
|
data/config/routes.rb
CHANGED
data/lib/lookbook/component.rb
CHANGED
data/lib/lookbook/engine.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require "view_component"
|
2
2
|
require "action_cable/engine"
|
3
3
|
require "listen"
|
4
|
-
require "rake"
|
5
4
|
|
6
5
|
module Lookbook
|
7
6
|
autoload :Config, "lookbook/config"
|
@@ -104,11 +103,13 @@ module Lookbook
|
|
104
103
|
# Rails.application.server is only available for newer Rails versions
|
105
104
|
Rails.application.server do
|
106
105
|
init_listeners
|
106
|
+
Lookbook::Engine.init_websocket
|
107
107
|
end
|
108
108
|
else
|
109
109
|
# Fallback for older Rails versions - don't start listeners if running in a rake task.
|
110
|
-
unless
|
110
|
+
unless Lookbook::Engine.prevent_listening?
|
111
111
|
init_listeners
|
112
|
+
Lookbook::Engine.init_websocket
|
112
113
|
end
|
113
114
|
end
|
114
115
|
|
@@ -127,64 +128,65 @@ module Lookbook
|
|
127
128
|
Lookbook::Engine.run_hooks(:after_initialize)
|
128
129
|
end
|
129
130
|
|
130
|
-
def init_listeners
|
131
|
-
return unless config.lookbook.listen == true
|
132
|
-
Listen.logger = Lookbook.logger
|
133
|
-
Lookbook.logger.info "Initializing listeners"
|
134
|
-
|
135
|
-
preview_listener = Listen.to(
|
136
|
-
*config.lookbook.listen_paths,
|
137
|
-
only: /\.(#{config.lookbook.listen_extensions.join("|")})$/,
|
138
|
-
force_polling: config.lookbook.listen_use_polling
|
139
|
-
) do |modified, added, removed|
|
140
|
-
changes = {modified: modified, added: added, removed: removed}
|
141
|
-
begin
|
142
|
-
Lookbook::Engine.parser.parse
|
143
|
-
rescue
|
144
|
-
end
|
145
|
-
Lookbook::Preview.clear_cache
|
146
|
-
Lookbook::Engine.reload_ui(changes)
|
147
|
-
Lookbook::Engine.run_hooks(:after_change, changes)
|
148
|
-
end
|
149
|
-
Lookbook::Engine.register_listener(preview_listener)
|
150
|
-
|
151
|
-
page_listener = Listen.to(
|
152
|
-
*config.lookbook.page_paths,
|
153
|
-
only: /\.(html.*|md.*)$/,
|
154
|
-
force_polling: config.lookbook.listen_use_polling
|
155
|
-
) do |modified, added, removed|
|
156
|
-
changes = {modified: modified, added: added, removed: removed}
|
157
|
-
Lookbook::Engine.reload_ui(changes)
|
158
|
-
Lookbook::Engine.run_hooks(:after_change, changes)
|
159
|
-
end
|
160
|
-
Lookbook::Engine.register_listener(page_listener)
|
161
|
-
end
|
162
|
-
|
163
131
|
at_exit do
|
164
132
|
if Lookbook::Engine.listeners.any?
|
165
133
|
Lookbook.logger.debug "Stopping listeners"
|
166
|
-
Lookbook::Engine.
|
134
|
+
Lookbook::Engine.stop_listeners
|
167
135
|
end
|
168
136
|
Lookbook::Engine.run_hooks(:before_exit)
|
169
137
|
end
|
170
138
|
|
171
139
|
class << self
|
172
|
-
def
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
ws
|
140
|
+
def init_listeners
|
141
|
+
config = Lookbook.config
|
142
|
+
return unless config.listen == true
|
143
|
+
Listen.logger = Lookbook.logger
|
144
|
+
|
145
|
+
preview_listener = Listen.to(
|
146
|
+
*config.listen_paths,
|
147
|
+
only: /\.(#{config.listen_extensions.join("|")})$/,
|
148
|
+
force_polling: config.listen_use_polling
|
149
|
+
) do |modified, added, removed|
|
150
|
+
changes = {modified: modified, added: added, removed: removed}
|
151
|
+
begin
|
152
|
+
parser.parse
|
153
|
+
rescue
|
187
154
|
end
|
155
|
+
Lookbook::Preview.clear_cache
|
156
|
+
reload_ui(changes)
|
157
|
+
run_hooks(:after_change, changes)
|
158
|
+
end
|
159
|
+
register_listener(preview_listener)
|
160
|
+
|
161
|
+
page_listener = Listen.to(
|
162
|
+
*config.page_paths,
|
163
|
+
only: /\.(html.*|md.*)$/,
|
164
|
+
force_polling: config.listen_use_polling
|
165
|
+
) do |modified, added, removed|
|
166
|
+
changes = {modified: modified, added: added, removed: removed}
|
167
|
+
reload_ui(changes)
|
168
|
+
run_hooks(:after_change, changes)
|
169
|
+
end
|
170
|
+
register_listener(page_listener)
|
171
|
+
end
|
172
|
+
|
173
|
+
def init_websocket
|
174
|
+
config = Lookbook.config
|
175
|
+
return unless config.auto_refresh == true
|
176
|
+
Lookbook.logger.info "Initializing websocket"
|
177
|
+
|
178
|
+
cable = ActionCable::Server::Configuration.new
|
179
|
+
cable.cable = {adapter: "async"}.with_indifferent_access
|
180
|
+
cable.mount_path = config.cable_mount_path
|
181
|
+
cable.connection_class = -> { Lookbook::Connection }
|
182
|
+
cable.logger = config.cable_logger
|
183
|
+
|
184
|
+
@websocket = if Gem::Version.new(Rails.version) >= Gem::Version.new(6.0)
|
185
|
+
ActionCable::Server::Base.new(config: cable)
|
186
|
+
else
|
187
|
+
ws = ActionCable::Server::Base.new
|
188
|
+
ws.config = cable
|
189
|
+
ws
|
188
190
|
end
|
189
191
|
end
|
190
192
|
|
@@ -192,6 +194,10 @@ module Lookbook
|
|
192
194
|
"#{mounted_path}#{config.lookbook.cable_mount_path}" if websocket
|
193
195
|
end
|
194
196
|
|
197
|
+
def websocket?
|
198
|
+
!!websocket
|
199
|
+
end
|
200
|
+
|
195
201
|
def mounted_path
|
196
202
|
Lookbook::Engine.routes.find_script_name({})
|
197
203
|
end
|
@@ -222,6 +228,10 @@ module Lookbook
|
|
222
228
|
@listeners ||= []
|
223
229
|
end
|
224
230
|
|
231
|
+
def stop_listeners
|
232
|
+
listeners.each { |listener| listener.stop }
|
233
|
+
end
|
234
|
+
|
225
235
|
def run_hooks(event_name, *args)
|
226
236
|
config.lookbook.hooks[event_name].each do |hook|
|
227
237
|
hook.call(Lookbook, *args)
|
@@ -232,7 +242,19 @@ module Lookbook
|
|
232
242
|
websocket&.broadcast("reload", changed)
|
233
243
|
end
|
234
244
|
|
235
|
-
|
245
|
+
def prevent_listening?
|
246
|
+
Rails.env.test? || running_in_rake_task?
|
247
|
+
end
|
248
|
+
|
249
|
+
def running_in_rake_task?
|
250
|
+
if defined?(Rake) && Rake.respond_to?(:application)
|
251
|
+
File.basename($0) == "rake" || Rake.application.top_level_tasks.any?
|
252
|
+
else
|
253
|
+
false
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
attr_reader :preview_controller, :websocket
|
236
258
|
end
|
237
259
|
end
|
238
260
|
end
|
data/lib/lookbook/page.rb
CHANGED
@@ -13,7 +13,7 @@ module Lookbook
|
|
13
13
|
:data
|
14
14
|
]
|
15
15
|
|
16
|
-
attr_reader :errors
|
16
|
+
attr_reader :errors, :rel_path
|
17
17
|
attr_accessor :sections
|
18
18
|
|
19
19
|
def initialize(path, base_path)
|
@@ -23,8 +23,8 @@ module Lookbook
|
|
23
23
|
@errors = []
|
24
24
|
@sections = []
|
25
25
|
@page_name = remove_position_prefix(path_name)
|
26
|
-
rel_path = @pathname.relative_path_from(@base_path)
|
27
|
-
page_path = rel_path.dirname.to_s == "." ? @page_name : "#{rel_path.dirname}/#{@page_name}"
|
26
|
+
@rel_path = @pathname.relative_path_from(@base_path)
|
27
|
+
page_path = @rel_path.dirname.to_s == "." ? @page_name : "#{@rel_path.dirname}/#{@page_name}"
|
28
28
|
super(page_path)
|
29
29
|
end
|
30
30
|
|
@@ -33,7 +33,7 @@ module Lookbook
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def full_path
|
36
|
-
Rails.root.join(@pathname.to_s)
|
36
|
+
Pathname.new Rails.root.join(@pathname.to_s)
|
37
37
|
end
|
38
38
|
|
39
39
|
def name
|
data/lib/lookbook/preview.rb
CHANGED
@@ -61,11 +61,15 @@ module Lookbook
|
|
61
61
|
examples.first
|
62
62
|
end
|
63
63
|
|
64
|
+
def rel_path
|
65
|
+
"#{name.underscore}.rb"
|
66
|
+
end
|
67
|
+
|
64
68
|
def full_path
|
65
69
|
base_path = Array(Lookbook.config.preview_paths).detect do |preview_path|
|
66
|
-
Dir["#{preview_path}/#{
|
70
|
+
Dir["#{preview_path}/#{rel_path}"].first
|
67
71
|
end
|
68
|
-
Pathname.new(Dir["#{base_path}/#{
|
72
|
+
Pathname.new(Dir["#{base_path}/#{rel_path}"].first)
|
69
73
|
end
|
70
74
|
|
71
75
|
def url_path
|
data/lib/lookbook/version.rb
CHANGED