lib/lookbook/engine.rb in lookbook-1.0.0.beta.4 vs lib/lookbook/engine.rb in lookbook-1.0.0.beta.5

- old
+ new

@@ -34,14 +34,22 @@ def previews Preview.all end + def previews? + Preview.any? + end + def pages Page.all end + def pages? + Page.any? + end + def after_initialize(&block) add_hook(:after_initialize, block) end def before_exit(&block) @@ -110,14 +118,15 @@ @preview_controller = Lookbook.config.preview_controller.constantize @preview_controller.include(Lookbook::PreviewController) if config.lookbook.listen Listen.logger = Lookbook.logger + preview_listener = Listen.to( *config.lookbook.listen_paths, - only: /\.(rb|html.*)$/, - force_polling: Lookbook.config.listen_use_polling + only: /\.(#{config.lookbook.listen_extensions.join("|")})$/, + force_polling: config.lookbook.listen_use_polling ) do |modified, added, removed| changes = { modified: modified, added: added, removed: removed } begin parser.parse rescue @@ -129,11 +138,11 @@ Lookbook::Engine.register_listener(preview_listener) page_listener = Listen.to( *config.lookbook.page_paths, only: /\.(html.*|md.*)$/, - force_polling: Lookbook.config.listen_use_polling + force_polling: config.lookbook.listen_use_polling ) do |modified, added, removed| changes = { modified: modified, added: added, removed: removed } Lookbook::Engine.reload_ui(changes) Lookbook::Engine.run_hooks(:after_change, changes) end @@ -164,22 +173,23 @@ end class << self def websocket + return @websocket unless @websocket.nil? if config.lookbook.auto_refresh cable = ActionCable::Server::Configuration.new cable.cable = {adapter: "async"}.with_indifferent_access cable.mount_path = config.lookbook.cable_mount_path cable.connection_class = -> { Lookbook::Connection } cable.logger = config.lookbook.cable_logger @websocket ||= if Rails.version.to_f >= 6.0 ActionCable::Server::Base.new(config: cable) else - websocket ||= ActionCable::Server::Base.new - websocket.config = cable - websocket + @websocket ||= ActionCable::Server::Base.new + @websocket.config = cable + @websocket end end end def websocket_mount_path