<commit_before>defmodule Serum.Renderer do
  @moduledoc """
  This module provides functions for rendering pages into HTML.
  """

  alias Serum.Result
  alias Serum.GlobalBindings
  alias Serum.Build
  alias Serum.Template

  @type state :: Build.state

  @re_media ~r/(?<type>href|src)="(?:%|%25)media:(?<url>[^"]*)"/
  @re_post ~r/(?<type>href|src)="(?:%|%25)post:(?<url>[^"]*)"/
  @re_page ~r/(?<type>href|src)="(?:%|%25)page:(?<url>[^"]*)"/

  @doc """
  Renders contents into a complete HTML page.

  `stub_ctx` is a list of variable bindings which is fed into
  `templates/<template_name>.html.eex` template file, and `page_ctx` is a list
  of variable bindings which is then fed into `templates/base.html.eex` template
  file.
  """
  @spec render(binary, keyword, keyword, state) :: Result.t(binary)

  # render full page
  def render(template_name, stub_ctx, page_ctx, state) do
    proj = state.project_info
    global_bindings = GlobalBindings.as_keyword()
    case render_fragment Template.get(template_name), stub_ctx do
      {:ok, stub} ->
        contents = process_links stub, proj.base_url
        ctx = [contents: contents] ++ page_ctx
        render_fragment Template.get("base"), ctx ++ global_bindings
      error -> error
    end
  end

  @doc """
  Renders contents into a (partial) HTML stub.
  """
  @spec render_fragment(Template.t(), keyword()) :: Result.t(binary())
  def render_fragment(template, bindings) do
    global_bindings = GlobalBindings.as_keyword()
    bindings2 = Keyword.merge(bindings, global_bindings, fn _k, v, _ -> v end)
    {html, _} = Code.eval_quoted template.ast, bindings2
    {:ok, html}
  rescue
    e in CompileError ->
      {:error, {e.description, template.file, e.line}}
    e -><commit_msg>Remove a unused function<commit_after>defmodule Serum.Renderer do
  @moduledoc """
  This module provides functions for rendering pages into HTML.
  """

  alias Serum.Result
  alias Serum.GlobalBindings
  alias Serum.Template

  @re_media ~r/(?<type>href|src)="(?:%|%25)media:(?<url>[^"]*)"/
  @re_post ~r/(?<type>href|src)="(?:%|%25)post:(?<url>[^"]*)"/
  @re_page ~r/(?<type>href|src)="(?:%|%25)page:(?<url>[^"]*)"/

  @doc """
  Renders contents into a (partial) HTML stub.
  """
  @spec render_fragment(Template.t(), keyword()) :: Result.t(binary())
  def render_fragment(template, bindings) do
    global_bindings = GlobalBindings.as_keyword()
    bindings2 = Keyword.merge(bindings, global_bindings, fn _k, v, _ -> v end)
    {html, _} = Code.eval_quoted template.ast, bindings2
    {:ok, html}
  rescue
    e in CompileError ->
      {:error, {e.description, template.file, e.line}}
    e ->
{'fraction_non_alphanumeric': 0.16484345529988684, 'fraction_numerical': 0.006035458317615994, 'mean_word_length': 3.9849624060150375, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 24, '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': '1419714', 'n_tokens_mistral': 951, 'n_tokens_neox': 901, 'n_words': 220}