Anonymous avatar Anonymous committed 510c1f5

fixed file dependencies for custom call tag and extended test case

Comments (0)

Files changed (4)

demo/out/test_custom_call.html

->>>> before custom call tag
+>>>> before custom call tag 'test_comment'
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
   <head>
   </body>
 </html>
 
->>>> after custom call tag
+>>>> after custom call tag 'test_comment'
+
+>>>> before custom call tag 'test_if'
+One but not two:  two 
+Two but not one:  one 
+One: 
+None: 
+
+>>>> after custom call tag 'test_if'

demo/templates/test_custom_call.html

->>>> before custom call tag
+>>>> before custom call tag 'test_comment'
 {% call test_comment %}
->>>> after custom call tag
+>>>> after custom call tag 'test_comment'
+
+>>>> before custom call tag 'test_if'
+{% call test_if with var1 %}
+>>>> after custom call tag 'test_if'

src/demo/erlydtl_demo.erl

     render(Name, []);
                 
 render("custom_call" = Name) ->
-    render(Name, []);
+    render(Name, [{var1, "something"}]);
                     
 render(Name) ->
     io:format("No such template: ~p~n",[Name]).  

src/erlydtl/erlydtl_compiler.erl

             Render1FunctionAst, SourceFunctionAst, DependenciesFunctionAst, RenderInternalFunctionAst, 
             ProplistsFunctionAst | BodyInfo#ast_info.pre_render_asts]].    
 
-
-full_path(File, DocRoot) ->
-    filename:join([DocRoot, File]).
-
         
 % child templates should only consist of blocks at the top level
 body_ast([{extends, {string_literal, _Pos, String}} | ThisParseTree], Context, TreeWalker) ->
                         BlockDict, Context#dtl_context.block_dict),
                     parse_trail = [File | Context#dtl_context.parse_trail]}, TreeWalker))
     end;
+ 
     
 body_ast(DjangoParseTree, Context, TreeWalker) ->
     {AstInfoList, TreeWalker2} = lists:mapfoldl(
         end, {#ast_info{}, TreeWalker2}, AstInfoList),
     {{erl_syntax:list(AstList), Info}, TreeWalker3}.
 
+
 merge_info(Info1, Info2) ->
     #ast_info{dependencies = 
         lists:merge(
                 Info1#ast_info.pre_render_asts,
                 Info2#ast_info.pre_render_asts)}.
 
+
+with_dependencies([], Args) ->
+    Args;
+with_dependencies([H, T], Args) ->
+     with_dependencies(T, with_dependency(H, Args)).
+        
 with_dependency(FilePath, {{Ast, Info}, TreeWalker}) ->
     {{Ast, Info#ast_info{dependencies = [FilePath | Info#ast_info.dependencies]}}, TreeWalker}.
 
+
 empty_ast(TreeWalker) ->
     {{erl_syntax:list([]), #ast_info{}}, TreeWalker}.
 
+
 string_ast(String, TreeWalker) ->
     {{erl_syntax:string(String), #ast_info{}}, TreeWalker}. %% less verbose AST, better for development and debugging
     % {{erl_syntax:binary([erl_syntax:binary_field(erl_syntax:integer(X)) || X <- String]), #ast_info{}}, TreeWalker}.       
 
+
 include_ast(File, Context, TreeWalker) ->
     FilePath = full_path(File, Context#dtl_context.doc_root),
     {ok, InclusionParseTree} = parse(FilePath, Context#dtl_context.reader),
     with_dependency(FilePath, body_ast(InclusionParseTree, Context#dtl_context{
         parse_trail = [FilePath | Context#dtl_context.parse_trail]}, TreeWalker)).
 
+
 filter_ast(Variable, Filter, Context, TreeWalker) ->
     % the escape filter is special; it is always applied last, so we have to go digging for it
 
     {erl_syntax:application(ModuleAst, erl_syntax:atom(get_value),
                     [erl_syntax:atom(AttrName), resolve_variable_name_ast(VarName, Context)]), VarName}.
 
+
 resolve_variable_name_ast(VarName, Context) ->
     resolve_variable_name_ast(VarName, Context, none).
+  
     
 resolve_variable_name_ast(VarName, Context, ModuleAst) ->
     VarValue = lists:foldl(fun(Scope, Value) ->
             VarValue
     end.
 
+
 format(Ast, Context) ->
     auto_escape(format_integer_ast(Ast), Context).
 
+
 format_integer_ast(Ast) ->
     erl_syntax:application(erl_syntax:atom(erlydtl_filters), erl_syntax:atom(format_integer),
         [Ast]).
 
+
 auto_escape(Value, Context) ->
     case Context#dtl_context.auto_escape of
         on ->
             Value
     end.
 
+
 ifelse_ast(Variable, {IfContentsAst, IfContentsInfo}, {ElseContentsAst, ElseContentsInfo}, Context, TreeWalker) ->
     Info = merge_info(IfContentsInfo, ElseContentsInfo),
     VarNames = Info#ast_info.var_names,
             erl_syntax:clause([erl_syntax:underscore()], none,
                 [IfContentsAst])
         ]), Info#ast_info{var_names = [VarName | VarNames]}}, TreeWalker}.
+
         
 ifequalelse_ast(Args, {IfContentsAst, IfContentsInfo}, {ElseContentsAst, ElseContentsInfo}, Context, TreeWalker) ->
     Info = merge_info(IfContentsInfo, ElseContentsInfo),
                         erl_syntax:list([Arg1Ast, Arg2Ast])]),    
     {{Ast, Info#ast_info{var_names = VarNames}}, TreeWalker}.         
 
+
 for_loop_ast(IteratorList, {variable, Variable}, Contents, Context, TreeWalker) ->
     Vars = lists:map(fun({identifier, _, Iterator}) -> 
                     erl_syntax:variable("Var_" ++ Iterator) 
     CustomTags = lists:merge([X || {identifier, _ , X} <- Names], TreeWalker#treewalker.custom_tags),
     {{erl_syntax:list([]), #ast_info{}}, TreeWalker#treewalker{custom_tags = CustomTags}}.  
 
+
 unescape_string_literal(String) ->
     unescape_string_literal(string:strip(String, both, 34), [], noslash).
 
     unescape_string_literal(Rest, [C | Acc], noslash).
 
 
+full_path(File, DocRoot) ->
+    filename:join([DocRoot, File]).
+        
 %%-------------------------------------------------------------------
 %% Custom tags
 %%-------------------------------------------------------------------
 		 [erl_syntax:tuple([erl_syntax:atom(error), ReasonAst])], 
 		 none,
 		 [ErrStrAst]),
-    CallAst = erl_syntax:case_expr(AppAst, [OkAst, ErrorAst]),
-    {{CallAst, AstInfo}, TreeWalker}.
+    CallAst = erl_syntax:case_expr(AppAst, [OkAst, ErrorAst]),   
+    Module2 = list_to_atom(Module),
+    with_dependencies(Module2:dependencies(), {{CallAst, AstInfo}, TreeWalker}).
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.