Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow to set custom dir for templates through environment variable #10

Merged
merged 3 commits into from

2 participants

@vladimir-vg

As is. Review please.

src/mustache.erl
@@ -154,9 +154,20 @@ compile_tag("{", Content, State) ->
compile_tag("!", _Content, _State) ->
"[]".
+template_dir(Mod) ->
+ DefaultDirPath = filename:dirname(code:which(Mod)),
+ case application:get_env(mustache, templates_dir) of
+ {ok, DirPath} when is_list(DirPath) ->
+ CorrectDir = filelib:ensure_dir(DirPath) == ok,
+ if CorrectDir -> DirPath;
@pusewicz Collaborator

Could you change that to a case statement please?

sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pusewicz pusewicz merged commit f6499a9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/mustache.erl
View
16 src/mustache.erl
@@ -154,9 +154,21 @@ compile_tag("{", Content, State) ->
compile_tag("!", _Content, _State) ->
"[]".
+template_dir(Mod) ->
+ DefaultDirPath = filename:dirname(code:which(Mod)),
+ case application:get_env(mustache, templates_dir) of
+ {ok, DirPath} when is_list(DirPath) ->
+ case filelib:ensure_dir(DirPath) of
+ ok -> DirPath;
+ _ -> DefaultDirPath
+ end;
+ _ ->
+ DefaultDirPath
+ end.
template_path(Mod) ->
- ModPath = code:which(Mod),
- re:replace(ModPath, "\.beam$", ".mustache", [{return, list}]).
+ DirPath = template_dir(Mod),
+ Basename = atom_to_list(Mod),
+ filename:join(DirPath, Basename ++ ".mustache").
get(Key, Ctx) when is_list(Key) ->
{ok, Mod} = dict:find('__mod__', Ctx),
Something went wrong with that request. Please try again.