lib/lookbook/engine.rb in lookbook-2.3.2 vs lib/lookbook/engine.rb in lookbook-2.3.3

- old
+ new

@@ -69,14 +69,16 @@ config.after_initialize do if Engine.reloading? reloaders.add(:previews, Engine.preview_watch_paths, opts.listen_extensions, &Engine.method(:load_previews)) reloaders.add(:pages, Engine.page_watch_paths, opts.page_extensions, &Engine.method(:load_pages)) - reloaders.execute + reloaders.execute unless opts.lazy_load_previews_and_pages else - Engine.load_previews - Engine.load_pages + unless opts.lazy_load_previews_and_pages + Engine.load_previews + Engine.load_pages + end end Engine.run_hooks(:after_initialize) end @@ -194,31 +196,57 @@ end end def pages @_pages ||= PageCollection.new + + if opts.lazy_load_previews_and_pages && !@_loaded_pages + @_loaded_pages = true + + if reloading? + reloaders.execute(:pages) + else + load_pages + end + end + + @_pages end def previews @_previews ||= PreviewCollection.new + + if opts.lazy_load_previews_and_pages && !@_loaded_previews + @_loaded_previews = true + + if reloading? + reloaders.execute(:previews) + else + load_previews + end + end + + @_previews end def preview_controller @_preview_controller = opts.preview_controller.constantize @_preview_controller.include PreviewControllerActions end def load_previews(changes = nil) + puts "----------------------------- LOADING PREVIEWS" changed_files = [*changes[:added], *changes[:modified]] if changes parser.parse(changed_files) do |code_objects| previews.load(code_objects.all(:class), changes) end rescue => e Lookbook.logger.error(e) raise e end def load_pages(changes = nil) + puts "----------------------------- LOADING PAGES" pages.load(Engine.page_paths, changes) rescue => e Lookbook.logger.error(e) raise e end