summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--priv/templates/app.erl4
-rw-r--r--priv/templates/escript_mod.erl2
-rw-r--r--priv/templates/escript_rebar.config6
-rw-r--r--priv/templates/gitignore6
-rw-r--r--priv/templates/mod.erl2
-rw-r--r--priv/templates/otp_app.app.src4
-rw-r--r--priv/templates/otp_lib.app.src2
-rw-r--r--priv/templates/plugin.erl4
-rw-r--r--priv/templates/provider.erl4
-rw-r--r--priv/templates/relx_rebar.config4
-rw-r--r--priv/templates/sup.erl2
-rw-r--r--priv/templates/sys.config2
-rw-r--r--src/rebar_templater.erl25
13 files changed, 44 insertions, 23 deletions
diff --git a/priv/templates/app.erl b/priv/templates/app.erl
index 2e7b909..83eb9a3 100644
--- a/priv/templates/app.erl
+++ b/priv/templates/app.erl
@@ -3,7 +3,7 @@
%% @end
%%%-------------------------------------------------------------------
--module('{{name}}_app').
+-module({{name}}_app).
-behaviour(application).
@@ -16,7 +16,7 @@
%%====================================================================
start(_StartType, _StartArgs) ->
- '{{name}}_sup':start_link().
+ {{name}}_sup:start_link().
%%--------------------------------------------------------------------
stop(_State) ->
diff --git a/priv/templates/escript_mod.erl b/priv/templates/escript_mod.erl
index dd2feb8..f8a779b 100644
--- a/priv/templates/escript_mod.erl
+++ b/priv/templates/escript_mod.erl
@@ -1,4 +1,4 @@
--module('{{name}}').
+-module({{name}}).
%% API exports
-export([main/1]).
diff --git a/priv/templates/escript_rebar.config b/priv/templates/escript_rebar.config
index c0a3301..196f835 100644
--- a/priv/templates/escript_rebar.config
+++ b/priv/templates/escript_rebar.config
@@ -2,9 +2,9 @@
{deps, []}.
{escript_incl_apps,
- ['{{name}}']}.
-{escript_top_level_app, '{{name}}'}.
-{escript_name, '{{name}}'}.
+ [{{name}}]}.
+{escript_top_level_app, {{name}}}.
+{escript_name, {{name}}}.
{escript_emu_args, "%%! +sbtu +A0\n"}.
%% Profiles
diff --git a/priv/templates/gitignore b/priv/templates/gitignore
index a939dce..ced0c5e 100644
--- a/priv/templates/gitignore
+++ b/priv/templates/gitignore
@@ -11,9 +11,5 @@ ebin
log
erl_crash.dump
.rebar
-_rel
-_deps
-_plugins
-_tdeps
logs
-_build \ No newline at end of file
+_build
diff --git a/priv/templates/mod.erl b/priv/templates/mod.erl
index 208307e..2f5e09e 100644
--- a/priv/templates/mod.erl
+++ b/priv/templates/mod.erl
@@ -1,4 +1,4 @@
--module('{{name}}').
+-module({{name}}).
%% API exports
-export([]).
diff --git a/priv/templates/otp_app.app.src b/priv/templates/otp_app.app.src
index 783a130..243cef5 100644
--- a/priv/templates/otp_app.app.src
+++ b/priv/templates/otp_app.app.src
@@ -1,8 +1,8 @@
-{application, '{{name}}',
+{application, {{name}},
[{description, "{{desc}}"},
{vsn, "0.1.0"},
{registered, []},
- {mod, {'{{name}}_app', []}},
+ {mod, {{{name}}_app, []}},
{applications,
[kernel,
stdlib
diff --git a/priv/templates/otp_lib.app.src b/priv/templates/otp_lib.app.src
index 6e76b4b..5b98a51 100644
--- a/priv/templates/otp_lib.app.src
+++ b/priv/templates/otp_lib.app.src
@@ -1,4 +1,4 @@
-{application, '{{name}}',
+{application, {{name}},
[{description, "{{desc}}"},
{vsn, "0.1.0"},
{registered, []},
diff --git a/priv/templates/plugin.erl b/priv/templates/plugin.erl
index c6e5e40..218960d 100644
--- a/priv/templates/plugin.erl
+++ b/priv/templates/plugin.erl
@@ -1,8 +1,8 @@
--module('{{name}}').
+-module({{name}}).
-export([init/1]).
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- {ok, State1} = '{{name}}_prv':init(State),
+ {ok, State1} = {{name}}_prv:init(State),
{ok, State1}.
diff --git a/priv/templates/provider.erl b/priv/templates/provider.erl
index 669df83..7639d97 100644
--- a/priv/templates/provider.erl
+++ b/priv/templates/provider.erl
@@ -1,8 +1,8 @@
--module('{{name}}_prv').
+-module({{name}}_prv).
-export([init/1, do/1, format_error/1]).
--define(PROVIDER, '{{name}}').
+-define(PROVIDER, {{name}}).
-define(DEPS, [app_discovery]).
%% ===================================================================
diff --git a/priv/templates/relx_rebar.config b/priv/templates/relx_rebar.config
index da32819..eab99ac 100644
--- a/priv/templates/relx_rebar.config
+++ b/priv/templates/relx_rebar.config
@@ -1,8 +1,8 @@
{erl_opts, [debug_info]}.
{deps, []}.
-{relx, [{release, {'{{name}}', "0.1.0"},
- ['{{name}}',
+{relx, [{release, {{{name}}, "0.1.0"},
+ [{{name}},
sasl]},
{sys_config, "./config/sys.config"},
diff --git a/priv/templates/sup.erl b/priv/templates/sup.erl
index cd9192a..a2e7209 100644
--- a/priv/templates/sup.erl
+++ b/priv/templates/sup.erl
@@ -3,7 +3,7 @@
%% @end
%%%-------------------------------------------------------------------
--module('{{name}}_sup').
+-module({{name}}_sup).
-behaviour(supervisor).
diff --git a/priv/templates/sys.config b/priv/templates/sys.config
index 7fd6bcb..b587675 100644
--- a/priv/templates/sys.config
+++ b/priv/templates/sys.config
@@ -1,3 +1,3 @@
[
- {'{{name}}', []}
+ {{{name}}, []}
].
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index f687637..2f33bfc 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -159,9 +159,34 @@ drop_var_docs([{K,V}|Rest]) -> [{K,V} | drop_var_docs(Rest)].
create({Template, Type, File}, Files, UserVars, Force, State) ->
TemplateTerms = consult(load_file(Files, Type, File)),
Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms, State))),
+ maybe_warn_about_name(Vars),
TemplateCwd = filename:dirname(File),
execute_template(TemplateTerms, Files, {Template, Type, TemplateCwd}, Vars, Force).
+maybe_warn_about_name(Vars) ->
+ Name = proplists:get_value(name, Vars, "valid"),
+ case validate_atom(Name) of
+ invalid ->
+ ?WARN("The 'name' variable is often associated with Erlang "
+ "module names and/or file names. The value submitted "
+ "(~s) isn't an unquoted Erlang atom. Templates "
+ "generated may contain errors.",
+ [Name]);
+ valid ->
+ ok
+ end.
+
+validate_atom(Str) ->
+ case io_lib:fread("~a", unicode:characters_to_list(Str)) of
+ {ok, [Atom], ""} ->
+ case io_lib:write_atom(Atom) of
+ "'" ++ _ -> invalid; % quoted
+ _ -> valid % unquoted
+ end;
+ _ ->
+ invalid
+ end.
+
%% Run template instructions one at a time.
execute_template([], _, {Template,_,_}, _, _) ->
?DEBUG("Template ~s applied", [Template]),