<commit_before>defmodule Talon.Page do
  @moduledoc """
  Define an Talon managed page

  """

  @type module_or_struct :: atom | struct

  defmacro __using__(opts) do

    context = opts[:context]

    quote do
      @__context__ unquote(context) || (Module.split(__MODULE__) |> hd |> Module.concat(nil))

      @spec index_card_title() :: String.t
      def index_card_title do
        "#{Module.split(__MODULE__) |> List.last}"
      end

      @doc """
      Returns a list of links for each of the Talon managed pages.

      Note: This function is overridable
      """
      @spec page_paths(Map.t) :: [Tuple.t]
      def page_paths(%{talon: talon} = _talon) do
        talon.page_names()
        |> Enum.map(&{Talon.Utils.titleize(&1),  "/talon/pages/#{&1}"})
      end

      @doc """
      Returns a list of links for each of the Talon managed resources.

      Note: This function is overridable
      """
      @spec resource_paths(Map.t) :: [Tuple.t]
      def resource_paths(%{talon: talon} = _talon) do
        talon.resources()
        |> Enum.map(fn talon_resource ->
          schema = talon_resource.schema() # TODO: let resource determine presentation name (DJS)
          {Talon.Utils.titleize(schema) |> Inflex.Pluralize.pluralize, Talon.Utils.talon_resource_path(schema, :index)}
        end)
      end

      @doc """
      Return the Talon context.
      """
      @spec context() :: atom
      def context, do: @__context__

      defoverridable [
        context: 0, resource_paths: 1, page_paths: 1, index_card_title: 0
      ]
    end
  end
end<commit_msg>Tighten page implementation #52<commit_after>defmodule Talon.Page do
  @moduledoc """
  Define an Talon managed page

  """

  @type module_or_struct :: atom | struct

  defmacro __using__(opts) do

    context = opts[:context]

    quote do
      @__context__ unquote(context) || (Module.split(__MODULE__) |> hd |> Module.concat(nil))

      # TODO: too specific to template. Move to view.
      @spec index_card_title() :: String.t
      def index_card_title, do: title()

      @doc """
      Returns a list of links for each of the Talon managed pages.

      Note: This function is overridable
      """
      @spec page_paths(Map.t) :: [Tuple.t]
      def page_paths(%{talon: talon} = _talon) do  # TODO: move to concern and use this approach for resource_paths (DJS)
        talon.pages |> Enum.map(&{apply(&1, :title, []),  "/talon/pages/#{apply(&1, :name, [])}"})
      end

      @doc """
      Returns a list of links for each of the Talon managed resources.

      Note: This function is overridable
      """
      @spec resource_paths(Map.t) :: [Tuple.t]
      def resource_paths(%{talon: talon} = _talon) do
        talon.resources()
        |> Enum.map(fn talon_resource ->
          schema = talon_resource.schema()
          # TODO: let resource determine presentation name (DJS)
          {Talon.Utils.titleize(schema) |> Inflex.Pluralize.pluralize, Talon.Utils.talon_resource_path(schema, :index)}
        end)
      end

      @doc """
      Return the Talon context.
      """
      @spec context() :: atom
      def context, do: @__context__

      @spec title() :: String.t
      def title, do: name() |> Talon.Utils.titleize

      # TODO: perhaps resource_name, module_name
      @spec name() :: String.t
      def name, do: __MODULE__ |> Module.split |> List.last() |> to_string |> Inflex.underscore

      defoverridable [
        context: 0, resource_paths: 1, page_paths: 1, index_card_title: 0, title: 0, name: 0
      ]
    end
  end
end
{'fraction_non_alphanumeric': 0.1221159257175014, 'fraction_numerical': 0.004501969611705121, 'mean_word_length': 2.5585585585585586, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3552976', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1116, 'n_words': 312}