Kaynağa Gözat

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.
pull/3/head
Fred Hebert 10 yıl önce
ebeveyn
işleme
392abf1481
17 değiştirilmiş dosya ile 62 ekleme ve 45 silme
  1. +18
    -9
      doc/templates.md
  2. +1
    -1
      priv/templates/README.md.dtl
  3. +3
    -3
      priv/templates/app.erl.dtl
  4. +3
    -3
      priv/templates/app.template
  5. +3
    -3
      priv/templates/lib.template
  6. +1
    -1
      priv/templates/mod.erl.dtl
  7. +2
    -2
      priv/templates/otp_app.app.src.dtl
  8. +1
    -1
      priv/templates/otp_lib.app.src.dtl
  9. +2
    -2
      priv/templates/plugin.erl.dtl
  10. +3
    -3
      priv/templates/plugin.template
  11. +5
    -5
      priv/templates/plugin_README.md.dtl
  12. +4
    -4
      priv/templates/release.template
  13. +2
    -2
      priv/templates/relx.config.dtl
  14. +2
    -2
      priv/templates/sup.erl.dtl
  15. +1
    -1
      priv/templates/sys.config.dtl
  16. +2
    -2
      priv/templates/vm.args.dtl
  17. +9
    -1
      src/rebar_prv_new.erl

+ 18
- 9
doc/templates.md Dosyayı Görüntüle

