Class: Breakfast::CompilationListener

Inherits:
Object
  • Object
show all
Defined in:
lib/breakfast/compilation_listener.rb

Constant Summary collapse

EXTENSIONS =
["css", "js", "html"].freeze
CHANNEL =
"breakfast_live_reload".freeze

Class Method Summary collapse

Class Method Details

.start(asset_output_folders:, view_folders:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/breakfast/compilation_listener.rb', line 6

def self.start(asset_output_folders:, view_folders:)
  listen_to_paths = Array.wrap(asset_output_folders) + Array.wrap(view_folders)

  listener = ::Listen.to(*listen_to_paths) do |modified, added, removed|
    files = modified + added + removed

    EXTENSIONS.each do |extension|
      if files.any? { |file| file.match(/\.#{extension}/) }
        ActionCable.server.broadcast(CHANNEL, { extension: extension })
      end
    end
  end

  listener.start
end