diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2016-09-29 22:08:20 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2016-09-29 22:12:51 +0200 |
commit | b22df66374473474234a4ed9ce87a345acde90cd (patch) | |
tree | 61bcf523b3f9e7bd4a9e332f67685410617574e8 | |
parent | aef130c0ebaab148390ca87f93bb0c56ddf0eb2e (diff) | |
download | elixir-b22df66374473474234a4ed9ce87a345acde90cd.tar.gz |
Update applications built by mix new
* Include a link to ExDoc and update links to hexdocs.pm
* Generate @moduledoc and @doc with doctests
* For --sup projects, move the application module to Mod.Application
-rw-r--r-- | lib/mix/lib/mix/tasks/new.ex | 32 | ||||
-rw-r--r-- | lib/mix/test/mix/tasks/new_test.exs | 7 |
2 files changed, 30 insertions, 9 deletions
diff --git a/lib/mix/lib/mix/tasks/new.ex b/lib/mix/lib/mix/tasks/new.ex index ebdd028ea..0679a97aa 100644 --- a/lib/mix/lib/mix/tasks/new.ex +++ b/lib/mix/lib/mix/tasks/new.ex @@ -86,11 +86,10 @@ defmodule Mix.Tasks.New do create_file "config/config.exs", config_template(assigns) create_directory "lib" + create_file "lib/#{app}.ex", lib_template(assigns) if opts[:sup] do - create_file "lib/#{app}.ex", lib_sup_template(assigns) - else - create_file "lib/#{app}.ex", lib_template(assigns) + create_file "lib/#{app}/application.ex", lib_app_template(assigns) end create_directory "test" @@ -116,7 +115,7 @@ defmodule Mix.Tasks.New do end defp otp_app(mod, true) do - " [applications: [:logger],\n mod: {#{mod}, []}]" + " [applications: [:logger],\n mod: {#{mod}.Application, []}]" end defp generate_umbrella(_app, mod, path, _opts) do @@ -222,8 +221,9 @@ defmodule Mix.Tasks.New do end ``` - If [published on HexDocs](https://hex.pm/docs/tasks#hex_docs), the docs can - be found at [https://hexdocs.pm/<%= @app %>](https://hexdocs.pm/<%= @app %>) + Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) + and published on [HexDocs](https://hexdocs.pm). Once published, the docs can + be found at [https://hexdocs.pm/<%= @app %>](https://hexdocs.pm/<%= @app %>). <% end %> """ @@ -412,11 +412,27 @@ defmodule Mix.Tasks.New do embed_template :lib, """ defmodule <%= @mod %> do + @moduledoc \""" + Documentation for <%= @mod %>. + \""" + + @doc \""" + Hello world. + + ## Examples + + iex> <%= @mod %>.hello + :world + + \""" + def hello do + :world + end end """ - embed_template :lib_sup, """ - defmodule <%= @mod %> do + embed_template :lib_app, """ + defmodule <%= @mod %>.Application do use Application # See http://elixir-lang.org/docs/stable/elixir/Application.html diff --git a/lib/mix/test/mix/tasks/new_test.exs b/lib/mix/test/mix/tasks/new_test.exs index 4d24625ac..97ec34970 100644 --- a/lib/mix/test/mix/tasks/new_test.exs +++ b/lib/mix/test/mix/tasks/new_test.exs @@ -32,7 +32,7 @@ defmodule Mix.Tasks.NewTest do assert_file "hello_world/mix.exs", fn(file) -> assert file =~ "app: :hello_world" assert file =~ "version: \"0.1.0\"" - assert file =~ "mod: {HelloWorld, []}" + assert file =~ "mod: {HelloWorld.Application, []}" end assert_file "hello_world/README.md", ~r/# HelloWorld\n/ @@ -40,6 +40,11 @@ defmodule Mix.Tasks.NewTest do assert_file "hello_world/lib/hello_world.ex", fn(file) -> assert file =~ "defmodule HelloWorld do" + assert file =~ "def hello do" + end + + assert_file "hello_world/lib/hello_world/application.ex", fn(file) -> + assert file =~ "defmodule HelloWorld.Application do" assert file =~ "use Application" assert file =~ "Supervisor.start_link(children, opts)" end |