Permalink
Browse files

Fix result value of compile_dir templates

Relates to comment in #124.

This is a backwards breaking change (again, sorry, but it just wasn't
right as it was).

The compiled dir template now returns `{ok, Rendered}` or `{error,
Reason}` just as normally compiled templates.
  • Loading branch information...
1 parent 26b6a79 commit 0b61b69591f60a427d65faa95c00119e23edad09 @kaos kaos committed Feb 24, 2014
Showing with 8 additions and 9 deletions.
  1. +8 −9 src/erlydtl_beam_compiler.erl
View
17 src/erlydtl_beam_compiler.erl
@@ -146,15 +146,14 @@ compile_multiple_to_binary(Dir, ParserResults, Context0) ->
{FilePath, CheckSum},
body_ast(DjangoParseTree, Ctx, TreeWalker)),
FunctionName = filename:rootname(filename:basename(File)),
- Function1 = ?Q("_@FunctionName@(_Variables) -> _@FunctionName@(_Variables, [])"),
- Function2 = erl_syntax:function(
- erl_syntax:atom(FunctionName),
- [erl_syntax:clause(
- [erl_syntax:variable("_Variables"),
- erl_syntax:variable("RenderOptions")],
- none,
- MatchAst ++ stringify(BodyAst, Ctx))
- ]),
+ Function1 = ?Q("_@FunctionName@(Variables) -> _@FunctionName@(Variables, [])"),
+ Function2 = ?Q(["_@FunctionName@(Variables, RenderOptions) ->",
+ " try _@MatchAst, _@body of",
+ " Val -> {ok, Val}",
+ " catch",
+ " Err -> {error, Err}",
+ "end"],
+ [{body, stringify(BodyAst, Ctx)}]),
{{FunctionName, Function1, Function2}, {merge_info(AstInfo, BodyInfo), TreeWalker1, Ctx}}
catch
throw:Error ->

0 comments on commit 0b61b69

Please sign in to comment.