Permalink
Browse files

Integrate new filters and tests from dgulino

Restructured the file layout somewhat.
  • Loading branch information...
1 parent 3aa6967 commit ae6bf4b0362c9eda14b3fe83b775a1b6f3f4d9a1 @evanmiller evanmiller committed Mar 18, 2011
Showing with 921 additions and 396 deletions.
  1. +4 −6 Emakefile
  2. +3 −3 Makefile
  3. +1 −1 README.markdown
  4. +1 −5 ebin/erlydtl.app
  5. 0 src/{erlydtl → }/erlydtl.erl
  6. +17 −20 src/{erlydtl → }/erlydtl_compiler.erl
  7. 0 src/{erlydtl → }/erlydtl_deps.erl
  8. +409 −303 src/{erlydtl → }/erlydtl_filters.erl
  9. 0 src/{erlydtl → }/erlydtl_i18n.erl
  10. +1 −0 src/{erlydtl → }/erlydtl_parser.yrl
  11. 0 src/{erlydtl → }/erlydtl_runtime.erl
  12. 0 src/{erlydtl → }/erlydtl_scanner.erl
  13. 0 src/{erlydtl → }/filter_lib/erlydtl_dateformat.erl
  14. +13 −17 src/{erlydtl → }/filter_lib/erlydtl_slice.erl
  15. 0 src/{erlydtl → }/i18n/Makefile
  16. 0 src/{erlydtl → }/i18n/i18n_manager.erl
  17. 0 src/{erlydtl → }/i18n/po_generator.erl
  18. 0 src/{erlydtl → }/i18n/po_scanner.erl
  19. 0 src/{erlydtl → }/i18n/sources_parser.erl
  20. 0 {examples/docroot → tests/input}/autoescape
  21. 0 {examples/docroot → tests/input}/base
  22. 0 {examples/docroot → tests/input}/comment
  23. 0 {examples/docroot → tests/input}/custom_call
  24. 0 {examples/docroot → tests/input}/custom_tag
  25. 0 {examples/docroot → tests/input}/cycle
  26. 0 {examples/docroot → tests/input}/extends
  27. 0 {examples/docroot → tests/input}/extends_path
  28. 0 {examples/docroot → tests/input}/extends_path2
  29. 0 {examples/docroot → tests/input}/filters
  30. 0 {examples/docroot → tests/input}/for
  31. 0 {examples/docroot → tests/input}/for_list
  32. 0 {examples/docroot → tests/input}/for_list_preset
  33. 0 {examples/docroot → tests/input}/for_preset
  34. 0 {examples/docroot → tests/input}/for_records
  35. 0 {examples/docroot → tests/input}/for_records_preset
  36. 0 {examples/docroot → tests/input}/for_tuple
  37. 0 {examples/docroot → tests/input}/if
  38. 0 {examples/docroot → tests/input}/if_preset
  39. 0 {examples/docroot → tests/input}/ifequal
  40. 0 {examples/docroot → tests/input}/ifequal_preset
  41. 0 {examples/docroot → tests/input}/ifnotequal
  42. 0 {examples/docroot → tests/input}/ifnotequal_preset
  43. 0 {examples/docroot → tests/input}/include
  44. 0 {examples/docroot → tests/input}/include.html
  45. 0 {examples/docroot → tests/input}/include_path
  46. 0 {examples/docroot → tests/input}/include_template
  47. 0 {examples/docroot → tests/input}/now
  48. 0 {examples/docroot → tests/input}/path1/base1
  49. 0 {examples/docroot → tests/input}/path1/base2
  50. 0 {examples/docroot → tests/input}/path1/include1
  51. 0 {examples/docroot → tests/input}/path1/template1
  52. 0 {examples/docroot → tests/input}/path2/base2
  53. 0 {examples/docroot → tests/input}/path2/template2
  54. 0 {examples/docroot → tests/input}/trans
  55. 0 {examples/docroot → tests/input}/var
  56. 0 {examples/docroot → tests/input}/var_preset
  57. +49 −0 tests/py/erlydtl_python_test.py
  58. BIN tests/py/erlydtl_python_test.pyc
  59. +29 −0 tests/py/python_dtl_setup.txt
  60. +15 −0 tests/py/run_erl_node.sh
  61. 0 {src/tests → tests/src}/erlydtl_dateformat_tests.erl
  62. 0 {src/tests → tests/src}/erlydtl_example_variable_storage.erl
  63. +2 −2 {src/tests → tests/src}/erlydtl_functional_tests.erl
  64. +377 −39 {src/tests → tests/src}/erlydtl_unittests.erl
  65. 0 {src/tests → tests/src}/gettext.erl
  66. 0 {src/tests/i18n → tests/src}/sources_parser_unittests.erl