@ -50,7 +50,7 @@ Details for each individual plugin can be obtained by calling `rebar3 new help <
built-in template
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)
date="2014-11-10"
datetime="2014-11-10T18:29:41+00:00"
@ -63,6 +63,17 @@ All the variables there have their default values shown, and an optional explana
The variables can also be [overriden globally](#global-variables).
A template can be run by calling:
→ ./rebar3 new plugin name=demo author_name="Fred H."
...
Alternatively, the `name` variable is special -- if the first argument to a template has no key associated with it, `name` is automatically added. The call above is therefore equivalent to:
→ ./rebar3 new plugin demo author_name="Fred H."
...
## Custom Templates ##
Custom templates can be added in `$HOME/.rebar3/templates/`. Each template is at least two files:
@ -107,11 +118,11 @@ We'll start with an index for our template, called `ct_suite.template`:
```erlang
{description, "A basic Common Test suite for an OTP application"}.
{variables, [
{suite, "suite", "Name of the suite, prepended to the standard _SUITE suffix"}
{name, "suite", "Name of the suite, prepended to the standard _SUITE suffix"}
]}.
{dir, "test"}.
{template, "ct_suite.erl.dtl", "test/{{suite}}_SUITE.erl"}.
{template, "ct_suite.erl.dtl", "test/{{name}}_SUITE.erl"}.
```
This tells rebar3 to create the test directory and to evaluate an [ErlyDTL](https://github.com/erlydtl/erlydtl) template. All the paths are relative to the current working directory.
@ -119,7 +130,7 @@ This tells rebar3 to create the test directory and to evaluate an [ErlyDTL](http
Let's create the template file:
```erlang
-module({{suite}}_SUITE).
-module({{name}}_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl"). % Eunit macros for convenience
@ -145,7 +156,7 @@ fail(_Config) ->
?assert(false).
```
This one does very simple variable substitution for the name (using `{{suite}}`) and that's all it needs.
This one does very simple variable substitution for the name (using `{{name}}`) and that's all it needs.
Let's get to any existing project you have and try it:
@ -164,7 +175,7 @@ Let's look at the details:
custom template (/home/ferd/.rebar3/templates/ct_suite.template)
Description: A basic Common Test suite for an OTP application
Variables:
suite="suite" (Name of the suite, prepended to the standard _SUITE suffix)
name="suite" (Name of the suite, prepended to the standard _SUITE suffix)
date="2014-11-10"
datetime="2014-11-10T18:46:33+00:00"
author_name="Anonymous"
@ -174,9 +185,7 @@ Let's look at the details:
The documentation from variables and the description are well in place. To apply the template, go to any of your OTP application's top-level directory:
→ ./rebar3 new ct_suite suite=demo
→ ./rebar3 new ct_suite demo
===> Writing test/demo_SUITE.erl
And you will see the code in place.
~

+ 1
- 1
priv/templates/README.md.dtl Dosyayı Görüntüle

@ -1,4 +1,4 @@
{{appid}}
{{name}}
=====
{{desc}}

+ 3
- 3
priv/templates/app.erl.dtl Dosyayı Görüntüle

@ -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) ->

+ 3
- 3
priv/templates/app.template Dosyayı Görüntüle

@ -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"}.

+ 3
- 3
priv/templates/lib.template Dosyayı Görüntüle

@ -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"}.

+ 1
- 1
priv/templates/mod.erl.dtl Dosyayı Görüntüle

@ -1,4 +1,4 @@
-module({{appid}}).
-module({{name}}).
%% API exports
-export([]).

+ 2
- 2
priv/templates/otp_app.app.src.dtl Dosyayı Görüntüle

@ -1,8 +1,8 @@
{application, {{appid}},
{application, {{name}},
[{description, "{{desc}}"}
,{vsn, "0.1.0"}
,{registered, []}
,{mod, {'{{appid}}_app', []}}
,{mod, {'{{name}}_app', []}}
,{applications,
[kernel
,stdlib

+ 1
- 1
priv/templates/otp_lib.app.src.dtl Dosyayı Görüntüle

@ -1,4 +1,4 @@
{application, {{appid}},
{application, {{name}},
[{description, "{{desc}}"}
,{vsn, "0.1.0"}
,{registered, []}

+ 2
- 2
priv/templates/plugin.erl.dtl Dosyayı Görüntüle

@ -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, ""}

+ 3
- 3
priv/templates/plugin.template Dosyayı Görüntüle

@ -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"}.

+ 5
- 5
priv/templates/plugin_README.md.dtl Dosyayı Görüntüle

@ -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}}
<Plugin Output>

+ 4
- 4
priv/templates/release.template Dosyayı Görüntüle

@ -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"}.

+ 2
- 2
priv/templates/relx.config.dtl Dosyayı Görüntüle

@ -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"}.

+ 2
- 2
priv/templates/sup.erl.dtl Dosyayı Görüntüle

@ -1,9 +1,9 @@
%%%-------------------------------------------------------------------
%% @doc {{appid}} top level supervisor.
%% @doc {{name}} top level supervisor.
%% @end
%%%-------------------------------------------------------------------
-module({{appid}}_sup).
-module({{name}}_sup).
-behaviour(supervisor).

+ 1
- 1
priv/templates/sys.config.dtl Dosyayı Görüntüle

@ -1,3 +1,3 @@
[
{'{{appid}}', []}
{'{{name}}', []}
].

+ 2
- 2
priv/templates/vm.args.dtl Dosyayı Görüntüle

@ -1,6 +1,6 @@
-name {{appid}}
-name {{name}}
-setcookie {{appid}}_cookie
-setcookie {{name}}_cookie
+K true
+A30

+ 9
- 1
src/rebar_prv_new.erl Dosyayı Görüntüle

@ -71,7 +71,15 @@ is_forced(State) ->
end.
parse_opts([]) -> [];
parse_opts([Opt|Opts]) -> [parse_opt(Opt, "") | parse_opts(Opts)].
parse_opts([Opt|Opts]) -> [parse_first_opt(Opt, "") | parse_opts1(Opts)].
parse_opts1([]) -> [];
parse_opts1([Opt|Opts]) -> [parse_opt(Opt, "") | parse_opts1(Opts)].
%% If the first argument meets no '=', we got a default 'name' argument
parse_first_opt("", Acc) -> {name, lists:reverse(Acc)};
parse_first_opt("="++Rest, Acc) -> parse_opt("="++Rest, Acc);
parse_first_opt([H|Str], Acc) -> parse_first_opt(Str, [H|Acc]).
%% We convert to atoms dynamically. Horrible in general, but fine in a
%% build system's templating tool.

Yükleniyor…
İptal
Kaydet