Skip to content
Browse files

Merge pull request #10 from vladimir-vg/custom-templates-dir

Allow to set custom dir for templates through environment variable
  • Loading branch information...
2 parents 7fd60c0 + 3fc956c commit f6499a9c0d8fb1de66f36de660d9c2b18a9b4a6a @pusewicz pusewicz committed Aug 11, 2012
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/mustache.erl
View
16 src/mustache.erl
@@ -150,9 +150,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),

0 comments on commit f6499a9

Please sign in to comment.
Something went wrong with that request. Please try again.