<commit_before>defmodule Serum.Plugins.LiveReloader do
  @moduledoc """
  A Serum plugin that injects the live reloader script at the end of HTML files.

  Once the page is loaded inside your web browser, the injected script tries to
  connect to the Serum development server via WebSocket. When the page receives
  "reload" message from the server, it refreshes the current page.

  If you disable this plugin, you need to manually refresh the page after you
  made some changes to your source files.

  ## Using the Plugin

  You usually don't want the script injected into pages when the Serum
  development server is not running. Let the plugin run only when `Mix.env()`
  is `dev`, and run `MIX_ENV=prod mix serum.build` when you are about to
  publish your website.

      # serum.exs:
      %{
        plugins: [
          {#{__MODULE__ |> to_string() |> String.replace_prefix("Elixir.", "")}, only: :dev}
        ]
      }
  """

  @behaviour Serum.Plugin

  def name, do: "Inject Live Reloader Script"
  def version, do: "1.0.0"
  def elixir, do: ">= 1.6.0"
  def serum, do: "0.11.0"

  def description do
    "Injects the live reloader script at the end of " <>
      "all HTML files for use in the Serum development server."
  end

  def implements(),
    do: [
      :rendered_page
    ]

  script_snippet =
    :serum
    |> :code.priv_dir()
    |> IO.iodata_to_binary()
    |> Path.join("build_resources/live_reloader.html")
    |> File.read!()

  def rendered_page(%{out_data: data} = file) do
    {:ok, %{file | out_data: data <> unquote(script_snippet)}}
  end
end
<commit_msg>C r e d o<commit_after>defmodule Serum.Plugins.LiveReloader do
  @moduledoc """
  A Serum plugin that injects the live reloader script at the end of HTML files.

  Once the page is loaded inside your web browser, the injected script tries to
  connect to the Serum development server via WebSocket. When the page receives
  "reload" message from the server, it refreshes the current page.

  If you disable this plugin, you need to manually refresh the page after you
  made some changes to your source files.

  ## Using the Plugin

  You usually don't want the script injected into pages when the Serum
  development server is not running. Let the plugin run only when `Mix.env()`
  is `dev`, and run `MIX_ENV=prod mix serum.build` when you are about to
  publish your website.

      # serum.exs:
      %{
        plugins: [
          {#{__MODULE__ |> to_string() |> String.replace_prefix("Elixir.", "")}, only: :dev}
        ]
      }
  """

  @behaviour Serum.Plugin

  def name, do: "Inject Live Reloader Script"
  def version, do: "1.0.0"
  def elixir, do: ">= 1.6.0"
  def serum, do: "0.11.0"

  def description do
    "Injects the live reloader script at the end of " <>
      "all HTML files for use in the Serum development server."
  end

  def implements,
    do: [
      :rendered_page
    ]

  script_snippet =
    :serum
    |> :code.priv_dir()
    |> IO.iodata_to_binary()
    |> Path.join("build_resources/live_reloader.html")
    |> File.read!()

  def rendered_page(%{out_data: data} = file) do
    {:ok, %{file | out_data: data <> unquote(script_snippet)}}
  end
end

{'fraction_non_alphanumeric': 0.09868007542426147, 'fraction_numerical': 0.006285355122564425, 'mean_word_length': 3.0240202275600505, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6182034', 'n_tokens_mistral': 1049, 'n_tokens_neox': 978, 'n_words': 386}