Packages
phoenix_live_reload
0.3.3
1.6.2
1.6.1
1.6.0
1.5.3
1.5.2
1.5.1
1.5.0
1.4.1
1.4.0
1.3.3
1.3.2
1.3.1
1.3.0
1.2.4
1.2.3
retired
1.2.2
1.2.1
1.2.0
1.2.0-rc.0
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.6.0
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Provides live-reload functionality for Phoenix
Current section
Files
Jump to
Current section
Files
lib/phoenix_live_reload/channel.ex
defmodule Phoenix.LiveReload.Channel do
use Phoenix.Channel
@moduledoc """
Phoenix's live-reload channel
"""
def join("phoenix:live_reload", _msg, socket) do
{:ok, _} = Application.ensure_all_started(:phoenix_live_reload)
patterns = socket.endpoint.config(:live_reload)[:patterns]
:fs.subscribe()
{:ok, assign(socket, :patterns, patterns)}
end
def handle_info({_pid, {:fs, :file_event}, {path, _event}}, socket) do
if matches_any_pattern?(path, socket.assigns[:patterns]) do
asset_type = Path.extname(path) |> String.lstrip(?.)
push socket, "assets_change", %{asset_type: asset_type}
end
{:noreply, socket}
end
def matches_any_pattern?(path, patterns) do
path = to_string(path)
Enum.any?(patterns, fn pattern ->
String.match?(path, pattern) and !String.match?(path, ~r/_build/)
end)
end
end