class Lookbook::Engine
def init_listeners
def init_listeners if config.lookbook.listen @preview_listener = Listen.to(*config.lookbook.listen_paths, only: /\.(#{config.lookbook.listen_extensions.join("|")})$/) do |modified, added, removed| begin Lookbook::Engine.parser.parse rescue end Lookbook::Preview.clear_cache Lookbook::Engine.websocket&.broadcast("reload", { modified: modified, removed: removed, added: added }) end @preview_listener.start if Lookbook::Features.enabled?(:pages) @page_listener = Listen.to(*config.lookbook.page_paths.select { |dir| Dir.exist? dir }, only: /\.(html.*|md.*)$/) do |modified, added, removed| Lookbook::Engine.websocket&.broadcast("reload", { modified: modified, removed: removed, added: added }) end @page_listener.start end end end
def mounted_path
def mounted_path Lookbook::Engine.routes.find_script_name({}) end
def parser
def parser @parser ||= Lookbook::Parser.new(config.lookbook.preview_paths, config.lookbook.parser_registry_path) end
def websocket
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 ws = ActionCable::Server::Base.new ws.config = cable ws end end end
def websocket_mount_path
def websocket_mount_path "#{mounted_path}#{config.lookbook.cable_mount_path}" if websocket end