Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ifnotequal tag

  • Loading branch information...
commit 7ebb7dd1f22f0165eb844a6d110a609adb6ede69 1 parent 15fa5ce
@rsaccon rsaccon authored
View
28 demo/out/test_ifnotequal.html
@@ -0,0 +1,28 @@
+
+
+
+else: var1="foo" and var2="foo" are not equal
+
+
+
+if: var1="foo" and var3="bar" are equal
+
+
+
+if: var1="foo" and var3="bar" are equal
+
+
+
+else: "foo" and "foo" are not equal
+
+
+
+if: "foo" and "bar" are equal
+
+
+
+else: 99 and 99 are not equal
+
+
+
+if: 77 and 99 are equal
View
28 demo/out/test_ifnotequal_preset.html
@@ -0,0 +1,28 @@
+
+
+
+else: var1="foo" and var2="foo" are not equal
+
+
+
+if: var1="foo" and var3="bar" are equal
+
+
+
+if: var1="foo" and var3="bar" are equal
+
+
+
+else: "foo" and "foo" are not equal
+
+
+
+if: "foo" and "bar" are equal
+
+
+
+else: 99 and 99 are not equal
+
+
+
+if: 77 and 99 are equal
View
2  demo/templates/test_ifequal.html
@@ -33,7 +33,7 @@
{% ifequal 99 99 %}
if: 99 and 99 are equal
{% else %}
-else: 99 and 99" are not equal
+else: 99 and 99 are not equal
{% endifequal %}
{% ifequal 77 99 %}
View
2  demo/templates/test_ifequal_preset.html
@@ -33,7 +33,7 @@
{% ifequal 99 99 %}
if: 99 and 99 are equal
{% else %}
-else: 99 and 99" are not equal
+else: 99 and 99 are not equal
{% endifequal %}
{% ifequal 77 99 %}
View
43 demo/templates/test_ifnotequal.html
@@ -0,0 +1,43 @@
+{% ifnotequal var1 var2 %}
+if: var1="foo" and var2="foo" are equal
+{% endifnotequal %}
+
+{% ifnotequal var1 var2 %}
+if: var1="foo" and var2="foo" are equal
+{% else %}
+else: var1="foo" and var2="foo" are not equal
+{% endifnotequal %}
+
+{% ifnotequal var1 var3 %}
+if: var1="foo" and var3="bar" are equal
+{% endifnotequal %}
+
+{% ifnotequal var1 var3 %}
+if: var1="foo" and var3="bar" are equal
+{% else %}
+else: var1="foo" and var3="bar" are not equal
+{% endifnotequal %}
+
+{% ifnotequal "foo" "foo" %}
+if: "foo" and "foo" are equal
+{% else %}
+else: "foo" and "foo" are not equal
+{% endifnotequal %}
+
+{% ifnotequal "foo" "bar" %}
+if: "foo" and "bar" are equal
+{% else %}
+else: "foo" and "bar" are not equal
+{% endifnotequal %}
+
+{% ifnotequal 99 99 %}
+if: 99 and 99 are equal
+{% else %}
+else: 99 and 99 are not equal
+{% endifnotequal %}
+
+{% ifnotequal 77 99 %}
+if: 77 and 99 are equal
+{% else %}
+else: 77 and 99 are not equal
+{% endifnotequal %}
View
43 demo/templates/test_ifnotequal_preset.html
@@ -0,0 +1,43 @@
+{% ifnotequal var1 var2 %}
+if: var1="foo" and var2="foo" are equal
+{% endifnotequal %}
+
+{% ifnotequal var1 var2 %}
+if: var1="foo" and var2="foo" are equal
+{% else %}
+else: var1="foo" and var2="foo" are not equal
+{% endifnotequal %}
+
+{% ifnotequal var1 var3 %}
+if: var1="foo" and var3="bar" are equal
+{% endifnotequal %}
+
+{% ifnotequal var1 var3 %}
+if: var1="foo" and var3="bar" are equal
+{% else %}
+else: var1="foo" and var3="bar" are not equal
+{% endifnotequal %}
+
+{% ifnotequal "foo" "foo" %}
+if: "foo" and "foo" are equal
+{% else %}
+else: "foo" and "foo" are not equal
+{% endifnotequal %}
+
+{% ifnotequal "foo" "bar" %}
+if: "foo" and "bar" are equal
+{% else %}
+else: "foo" and "bar" are not equal
+{% endifnotequal %}
+
+{% ifnotequal 99 99 %}
+if: 99 and 99 are equal
+{% else %}
+else: 99 and 99 are not equal
+{% endifnotequal %}
+
+{% ifnotequal 77 99 %}
+if: 77 and 99 are equal
+{% else %}
+else: 77 and 99 are not equal
+{% endifnotequal %}
View
26 src/demo/erlydtl_demo.erl
@@ -81,7 +81,9 @@ compile_all() ->
compile("if"),
compile("if_preset"),
compile("ifequal"),
- compile("ifequal_preset"),
+ compile("ifequal_preset"),
+ compile("ifnotequal"),
+ compile("ifnotequal_preset"),
compile("include"),
compile("var"),
compile("var_preset").
@@ -122,7 +124,14 @@ compile("ifequal" = Name) ->
compile("ifequal_preset" = Name) ->
Vars = [{var1, "foo"}, {var2, "foo"}],
compile(Name, ".html", Vars);
-
+
+compile("ifnotequal" = Name) ->
+ compile(Name, ".html", []);
+
+compile("ifnotequal_preset" = Name) ->
+ Vars = [{var1, "foo"}, {var2, "foo"}],
+ compile(Name, ".html", Vars);
+
compile("filters" = Name) ->
compile(Name, ".html", []);
@@ -144,8 +153,7 @@ compile("for_list_preset" = Name) ->
compile("htmltags" = Name) ->
compile(Name, ".html", []);
-
-
+
compile("for_preset" = Name) ->
Vars = [{fruit_list, ["preset-apple", "preset-banana", "preset-coconut"]}],
compile(Name, ".html", Vars);
@@ -199,7 +207,9 @@ render_all() ->
render("if"),
render("if_preset"),
render("ifequal"),
- render("ifequal_preset"),
+ render("ifequal_preset"),
+ render("ifnotequal"),
+ render("ifnotequal_preset"),
render("include"),
render("var"),
render("var_preset").
@@ -237,6 +247,12 @@ render("ifequal" = Name) ->
render("ifequal_preset" = Name) ->
render(Name, [{var3, "bar"}]);
+render("ifnotequal" = Name) ->
+ render(Name, [{var1, "foo"}, {var2, "foo"}, {var3, "bar"}]);
+
+render("ifnotequal_preset" = Name) ->
+ render(Name, [{var3, "bar"}]);
+
render("for" = Name) ->
render(Name, [{fruit_list, ["apple", "banana", "coconut"]}]);
View
9 src/erlydtl/erlydtl_compiler.erl
@@ -224,14 +224,17 @@ body_ast(DjangoParseTree, Context) ->
body_ast(ElseContents, Context), Context);
({'ifelse', {'not', {variable, Variable}}, IfContents, ElseContents}) ->
ifelse_ast(Variable, body_ast(ElseContents, Context),
- body_ast(IfContents, Context), Context);
-
+ body_ast(IfContents, Context), Context);
({'ifequal', Args, Contents}) ->
ifequalelse_ast(Args, body_ast(Contents, Context), empty_ast(), Context);
({'ifequalelse', Args, IfContents, ElseContents}) ->
ifequalelse_ast(Args,body_ast(IfContents, Context),
body_ast(ElseContents, Context), Context);
-
+ ({'ifnotequal', Args, Contents}) ->
+ ifequalelse_ast(Args, empty_ast(), body_ast(Contents, Context), Context);
+ ({'ifnotequalelse', Args, IfContents, ElseContents}) ->
+ ifequalelse_ast(Args,body_ast(ElseContents, Context),
+ body_ast(IfContents, Context), Context);
({'apply_filter', Variable, Filter}) ->
filter_ast(Variable, Filter, Context);
({'for', {'in', {identifier, _, Iterator}, {identifier, _, List}}, Contents}) ->
View
1,923 src/erlydtl/erlydtl_parser.erl
1,118 additions, 805 deletions not shown
View
16 src/erlydtl/erlydtl_parser.yrl
@@ -67,7 +67,12 @@ Nonterminals
IfEqualBlock
IfEqualBraced
IfEqualExpression
- EndIfEqualBraced
+ EndIfEqualBraced
+
+ IfNotEqualBlock
+ IfNotEqualBraced
+ IfNotEqualExpression
+ EndIfNotEqualBraced
AutoEscapeBlock
AutoEscapeBraced
@@ -92,12 +97,14 @@ Terminals
endfor_keyword
endif_keyword
endifequal_keyword
+ endifnotequal_keyword
equal
extends_keyword
for_keyword
identifier
if_keyword
ifequal_keyword
+ ifnotequal_keyword
in_keyword
include_keyword
not_keyword
@@ -121,6 +128,7 @@ Elements -> Elements BlockBlock : '$1' ++ ['$2'].
Elements -> Elements ForBlock : '$1' ++ ['$2'].
Elements -> Elements IfBlock : '$1' ++ ['$2'].
Elements -> Elements IfEqualBlock : '$1' ++ ['$2'].
+Elements -> Elements IfNotEqualBlock : '$1' ++ ['$2'].
Elements -> Elements AutoEscapeBlock : '$1' ++ ['$2'].
Elements -> Elements CommentBlock : '$1' ++ ['$2'].
@@ -171,6 +179,12 @@ IfEqualBraced -> open_tag ifequal_keyword IfEqualExpression Variable close_tag :
IfEqualExpression -> Variable : '$1'.
EndIfEqualBraced -> open_tag endifequal_keyword close_tag.
+IfNotEqualBlock -> IfNotEqualBraced Elements ElseBraced Elements EndIfNotEqualBraced : {ifnotequalelse, '$1', '$2', '$4'}.
+IfNotEqualBlock -> IfNotEqualBraced Elements EndIfNotEqualBraced : {ifnotequal, '$1', '$2'}.
+IfNotEqualBraced -> open_tag ifnotequal_keyword IfNotEqualExpression Variable close_tag : ['$3', '$4'].
+IfNotEqualExpression -> Variable : '$1'.
+EndIfNotEqualBraced -> open_tag endifnotequal_keyword close_tag.
+
AutoEscapeBlock -> AutoEscapeBraced Elements EndAutoEscapeBraced : {autoescape, '$1', '$2'}.
AutoEscapeBraced -> open_tag autoescape_keyword identifier close_tag : '$3'.
EndAutoEscapeBraced -> open_tag endautoescape_keyword close_tag.
Please sign in to comment.
Something went wrong with that request. Please try again.