View
@@ -1,6 +1,4 @@
-{"src/erlydtl/*", [debug_info, {outdir, "ebin"}]}.
-{"src/erlydtl/i18n/*", [debug_info, {outdir, "ebin"}]}.
-{"src/erlydtl/filter_lib/*", [debug_info, {outdir, "ebin"}]}.
-{"src/tests/*", [debug_info, {outdir, "ebintest"}]}.
-{"src/tests/i18n/*", [debug_info, {outdir, "ebintest"}]}.
-{"src/demo/*", [debug_info, {outdir, "ebintest"}]}.
+{"src/*", [debug_info, {outdir, "ebin"}]}.
+{"src/i18n/*", [debug_info, {outdir, "ebin"}]}.
+{"src/filter_lib/*", [debug_info, {outdir, "ebin"}]}.
+{"tests/src/*", [debug_info, {outdir, "ebintest"}]}.
View
@@ -1,7 +1,7 @@
ERL=erl
ERLC=erlc
-PARSER=src/erlydtl/erlydtl_parser
+PARSER=src/erlydtl_parser
all: compile
@@ -11,7 +11,7 @@ compile: $(PARSER).erl
$(ERL) -make
$(PARSER).erl: $(PARSER).yrl
- $(ERLC) -o src/erlydtl src/erlydtl/erlydtl_parser.yrl
+ $(ERLC) -o src src/erlydtl_parser.yrl
run: compile
$(ERL) -pa ebin
@@ -29,4 +29,4 @@ clean:
rm -fv ebin/*.beam
rm -fv ebintest/*
rm -fv erl_crash.dump $(PARSER).erl
- rm -fv examples/rendered_output/*
+ rm -fv tests/output/*
View
@@ -125,4 +125,4 @@ From a Unix shell, run:
make test
-Note that the tests will create some output in examples/rendered_output.
+Note that the tests will create some output in tests/output.
View
@@ -1,21 +1,17 @@
%% -*- mode: erlang -*-
{application, erlydtl,
[{description, "ErlyDTL implements most but not all of the Django Template Language"},
- {vsn, "0.6.1"},
+ {vsn, "0.7.0"},
{modules, [
erlydtl,
erlydtl_compiler,
erlydtl_dateformat,
- erlydtl_dateformat_tests,
erlydtl_deps,
- erlydtl_example_variable_storage,
erlydtl_filters,
- erlydtl_functional_tests,
erlydtl_parser,
erlydtl_runtime,
erlydtl_scanner,
erlydtl_slice,
- erlydtl_unittests,
erlydtl_i18n,
i18n_manager,
po_generator,
File renamed without changes.
@@ -677,20 +677,23 @@ filter_ast(Variable, Filter, Context, TreeWalker) ->
filter_ast_noescape(Variable, [{identifier, _, 'escape'}], Context, TreeWalker) ->
value_ast(Variable, true, Context, TreeWalker);
filter_ast_noescape(Variable, Filter, Context, TreeWalker) ->
- {{VariableAst, Info}, TreeWalker2} = value_ast(Variable, true, Context, TreeWalker),
- VarValue = filter_ast1(Filter, VariableAst),
- {{VarValue, Info}, TreeWalker2}.
-
-filter_ast1([{identifier, _, Name}, {string_literal, _, ArgName}], VariableAst) ->
- filter_ast2(Name, VariableAst, [erl_syntax:string(unescape_string_literal(ArgName))]);
-filter_ast1([{identifier, _, Name}, {number_literal, _, ArgName}], VariableAst) ->
- filter_ast2(Name, VariableAst, [erl_syntax:integer(list_to_integer(ArgName))]);
-filter_ast1([{identifier, _, Name}|_], VariableAst) ->
- filter_ast2(Name, VariableAst, []).
-
-filter_ast2(Name, VariableAst, AdditionalArgs) ->
- erl_syntax:application(erl_syntax:atom(erlydtl_filters), erl_syntax:atom(Name),
- [VariableAst | AdditionalArgs]).
+ {{VariableAst, Info1}, TreeWalker2} = value_ast(Variable, true, Context, TreeWalker),
+ {VarValue, Info2} = filter_ast1(Filter, VariableAst, Context),
+ {{VarValue, merge_info(Info1, Info2)}, TreeWalker2}.
+
+filter_ast1([{identifier, _, Name}, {string_literal, _, ArgName}], VariableAst, _Context) ->
+ filter_ast2(Name, VariableAst, [erl_syntax:string(unescape_string_literal(ArgName))], []);
+filter_ast1([{identifier, _, Name}, {number_literal, _, ArgName}], VariableAst, _Context) ->
+ filter_ast2(Name, VariableAst, [erl_syntax:integer(list_to_integer(ArgName))], []);
+filter_ast1([{identifier, _, Name}, ArgVariable], VariableAst, Context) ->
+ {ArgAst, ArgVarName} = resolve_variable_ast(ArgVariable, Context),
+ filter_ast2(Name, VariableAst, [ArgAst], [ArgVarName]);
+filter_ast1([{identifier, _, Name}], VariableAst, _Context) ->
+ filter_ast2(Name, VariableAst, [], []).
+
+filter_ast2(Name, VariableAst, AdditionalArgs, VarNames) ->
+ {erl_syntax:application(erl_syntax:atom(erlydtl_filters), erl_syntax:atom(Name),
+ [VariableAst | AdditionalArgs]), #ast_info{var_names = VarNames}}.
search_for_escape_filter(_, _, #dtl_context{auto_escape = on}) ->
on;
@@ -707,7 +710,6 @@ search_for_escape_filter(_Variable, _Filter) ->
off.
-
resolve_variable_ast(VarTuple, Context) ->
resolve_variable_ast(VarTuple, Context, 'find_value').
@@ -726,11 +728,6 @@ resolve_variable_ast({variable, {identifier, _, VarName}}, Context, FinderFuncti
end,
{VarValue, VarName};
-resolve_variable_ast({apply_filter, Variable, Filter}, Context, FinderFunction) ->
- {VarAst, VarName} = resolve_variable_ast(Variable, Context, FinderFunction),
- VarValue = filter_ast1(Filter, erl_syntax:list([VarAst])),
- {VarValue, VarName};
-
resolve_variable_ast(What, _Context, _FinderFunction) ->
error_logger:error_msg("~p:resolve_variable_ast unhandled: ~p~n", [?MODULE, What]).
File renamed without changes.
Oops, something went wrong.

0 comments on commit ae6bf4b

Please sign in to comment.