Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use correct docroot in included templates. Thanks to Tobias Loefgren.

git-svn-id: http://erlydtl.googlecode.com/svn/trunk@152 a5195066-8e3e-0410-a82a-05b01b1b9875
  • Loading branch information...
commit 292951c8bc7acb4248c28472f6786ae3398786dd 1 parent 5803797
authored February 11, 2009
3  examples/docroot/extends_path
... ...
@@ -0,0 +1,3 @@
  1
+{% extends "path1/base1" %}
  2
+{% block title %}replacing the base title{% endblock %}
  3
+{% block content %}replacing the base content - variable: {{ test_var }} after variable {% endblock %}
5  examples/docroot/include_path
... ...
@@ -0,0 +1,5 @@
  1
+main file
  2
+
  3
+{% include "path1/template1" %}
  4
+
  5
+{{ base_var }}
3  examples/docroot/include_template
... ...
@@ -0,0 +1,3 @@
  1
+Including another template: {% include "base" %}
  2
+
  3
+test variable: {{ test_var }}
6  examples/docroot/path1/base1
... ...
@@ -0,0 +1,6 @@
  1
+{% extends "../path2/base2" %}
  2
+
  3
+{% block title2 %}block title 2 from  base1 {% endblock %}
  4
+
  5
+
  6
+
5  examples/docroot/path1/template1
... ...
@@ -0,0 +1,5 @@
  1
+This is template 1.
  2
+
  3
+{{ test_var }}
  4
+
  5
+{% include "../path2/template2" %}
14  examples/docroot/path2/base2
... ...
@@ -0,0 +1,14 @@
  1
+{{ base_var }}
  2
+
  3
+base2 template
  4
+
  5
+{% block title %}block title in base2, should be hidden by main template{% endblock %}
  6
+{% block title2 %}block title2 in base2, should be hidden by base1{% endblock %}
  7
+
  8
+more of base2 template
  9
+
  10
+{% block content %}block content in base 2, should be overwritten{% endblock %}
  11
+
  12
+{% block content2 %}block content2 in base 2, should pass through{% endblock %}
  13
+
  14
+end of base2 template
2  examples/docroot/path2/template2
... ...
@@ -0,0 +1,2 @@
  1
+
  2
+This is template 2
6  src/erlydtl/erlydtl_compiler.erl
@@ -293,7 +293,8 @@ body_ast([{extends, {string_literal, _Pos, String}} | ThisParseTree], Context, T
293 293
                     with_dependency({File, CheckSum}, body_ast(ParentParseTree, Context#dtl_context{
294 294
                         block_dict = dict:merge(fun(_Key, _ParentVal, ChildVal) -> ChildVal end,
295 295
                             BlockDict, Context#dtl_context.block_dict),
296  
-                                parse_trail = [File | Context#dtl_context.parse_trail]}, TreeWalker));
  296
+                                parse_trail = [File | Context#dtl_context.parse_trail], 
  297
+                                doc_root = filename:dirname(File)}, TreeWalker));
297 298
                 Err ->
298 299
                     throw(Err)
299 300
             end        
@@ -449,7 +450,8 @@ include_ast(File, Context, TreeWalker) ->
449 450
     case parse(FilePath, Context) of
450 451
         {ok, InclusionParseTree, CheckSum} ->
451 452
             with_dependency({FilePath, CheckSum}, body_ast(InclusionParseTree, Context#dtl_context{
452  
-                parse_trail = [FilePath | Context#dtl_context.parse_trail]}, TreeWalker));
  453
+                parse_trail = [FilePath | Context#dtl_context.parse_trail], 
  454
+                doc_root = filename:dirname(FilePath) }, TreeWalker));
453 455
         Err ->
454 456
             throw(Err)
455 457
     end.
13  src/tests/erlydtl_functional_tests.erl
@@ -45,7 +45,8 @@ test_list() ->
45 45
         "for_records_preset", "include", "if", "if_preset", "ifequal",
46 46
         "ifequal_preset", "ifnotequal", "ifnotequal_preset", "now",
47 47
         "var", "var_preset", "var_error", "cycle", "custom_tag",
48  
-        "custom_tag_error", "custom_call"].
  48
+        "custom_tag_error", "custom_call", 
  49
+        "include_template", "include_path", "extends_path" ].
49 50
 
50 51
 setup_compile("for_list_preset") ->
51 52
     CompileVars = [{fruit_list, [["apple", "apples"], ["banana", "bananas"], ["coconut", "coconuts"]]}],
@@ -144,6 +145,16 @@ setup("cycle") ->
144 145
     RenderVars = [{test, [integer_to_list(X) || X <- lists:seq(1, 20)]},
145 146
                   {a, "Apple"}, {b, "Banana"}, {c, "Cherry"}],
146 147
     {ok, RenderVars};
  148
+setup("include_template") ->
  149
+    RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
  150
+    {ok, RenderVars};
  151
+setup("include_path") ->
  152
+    RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
  153
+    {ok, RenderVars};
  154
+setup("extends_path") ->
  155
+    RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
  156
+    {ok, RenderVars};
  157
+
147 158
 %%--------------------------------------------------------------------       
148 159
 %% Custom tags
149 160
 %%--------------------------------------------------------------------

0 notes on commit 292951c

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