From c832b567dba73ddbed961b265f2018b3f2cb45ae Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Mon, 10 Nov 2014 19:03:25 +0000 Subject: Redo templates with docs and whatnot This totally breaks compatibility with rebar2, and maybe it shouldn't have. --- priv/templates/LICENSE.dtl | 2 +- priv/templates/README.md.dtl | 2 +- priv/templates/app.template | 11 ++++++++++ priv/templates/gitignore.dtl | 6 +++++- priv/templates/lib.template | 11 ++++++++++ priv/templates/mod.erl.dtl | 4 ++-- priv/templates/otp_app.app.src.dtl | 3 +-- priv/templates/otp_app.template | 7 ------- priv/templates/otp_lib.app.src.dtl | 7 ++----- priv/templates/otp_lib.template | 7 ------- priv/templates/otp_rel.template | 11 ---------- priv/templates/plugin.erl.dtl | 41 ++++++++++++++++++++++--------------- priv/templates/plugin.template | 18 +++++++++------- priv/templates/plugin_README.md.dtl | 15 +++++++++++++- priv/templates/release.template | 15 ++++++++++++++ 15 files changed, 98 insertions(+), 62 deletions(-) create mode 100644 priv/templates/app.template create mode 100644 priv/templates/lib.template delete mode 100644 priv/templates/otp_app.template delete mode 100644 priv/templates/otp_lib.template delete mode 100644 priv/templates/otp_rel.template create mode 100644 priv/templates/release.template (limited to 'priv/templates') diff --git a/priv/templates/LICENSE.dtl b/priv/templates/LICENSE.dtl index 5ce77ce..41588ab 100644 --- a/priv/templates/LICENSE.dtl +++ b/priv/templates/LICENSE.dtl @@ -1,4 +1,4 @@ -Copyright (c) {{copyright_year}}, {{copyright_holder}} <{{author_email}}>. +Copyright (c) {{copyright_year}}, {{author_name}} <{{author_email}}>. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/priv/templates/README.md.dtl b/priv/templates/README.md.dtl index b2435a8..900fedb 100644 --- a/priv/templates/README.md.dtl +++ b/priv/templates/README.md.dtl @@ -1,7 +1,7 @@ {{appid}} ===== -An Erlang {{appid}} library. +{{desc}} Build ----- diff --git a/priv/templates/app.template b/priv/templates/app.template new file mode 100644 index 0000000..39ec14a --- /dev/null +++ b/priv/templates/app.template @@ -0,0 +1,11 @@ +{description, "OTP Application"}. +{variables, [ + {appid, "mylib", "Name of the OTP application"}, + {desc, "An OTP application", "Short description of the app"} +]}. +{template, "app.erl.dtl", "src/{{appid}}_app.erl"}. +{template, "otp_app.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "rebar.config.dtl", "rebar.config"}. +{template, "gitignore.dtl", ".gitignore"}. +{template, "LICENSE.dtl", "LICENSE"}. +{template, "README.md.dtl", "README.md"}. diff --git a/priv/templates/gitignore.dtl b/priv/templates/gitignore.dtl index 23123d4..9e09bf1 100644 --- a/priv/templates/gitignore.dtl +++ b/priv/templates/gitignore.dtl @@ -1,13 +1,17 @@ _* .eunit -deps *.o *.beam *.plt +*.swp +*.swo .erlang.cookie ebin log erl_crash.dump .rebar _rel +_deps +_plugins +_tdeps logs diff --git a/priv/templates/lib.template b/priv/templates/lib.template new file mode 100644 index 0000000..3f35945 --- /dev/null +++ b/priv/templates/lib.template @@ -0,0 +1,11 @@ +{description, "OTP Library application (no processes)"}. +{variables, [ + {appid, "mylib", "Name of the OTP library application"}, + {desc, "An OTP library", "Short description of the app"} +]}. +{template, "mod.erl.dtl", "src/{{appid}}.erl"}. +{template, "otp_lib.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "rebar.config.dtl", "rebar.config"}. +{template, "gitignore.dtl", ".gitignore"}. +{template, "LICENSE.dtl", "LICENSE"}. +{template, "README.md.dtl", "README.md"}. diff --git a/priv/templates/mod.erl.dtl b/priv/templates/mod.erl.dtl index 1be8186..2453366 100644 --- a/priv/templates/mod.erl.dtl +++ b/priv/templates/mod.erl.dtl @@ -1,10 +1,10 @@ -module({{appid}}). -%% Application callbacks +%% API exports -export([]). %%==================================================================== -%% API +%% API functions %%==================================================================== diff --git a/priv/templates/otp_app.app.src.dtl b/priv/templates/otp_app.app.src.dtl index 0af909f..cd5ac89 100644 --- a/priv/templates/otp_app.app.src.dtl +++ b/priv/templates/otp_app.app.src.dtl @@ -1,6 +1,5 @@ {application, {{appid}}, - [ - {description, "{{appid}}"} + [{description, "{{desc}}"} ,{vsn, "0.1.0"} ,{registered, []} ,{mod, {'{{appid}}_app', []}} diff --git a/priv/templates/otp_app.template b/priv/templates/otp_app.template deleted file mode 100644 index db31b31..0000000 --- a/priv/templates/otp_app.template +++ /dev/null @@ -1,7 +0,0 @@ -{variables, []}. -{template, "app.erl", "src/{{appid}}_app.erl"}. -{template, "otp_app.app.src", "src/{{appid}}.app.src"}. -{template, "rebar.config", "rebar.config"}. -{template, "gitignore", ".gitignore"}. -{template, "LICENSE", "LICENSE"}. -{template, "README.md", "README.md"}. diff --git a/priv/templates/otp_lib.app.src.dtl b/priv/templates/otp_lib.app.src.dtl index 5192af7..53ebbb0 100644 --- a/priv/templates/otp_lib.app.src.dtl +++ b/priv/templates/otp_lib.app.src.dtl @@ -1,12 +1,9 @@ {application, {{appid}}, - [ - {description, "{{appid}}"} + [{description, "{{desc}}"} ,{vsn, "0.1.0"} ,{registered, []} ,{applications, - [kernel - ,stdlib - ]} + [kernel,stdlib]} ,{env,[]} ,{modules, []} ]}. diff --git a/priv/templates/otp_lib.template b/priv/templates/otp_lib.template deleted file mode 100644 index 19d7593..0000000 --- a/priv/templates/otp_lib.template +++ /dev/null @@ -1,7 +0,0 @@ -{variables, []}. -{template, "mod.erl", "src/{{appid}}.erl"}. -{template, "otp_lib.app.src", "src/{{appid}}.app.src"}. -{template, "rebar.config", "rebar.config"}. -{template, "gitignore", ".gitignore"}. -{template, "LICENSE", "LICENSE"}. -{template, "README.md", "README.md"}. diff --git a/priv/templates/otp_rel.template b/priv/templates/otp_rel.template deleted file mode 100644 index b75c1da..0000000 --- a/priv/templates/otp_rel.template +++ /dev/null @@ -1,11 +0,0 @@ -{variables, []}. -{template, "app.erl", "apps/{{appid}}/src/{{appid}}_app.erl"}. -{template, "sup.erl", "apps/{{appid}}/src/{{appid}}_sup.erl"}. -{template, "otp_app.app.src", "apps/{{appid}}/src/{{appid}}.app.src"}. -{template, "rebar.config", "rebar.config"}. -{template, "relx.config", "relx.config"}. -{template, "sys.config", "config/sys.config"}. -{template, "vm.args", "config/vm.args"}. -{template, "gitignore", ".gitignore"}. -{template, "LICENSE", "LICENSE"}. -{template, "README.md", "README.md"}. diff --git a/priv/templates/plugin.erl.dtl b/priv/templates/plugin.erl.dtl index 80a03bb..e51763b 100644 --- a/priv/templates/plugin.erl.dtl +++ b/priv/templates/plugin.erl.dtl @@ -1,29 +1,36 @@ -module({{appid}}). +-behaviour(provider). --behaviour(rebar_provider). +-export([init/1, do/1, format_error/2]). --export([init/1, - do/1]). +-include_lib("rebar3/include/rebar.hrl"). --define(PROVIDER, {{appid}}). --define(DEPS, []). +-define(PROVIDER, todo). +-define(DEPS, [app_discovery]). %% =================================================================== %% Public API %% =================================================================== - -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> - State1 = rebar_state:add_provider(State, rebar_provider:create([{name, ?PROVIDER}, - {provider_impl, ?MODULE}, - {bare, false}, - {deps, ?DEPS}, - {example, "rebar {{appid}}"}, - {short_desc, "{{appid}} plugin."}, - {desc, ""}, - {opts, []}])), - {ok, State1}. - --spec do(rebar_state:t()) -> {ok, rebar_state:t()}. + Provider = providers:create([ + {name, ?PROVIDER}, % The 'user friendly' name of the task + {module, ?MODULE}, % The module implementation of the task + {bare, true}, % The task can be run by the user, always true + {deps, ?DEPS}, % The list of dependencies + {example, "rebar {{appid}}"}, % How to use the plugin + {opts, []} % list of options understood by the plugin + {short_desc, {{desc}}}, + {desc, ""} + ]), + {ok, rebar_state:add_provider(State, Provider)}. + + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> {ok, State}. + +-spec format_error(any(), rebar_state:t()) -> {iolist(), rebar_state:t()}. +format_error(Reason, State) -> + {io_lib:format("~p", [Reason]), State}. + diff --git a/priv/templates/plugin.template b/priv/templates/plugin.template index bc44863..7235b60 100644 --- a/priv/templates/plugin.template +++ b/priv/templates/plugin.template @@ -1,7 +1,11 @@ -{variables, []}. -{template, "plugin.erl", "src/{{appid}}.erl"}. -{template, "otp_lib.app.src", "src/{{appid}}.app.src"}. -{template, "rebar.config", "rebar.config"}. -{template, "gitignore", ".gitignore"}. -{template, "LICENSE", "LICENSE"}. -{template, "plugin_README.md", "README.md"}. +{description, "Rebar3 plugin"}. +{variables, [ + {appid, "myplugin", "Name of the plugin"}, + {desc, "A rebar plugin", "Short description of the plugin's purpose"} +]}. +{template, "plugin.erl.dtl", "src/{{appid}}.erl"}. +{template, "otp_lib.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "rebar.config.dtl", "rebar.config"}. +{template, "gitignore.dtl", ".gitignore"}. +{template, "LICENSE.dtl", "LICENSE"}. +{template, "plugin_README.md.dtl", "README.md"}. diff --git a/priv/templates/plugin_README.md.dtl b/priv/templates/plugin_README.md.dtl index 19990f5..c784324 100644 --- a/priv/templates/plugin_README.md.dtl +++ b/priv/templates/plugin_README.md.dtl @@ -1,7 +1,7 @@ {{appid}} ===== -Rebar3 plugin +{{desc}} Build ----- @@ -11,4 +11,17 @@ Build Use --- +Add the plugin to your rebar config: + + {plugins, [ + { {{appid}}, ".*", {git, "git@host:user/{{appid}}.git", {tag, "0.1.0"}}} + ]}. + +Then just call your plugin directly in an existing application: + + $ rebar3 {{appid}} + ===> Fetching {{appid}} + Cloning into '.tmp_dir539136867963'... + ===> Compiling {{appid}} + diff --git a/priv/templates/release.template b/priv/templates/release.template new file mode 100644 index 0000000..5e3ba1a --- /dev/null +++ b/priv/templates/release.template @@ -0,0 +1,15 @@ +{description, "OTP Release structure for executable programs"}. +{variables, [ + {appid, "myapp", "Name of the OTP release. An app with this name will also be created."}, + {desc, "An OTP application", "Short description of the release's main app's purpose"} +]}. +{template, "app.erl.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}_app.erl"}. +{template, "sup.erl.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}_sup.erl"}. +{template, "otp_app.app.src.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}.app.src"}. +{template, "rebar.config.dtl", "rebar.config"}. +{template, "relx.config.dtl", "relx.config"}. +{template, "sys.config.dtl", "config/sys.config"}. +{template, "vm.args.dtl", "config/vm.args"}. +{template, "gitignore.dtl", ".gitignore"}. +{template, "LICENSE.dtl", "LICENSE"}. +{template, "README.md.dtl", "README.md"}. -- cgit v1.1 From 392abf148122be020f3955005497d488d3f881fd Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Tue, 11 Nov 2014 01:27:41 +0000 Subject: First unkeyed var is now 'name', appid -> name The first variable can be unkeyed and the provider will sub in the variable name 'name'. Additionally, the built-in templates and documentation have been updated so that 'appid' is now 'name' and the alternative commands are shown. --- priv/templates/README.md.dtl | 2 +- priv/templates/app.erl.dtl | 6 +++--- priv/templates/app.template | 6 +++--- priv/templates/lib.template | 6 +++--- priv/templates/mod.erl.dtl | 2 +- priv/templates/otp_app.app.src.dtl | 4 ++-- priv/templates/otp_lib.app.src.dtl | 2 +- priv/templates/plugin.erl.dtl | 4 ++-- priv/templates/plugin.template | 6 +++--- priv/templates/plugin_README.md.dtl | 10 +++++----- priv/templates/release.template | 8 ++++---- priv/templates/relx.config.dtl | 4 ++-- priv/templates/sup.erl.dtl | 4 ++-- priv/templates/sys.config.dtl | 2 +- priv/templates/vm.args.dtl | 4 ++-- 15 files changed, 35 insertions(+), 35 deletions(-) (limited to 'priv/templates') diff --git a/priv/templates/README.md.dtl b/priv/templates/README.md.dtl index 900fedb..5507536 100644 --- a/priv/templates/README.md.dtl +++ b/priv/templates/README.md.dtl @@ -1,4 +1,4 @@ -{{appid}} +{{name}} ===== {{desc}} diff --git a/priv/templates/app.erl.dtl b/priv/templates/app.erl.dtl index 1c3e8f2..83eb9a3 100644 --- a/priv/templates/app.erl.dtl +++ b/priv/templates/app.erl.dtl @@ -1,9 +1,9 @@ %%%------------------------------------------------------------------- -%% @doc {{appid}} public API +%% @doc {{name}} public API %% @end %%%------------------------------------------------------------------- --module({{appid}}_app). +-module({{name}}_app). -behaviour(application). @@ -16,7 +16,7 @@ %%==================================================================== start(_StartType, _StartArgs) -> - {{appid}}_sup:start_link(). + {{name}}_sup:start_link(). %%-------------------------------------------------------------------- stop(_State) -> diff --git a/priv/templates/app.template b/priv/templates/app.template index 39ec14a..78374af 100644 --- a/priv/templates/app.template +++ b/priv/templates/app.template @@ -1,10 +1,10 @@ {description, "OTP Application"}. {variables, [ - {appid, "mylib", "Name of the OTP application"}, + {name, "mylib", "Name of the OTP application"}, {desc, "An OTP application", "Short description of the app"} ]}. -{template, "app.erl.dtl", "src/{{appid}}_app.erl"}. -{template, "otp_app.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "app.erl.dtl", "src/{{name}}_app.erl"}. +{template, "otp_app.app.src.dtl", "src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "gitignore.dtl", ".gitignore"}. {template, "LICENSE.dtl", "LICENSE"}. diff --git a/priv/templates/lib.template b/priv/templates/lib.template index 3f35945..1db3b07 100644 --- a/priv/templates/lib.template +++ b/priv/templates/lib.template @@ -1,10 +1,10 @@ {description, "OTP Library application (no processes)"}. {variables, [ - {appid, "mylib", "Name of the OTP library application"}, + {name, "mylib", "Name of the OTP library application"}, {desc, "An OTP library", "Short description of the app"} ]}. -{template, "mod.erl.dtl", "src/{{appid}}.erl"}. -{template, "otp_lib.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "mod.erl.dtl", "src/{{name}}.erl"}. +{template, "otp_lib.app.src.dtl", "src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "gitignore.dtl", ".gitignore"}. {template, "LICENSE.dtl", "LICENSE"}. diff --git a/priv/templates/mod.erl.dtl b/priv/templates/mod.erl.dtl index 2453366..2f5e09e 100644 --- a/priv/templates/mod.erl.dtl +++ b/priv/templates/mod.erl.dtl @@ -1,4 +1,4 @@ --module({{appid}}). +-module({{name}}). %% API exports -export([]). diff --git a/priv/templates/otp_app.app.src.dtl b/priv/templates/otp_app.app.src.dtl index cd5ac89..5188f56 100644 --- a/priv/templates/otp_app.app.src.dtl +++ b/priv/templates/otp_app.app.src.dtl @@ -1,8 +1,8 @@ -{application, {{appid}}, +{application, {{name}}, [{description, "{{desc}}"} ,{vsn, "0.1.0"} ,{registered, []} - ,{mod, {'{{appid}}_app', []}} + ,{mod, {'{{name}}_app', []}} ,{applications, [kernel ,stdlib diff --git a/priv/templates/otp_lib.app.src.dtl b/priv/templates/otp_lib.app.src.dtl index 53ebbb0..3adefeb 100644 --- a/priv/templates/otp_lib.app.src.dtl +++ b/priv/templates/otp_lib.app.src.dtl @@ -1,4 +1,4 @@ -{application, {{appid}}, +{application, {{name}}, [{description, "{{desc}}"} ,{vsn, "0.1.0"} ,{registered, []} diff --git a/priv/templates/plugin.erl.dtl b/priv/templates/plugin.erl.dtl index e51763b..df92cf6 100644 --- a/priv/templates/plugin.erl.dtl +++ b/priv/templates/plugin.erl.dtl @@ -1,4 +1,4 @@ --module({{appid}}). +-module({{name}}). -behaviour(provider). -export([init/1, do/1, format_error/2]). @@ -18,7 +18,7 @@ init(State) -> {module, ?MODULE}, % The module implementation of the task {bare, true}, % The task can be run by the user, always true {deps, ?DEPS}, % The list of dependencies - {example, "rebar {{appid}}"}, % How to use the plugin + {example, "rebar {{name}}"}, % How to use the plugin {opts, []} % list of options understood by the plugin {short_desc, {{desc}}}, {desc, ""} diff --git a/priv/templates/plugin.template b/priv/templates/plugin.template index 7235b60..a7e15cc 100644 --- a/priv/templates/plugin.template +++ b/priv/templates/plugin.template @@ -1,10 +1,10 @@ {description, "Rebar3 plugin"}. {variables, [ - {appid, "myplugin", "Name of the plugin"}, + {name, "myplugin", "Name of the plugin"}, {desc, "A rebar plugin", "Short description of the plugin's purpose"} ]}. -{template, "plugin.erl.dtl", "src/{{appid}}.erl"}. -{template, "otp_lib.app.src.dtl", "src/{{appid}}.app.src"}. +{template, "plugin.erl.dtl", "src/{{name}}.erl"}. +{template, "otp_lib.app.src.dtl", "src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "gitignore.dtl", ".gitignore"}. {template, "LICENSE.dtl", "LICENSE"}. diff --git a/priv/templates/plugin_README.md.dtl b/priv/templates/plugin_README.md.dtl index c784324..8c91947 100644 --- a/priv/templates/plugin_README.md.dtl +++ b/priv/templates/plugin_README.md.dtl @@ -1,4 +1,4 @@ -{{appid}} +{{name}} ===== {{desc}} @@ -14,14 +14,14 @@ Use Add the plugin to your rebar config: {plugins, [ - { {{appid}}, ".*", {git, "git@host:user/{{appid}}.git", {tag, "0.1.0"}}} + { {{name}}, ".*", {git, "git@host:user/{{name}}.git", {tag, "0.1.0"}}} ]}. Then just call your plugin directly in an existing application: - $ rebar3 {{appid}} - ===> Fetching {{appid}} + $ rebar3 {{name}} + ===> Fetching {{name}} Cloning into '.tmp_dir539136867963'... - ===> Compiling {{appid}} + ===> Compiling {{name}} diff --git a/priv/templates/release.template b/priv/templates/release.template index 5e3ba1a..3539392 100644 --- a/priv/templates/release.template +++ b/priv/templates/release.template @@ -1,11 +1,11 @@ {description, "OTP Release structure for executable programs"}. {variables, [ - {appid, "myapp", "Name of the OTP release. An app with this name will also be created."}, + {name, "myapp", "Name of the OTP release. An app with this name will also be created."}, {desc, "An OTP application", "Short description of the release's main app's purpose"} ]}. -{template, "app.erl.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}_app.erl"}. -{template, "sup.erl.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}_sup.erl"}. -{template, "otp_app.app.src.dtl", "{{apps_dir}}/{{appid}}/src/{{appid}}.app.src"}. +{template, "app.erl.dtl", "{{apps_dir}}/{{name}}/src/{{name}}_app.erl"}. +{template, "sup.erl.dtl", "{{apps_dir}}/{{name}}/src/{{name}}_sup.erl"}. +{template, "otp_app.app.src.dtl", "{{apps_dir}}/{{name}}/src/{{name}}.app.src"}. {template, "rebar.config.dtl", "rebar.config"}. {template, "relx.config.dtl", "relx.config"}. {template, "sys.config.dtl", "config/sys.config"}. diff --git a/priv/templates/relx.config.dtl b/priv/templates/relx.config.dtl index 7cb3a8a..7b08f97 100644 --- a/priv/templates/relx.config.dtl +++ b/priv/templates/relx.config.dtl @@ -1,6 +1,6 @@ %% -*- mode: Erlang; fill-column: 80; comment-column: 75; -*- -{release, {'{{appid}}', "0.1.0"}, - [{{appid}}, +{release, {'{{name}}', "0.1.0"}, + [{{name}}, sasl]}. {sys_config, "./config/sys.config"}. diff --git a/priv/templates/sup.erl.dtl b/priv/templates/sup.erl.dtl index 3dd5b12..a2e7209 100644 --- a/priv/templates/sup.erl.dtl +++ b/priv/templates/sup.erl.dtl @@ -1,9 +1,9 @@ %%%------------------------------------------------------------------- -%% @doc {{appid}} top level supervisor. +%% @doc {{name}} top level supervisor. %% @end %%%------------------------------------------------------------------- --module({{appid}}_sup). +-module({{name}}_sup). -behaviour(supervisor). diff --git a/priv/templates/sys.config.dtl b/priv/templates/sys.config.dtl index e678cf7..7fd6bcb 100644 --- a/priv/templates/sys.config.dtl +++ b/priv/templates/sys.config.dtl @@ -1,3 +1,3 @@ [ - {'{{appid}}', []} + {'{{name}}', []} ]. diff --git a/priv/templates/vm.args.dtl b/priv/templates/vm.args.dtl index 27028ac..a8a43f0 100644 --- a/priv/templates/vm.args.dtl +++ b/priv/templates/vm.args.dtl @@ -1,6 +1,6 @@ --name {{appid}} +-name {{name}} --setcookie {{appid}}_cookie +-setcookie {{name}}_cookie +K true +A30 -- cgit v1.1