You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi :) We are also using Lookbook inside a Common UI components Rails Engine in basically the same structure as outlined in this issue: #359
We're encountering either a bug, or a situation where something isn't quite configured right, such that config.lookbook isn't available in our engine init code.
Also something around prepend_view_path is maybe not quite right?
To Reproduce
Steps to reproduce the behavior:
We're trying to override the template used for rendering groups (via a file engines/ui/app/views/lookbook/previews/group.html.erb). We've put that file in, and made a custom Controller (see below)
Trying to follow some of the suggestions from the other issue, including the line config.lookbook.preview_controller = 'Ui::PreviewController' causes an undefined method 'lookbook' crash on startup:
Interestingly, config.view_component.preview_controller seems to work fine.
Additionally, we have tried moving the require 'lookbook' etc lines into the engines/ui.rb top level file as the other issue showed, but this doesn't seem to make a difference.
Additionally (and this maybe might be useful to update docs around, (or maybe? a bug)..
using prepend_view_path directly in the overridden controller class didn't work, but overriding the prepend_application_view_paths method can be made to pick up the new views path
(see the code below)
Expected behavior
We can override the preview_controller such that we can pick up our alternative group template
Version numbers
Please complete the following information:
Lookbook: 2.3.2
ViewComponent: 3.14.0
Rails: 7.0.8.4
Ruby: 3.2.2
Additional context
The gemspec file for our engine contains these deps
require'lookbook'require'view_component'moduleUiclassEngine < ::Rails::Engineisolate_namespaceUiconfig.view_component.preview_paths << Ui::Engine.root.join('app/previews')config.view_component.default_preview_layout='previews'config.view_component.preview_controller='Ui::PreviewController'# This one doesn't crash at leastconfig.lookbook.preview_controller='Ui::PreviewController'# This is the line that crashesinitializer'ui.assets'do |app|
app.config.sass.load_paths << Ui::Engine.root.join('app/components')app.config.assets.paths << Ui::Engine.root.join('app/components')endendend
moduleUiclassPreviewController < Lookbook::PreviewControllerprepend_view_pathUi::Engine.root.join('app/views')# this didn't work# This does thoughprivatedefprepend_application_view_pathssuperprepend_view_pathUi::Engine.root.join('app/views')endendend
The text was updated successfully, but these errors were encountered:
Hey @joffotron, thanks for this - and I appreciate all the detailed info :)
At first glance I'm not sure why trying to access the Lookbook config at start up might cause the app to crash. Some sort of load/initialization order issue maybe but hard to say without digging in a bit deeper.
Just to check - with the workarounds you've described above is the group customisation actually working for you now?
I think I need to set up a very basic Engine along the lines of the one you describe here see if I can replicate it and figure out what is going on. Unless your component library UI engine is open source so I can pull that down and poke around - I'm guessing not?
Tbh it would be good to have an simple (working) example implementation of this sort of setup to point people to if they want to do something similar so I'll try and put something together when I get a chance and see if I can debug the issue.
I'm afraid I don't have as much time as I'd like to work on Lookbook at the moment so it might take me a little while but I'll update you here if I manage to figure out what's going on!
Describe the bug
Hi :) We are also using Lookbook inside a Common UI components Rails Engine in basically the same structure as outlined in this issue: #359
We're encountering either a bug, or a situation where something isn't quite configured right, such that
config.lookbook
isn't available in our engine init code.Also something around
prepend_view_path
is maybe not quite right?To Reproduce
Steps to reproduce the behavior:
We're trying to override the template used for rendering groups (via a file
engines/ui/app/views/lookbook/previews/group.html.erb
). We've put that file in, and made a custom Controller (see below)Trying to follow some of the suggestions from the other issue, including the line
config.lookbook.preview_controller = 'Ui::PreviewController'
causes anundefined method 'lookbook'
crash on startup:Interestingly,
config.view_component.preview_controller
seems to work fine.Additionally, we have tried moving the
require 'lookbook'
etc lines into theengines/ui.rb
top level file as the other issue showed, but this doesn't seem to make a difference.Additionally (and this maybe might be useful to update docs around, (or maybe? a bug)..
using
prepend_view_path
directly in the overridden controller class didn't work, but overriding theprepend_application_view_paths
method can be made to pick up the new views path(see the code below)
Expected behavior
We can override the preview_controller such that we can pick up our alternative group template
Version numbers
Please complete the following information:
Additional context
The
gemspec
file for our engine contains these depsThe
engine.rb
file is thus:engines/ui/app/controllers/ui/preview_controller.rb
:The text was updated successfully, but these errors were encountered: