Skip to content

Commit

Permalink
Remove auto-mount
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed May 29, 2024
1 parent 8cbf8c5 commit ee4fefd
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ group :development do
end
```

Lookbook will automatically be mounted at `/lookbook` within your app when the server is started.
Mount Lookbook at a path of your choosing in your `config/routes.rb` file:

> 🚨 Previously Lookbook required manual mounting in your app. This is **no longer the case**, so if trialing v3 in a project with an existing Lookbook install you must remove [the mounting code](https://lookbook.build/guide/installation#step-2) from your routes.rb file first.
```rb
Rails.application.routes.draw do
if Rails.env.development?
mount Lookbook::Engine => "/lookbook"
end
end
```

> The mount path (`/lookbook` in the example above) will be the URL that the Lookbook UI will be made accessible at within your app.
Once everything is installed, start your app as normal.

Assuming your app is running on port 3000 and you mounted Lookbook at the path `/lookbook` then browse to http://localhost:3000/lookbook to view the Lookbook UI.

### Configuration

Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions config/initializers/04_mount_lookbook.rb

This file was deleted.

7 changes: 0 additions & 7 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,3 @@

match "*path", to: "application#not_found", via: :all
end

Rails.application.routes.draw do
get "#{Lookbook.config.mount_path}/render_scenario/:preview/:scenario",
to: "#{Lookbook.config.preview_controller.sub(/Controller$/, "").underscore}#lookbook_render_scenario",
as: :lookbook_render_scenario,
internal: true
end
4 changes: 1 addition & 3 deletions lib/lookbook/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def defaults

languages: default_languages,

reload_on_change: dev?,
mount_path: "/lookbook",
auto_mount: true
reload_on_change: dev?
})
end

Expand Down
11 changes: 9 additions & 2 deletions lib/lookbook/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ class Engine < Rails::Engine
YARD::Parser::Ruby::RipperParser.prepend YardParserPatch
end

config.after_initialize do
config.after_initialize do |app|
ViewComponentConfigSync.call if Gem.loaded_specs.has_key?("view_component")

preview_controller = Lookbook.config.preview_controller.constantize
unless preview_controller.include?(Lookbook::PreviewControllerActions)
preview_controller.include(Lookbook::PreviewControllerActions)
end

app.routes.prepend do
get "#{Engine.mount_path}/render_scenario/:preview/:scenario",
to: "#{Lookbook.config.preview_controller.sub(/Controller$/, "").underscore}#lookbook_render_scenario",
as: :lookbook_render_scenario,
internal: true
end

boot!
end

Expand All @@ -44,7 +51,7 @@ def boot!
end

def mount_path
config.lookbook.mount_path || Lookbook::Config.defaults.mount_path
"/" + Utils.strip_slashes(routes.find_script_name({}))
end

def view_paths
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/demo/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Rails.application.routes.draw do
root "demo#index"

mount Lookbook::Engine => "/lookbook"
end

0 comments on commit ee4fefd

Please sign in to comment.