<commit_before>defmodule Webapp.DocController do
  use Webapp.Web, :controller
  @docs_path System.get_env("APP_HOME") <> "/docs"

  def index(conn, _params) do
    {:ok, list_of_docs_name} = File.ls(@docs_path)
    list_of_docs = Enum.map(list_of_docs_name, fn(filename) ->
      %{title: doc_title(filename), filename: "#{filename}"}
    end)
    json conn, %{data: list_of_docs}
  end

  def show(conn, %{"_format" => "json", "filename" => filename}) do
    {:ok, app_home_path} = File.cwd
    doc_path = "#{@docs_path}/#{filename}"
    doc_data = File.read!(doc_path)
    json conn, %{data: doc_data}
  end

  def show(conn, %{"filename" => filename}) do
    render conn, Webapp.PageView, "index.html"
  end

  defp doc_title(doc_name) do
    doc_name
    |> String.replace("_", " ")
    |> String.replace(".md", "")
    |> String.capitalize
  end
end<commit_msg>Set @app_name in DocController and leave a TODO to implement a plug to set it in Webapp.Router<commit_after>defmodule Webapp.DocController do
  use Webapp.Web, :controller
  @docs_path System.get_env("APP_HOME") <> "/docs"

  def index(conn, _params) do
    {:ok, list_of_docs_name} = File.ls(@docs_path)
    list_of_docs = Enum.map(list_of_docs_name, fn(filename) ->
      %{title: doc_title(filename), filename: "#{filename}"}
    end)
    json conn, %{data: list_of_docs}
  end

  def show(conn, %{"_format" => "json", "filename" => filename}) do
    {:ok, app_home_path} = File.cwd
    doc_path = "#{@docs_path}/#{filename}"
    doc_data = File.read!(doc_path)
    json conn, %{data: doc_data}
  end

  def show(conn, %{"filename" => filename}) do
    # TODO: create plug to set app_name in router.
    render conn, Webapp.PageView, "index.html", app_name: "core"
  end

  defp doc_title(doc_name) do
    doc_name
    |> String.replace("_", " ")
    |> String.replace(".md", "")
    |> String.capitalize
  end
end
{'fraction_non_alphanumeric': 0.15658174097664543, 'fraction_numerical': 0.0, 'mean_word_length': 3.784263959390863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '5098457', 'n_tokens_mistral': 698, 'n_tokens_neox': 677, 'n_words': 159}