Permalink
Browse files

Fix "File not found" error

When a custom tags implementing module is defined in `custom_tags_modules`,
don't throw an exception if the `custom_tags_dir` doesn't contain the file
implementing the custom tag.
  • Loading branch information...
1 parent 6e7bb36 commit cf081931ebe1cf06382a913ff380d2812af4bfe9 @saleyn saleyn committed Oct 27, 2012
Showing with 21 additions and 10 deletions.
  1. +21 −10 src/erlydtl_compiler.erl
View
31 src/erlydtl_compiler.erl
@@ -353,16 +353,26 @@ custom_tags_clauses_ast1([Tag|CustomTags], ExcludeTags, ClauseAcc, InfoAcc, Cont
custom_tags_clauses_ast1(CustomTags, ExcludeTags, ClauseAcc, InfoAcc, Context, TreeWalker);
false ->
CustomTagFile = full_path(Tag, Context#dtl_context.custom_tags_dir),
- case parse(CustomTagFile, Context) of
- {ok, DjangoParseTree, CheckSum} ->
- {{BodyAst, BodyAstInfo}, TreeWalker1} = with_dependency({CustomTagFile, CheckSum},
- body_ast(DjangoParseTree, Context, TreeWalker)),
- Clause = erl_syntax:clause([erl_syntax:string(Tag), erl_syntax:variable("_Variables"), options_ast()],
+ case filelib:is_file(CustomTagFile) of
+ true ->
+ case parse(CustomTagFile, Context) of
+ {ok, DjangoParseTree, CheckSum} ->
+ {{BodyAst, BodyAstInfo}, TreeWalker1} =
+ with_dependency({CustomTagFile, CheckSum},
+ body_ast(DjangoParseTree, Context, TreeWalker)),
+ Clause = erl_syntax:clause(
+ [erl_syntax:string(Tag),
+ erl_syntax:variable("_Variables"), options_ast()],
none, [BodyAst]),
- custom_tags_clauses_ast1(CustomTags, [Tag|ExcludeTags], [Clause|ClauseAcc], merge_info(BodyAstInfo, InfoAcc),
- Context, TreeWalker1);
- Error ->
- throw(Error)
+ custom_tags_clauses_ast1(CustomTags, [Tag|ExcludeTags],
+ [Clause|ClauseAcc], merge_info(BodyAstInfo, InfoAcc),
+ Context, TreeWalker1);
+ Error ->
+ throw(Error)
+ end;
+ false ->
+ custom_tags_clauses_ast1(CustomTags, [Tag | ExcludeTags],
+ ClauseAcc, InfoAcc, Context, TreeWalker)
end
end.
@@ -1278,7 +1288,8 @@ custom_tags_modules_ast(Name, InterpretedArgs, #dtl_context{ custom_tags_modules
I ->
throw({unsupported_custom_tag_fun, {Module, Name, I}})
catch _:function_clause ->
- custom_tags_modules_ast(Name, InterpretedArgs, Context#dtl_context{ custom_tags_modules = Rest })
+ custom_tags_modules_ast(Name, InterpretedArgs,
+ Context#dtl_context{ custom_tags_modules = Rest })
end.
print(true, Fmt, Args) ->

0 comments on commit cf08193

Please sign in to comment.