Skip to content

Commit

Permalink
Engine mounting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed May 29, 2024
1 parent ee4fefd commit fc0ecbb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Mount Lookbook at a path of your choosing in your `config/routes.rb` file:
```rb
Rails.application.routes.draw do
if Rails.env.development?
mount Lookbook::Engine => "/lookbook"
Lookbook::Engine.mount("/lookbook")
end
end
```
Expand Down
4 changes: 3 additions & 1 deletion lib/lookbook/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def defaults

languages: default_languages,

reload_on_change: dev?
reload_on_change: dev?,

mount_path: "/lookbook"
})
end

Expand Down
11 changes: 10 additions & 1 deletion lib/lookbook/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@ def boot!
info("Lookbook initialized#{" - watching filesystem for changes" if watch_files?}")
end

def mount(mount_path = nil)
config.lookbook.mount_path = mount_path unless mount_path.nil?

Rails.application.routes.draw do
mount Lookbook::Engine => Lookbook::Engine.mount_path
end
end

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

def view_paths
Expand Down
2 changes: 1 addition & 1 deletion test/demo/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Rails.application.routes.draw do
root "demo#index"

mount Lookbook::Engine => "/lookbook"
Lookbook::Engine.mount("/lookbook")
end

0 comments on commit fc0ecbb

Please sign in to comment.