From 2a3dec5f1c7e73a382d9628be6c297f765769c2b Mon Sep 17 00:00:00 2001 From: Eric Berry Date: Sun, 5 Feb 2023 18:51:31 -0700 Subject: [PATCH] Add lookbook with preview --- config/routes.rb | 1 + lib/component_library.rb | 1 + lib/component_library/engine.rb | 7 ++++++- spec/dummy/config/routes.rb | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index d45c142..676b304 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true ComponentLibrary::Engine.routes.draw do + mount Lookbook::Engine, at: "/" end diff --git a/lib/component_library.rb b/lib/component_library.rb index 9a5d365..aaa4554 100644 --- a/lib/component_library.rb +++ b/lib/component_library.rb @@ -4,6 +4,7 @@ require "component_library/engine" require "dry-initializer" +require "lookbook" module ComponentLibrary # Your code goes here... diff --git a/lib/component_library/engine.rb b/lib/component_library/engine.rb index f9c242d..688bf8a 100644 --- a/lib/component_library/engine.rb +++ b/lib/component_library/engine.rb @@ -9,10 +9,15 @@ class Engine < ::Rails::Engine config.generators { |g| g.test_framework :rspec } - component_path = root.join("app", "components") + component_path = root.join("app", "components", "component_library") config.autoload_paths << component_path config.view_component.preview_paths << component_path + initializer 'lookbook.autoload' do + config.lookbook.project_name = "Component Library" + config.lookbook.preview_paths = [component_path] + end + initializer 'component_library.autoload' do ActiveSupport.on_load(:view_component) do # Make it possible to store previews in sidecar folders diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 3bf690d..7e7c60f 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true Rails.application.routes.draw do - mount ComponentLibrary::Engine => "/component_library" + mount ComponentLibrary::Engine => "/" end