Current section
Files
Jump to
Current section
Files
lib/mix/tasks/lit.install.ex
defmodule Mix.Tasks.Lit.Install do
@moduledoc """
Installs lit layout to your `_web/templates` directory.
## Configuration
config :lit,
otp_app: :my_app,
template_format: :eex
## Example
Running without options will read configuration from your `config.exs` file,
as shown above.
mix lit.install
Also accepts `--format` and `--app` options:
mix lit.install --format slime --app my_app
"""
def run(args) do
if Mix.Project.umbrella?() do
Mix.raise("mix lit.install can only be run inside an application directory")
end
%{format: format, otp_app: otp_app} = Mix.Lit.parse_config!("lit.install", args)
Mix.Lit.ensure_phoenix_is_loaded!("lit.install")
phoenix_version = Application.spec(:phoenix, :vsn)
Mix.Lit.copy_from("priv/templates/#{format}", [
{template_file(phoenix_version, format),
"lib/#{otp_app}_web/templates/layout/lit.html.#{format}"}
])
end
defp template_file(phoenix_version, format) when is_list(phoenix_version),
do: phoenix_version |> to_string() |> template_file(format)
defp template_file(phoenix_version, format) when is_binary(phoenix_version) do
if Version.match?(phoenix_version, ">= 1.5.0") do
"layout.phx1_5.html.#{format}"
else
"layout.html.#{format}"
end
end
end