Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Default namespace changed to 'tal' instead of 'petal'.

  • Loading branch information...
commit e449ef55635c7c5e5832145d3f29df8168d107be 1 parent 2bce131
@supernovus authored
View
2  README
@@ -24,6 +24,8 @@ Note: Flower is not yet complete, and is still missing a lot of functionality.
= Major Differences from Petal:
+ * The default local namespace is 'tal', and to override it, you must
+ declare http://xml.zope.org/namespaces/tal instead of the Petal namespace.
* Flower can use template strings instead of requiring files.
* Flower does not support the multiple template files based on language.
* Adding custom modifiers is completely different in Flower.
View
24 lib/Flower.pm
@@ -5,15 +5,15 @@ use Flower::DefaultModifiers;
has $.template;
-has $!petal is rw = 'petal';
+has $!tal is rw = 'tal';
has $!metal is rw = 'metal';
-has $!i18n is rw = 'i18n';
+has $!i18n is rw = 'i18n';
-has $!petal-ns = 'http://purl.org/petal/1.0/';
+has $!tal-ns = 'http://xml.zope.org/namespaces/tal';
has $!metal-ns = 'http://xml.zope.org/namespaces/metal';
has $!i18n-ns = 'http://xml.zope.org/namespaces/i18n';
-has @!petal-tags = 'define', 'condition', 'repeat', 'attributes', 'content', 'replace', 'omit-tag';
+has @!tal-tags = 'define', 'condition', 'repeat', 'attributes', 'content', 'replace', 'omit-tag';
has @!metal-tags = 'define-macro', 'use-macro', 'define-slot', 'fill-slot';
@@ -70,8 +70,8 @@ method parse (*%data) {
## Next, let's see if the namespaces have been renamed.
for $.template.root.attribs.kv -> $key, $val {
- if $val eq $!petal-ns {
- $!petal = self!xml-ns($key);
+ if $val eq $!tal-ns {
+ $!tal = self!xml-ns($key);
}
elsif $val eq $!metal-ns {
$!metal = self!xml-ns($key);
@@ -86,7 +86,7 @@ method parse (*%data) {
return ~$.template;
}
-## parse-elements, currently only does petal items.
+## parse-elements, currently only does tal items.
## metal will be added in the next major release.
## i18n will be added at some point in the future.
## also TODO: implement 'on-error'.
@@ -114,13 +114,13 @@ method !parse-elements ($xml is rw) {
}
method !parse-element($element is rw) {
- for @!petal-tags -> $petal {
- my $tag = $!petal~':'~$petal;
- self!parse-tag($element, $tag, $petal);
+ for @!tal-tags -> $tal {
+ my $tag = $!tal~':'~$tal;
+ self!parse-tag($element, $tag, $tal);
if $element !~~ Exemel::Element { last; } # skip if we changed type.
}
-## petal:block borrowed from PHPTAL.
- if ($element ~~ Exemel::Element && $element.name eq $!petal~':block') {
+## tal:block borrowed from PHPTAL.
+ if ($element ~~ Exemel::Element && $element.name eq $!tal~':block') {
$element = $element.nodes;
}
## Haven't figured out METAL stuff entirely yet.
View
32 t/01-basics.t
@@ -5,36 +5,40 @@ BEGIN { @*INC.unshift: './lib' }
use Test;
use Flower;
-plan 6;
+plan 7;
my $xml = '<?xml version="1.0"?>';
-my $template = '<test><item petal:define="test my_test_var" petal:content="test"/></test>';
+my $template = '<test><item tal:define="test my_test_var" tal:content="test"/></test>';
my $flower = Flower.new(:template($template));
-is $flower.parse(my_test_var => 'Hello World'), $xml~'<test><item>Hello World</item></test>', 'petal:define and petal:content';
+is $flower.parse(my_test_var => 'Hello World'), $xml~'<test><item>Hello World</item></test>', 'tal:define and tal:content';
-$template = '<test><replaced petal:replace="hello">This will be replaced</replaced></test>';
+$template = '<test><replaced tal:replace="hello">This will be replaced</replaced></test>';
$flower = Flower.new(:template($template));
-is $flower.parse(hello => 'Hello World'), $xml~'<test>Hello World</test>', 'petal:replace';
+is $flower.parse(hello => 'Hello World'), $xml~'<test>Hello World</test>', 'tal:replace';
-$template = '<test><true petal:condition="hello">This is true</true><false petal:condition="notreal">This is false</false><right petal:condition="true:hello"/><wrong petal:condition="false:hello"/></test>';
+$template = '<test><true tal:condition="hello">This is true</true><false tal:condition="notreal">This is false</false><right tal:condition="true:hello"/><wrong tal:condition="false:hello"/></test>';
$flower = Flower.new(:template($template));
-is $flower.parse(hello => 'Hello World'), $xml~'<test><true>This is true</true><right/></test>', 'petal:condition';
+is $flower.parse(hello => 'Hello World'), $xml~'<test><true>This is true</true><right/></test>', 'tal:condition';
-$template = '<test><div petal:omit-tag="">Good <b petal:omit-tag="hello">Day</b> Mate</div></test>';
-#$template = '<test><div petal:omit-tag="string:1">Good Day Mate</div></test>';
+$template = '<test><div tal:omit-tag="">Good <b tal:omit-tag="hello">Day</b> Mate</div></test>';
+#$template = '<test><div tal:omit-tag="string:1">Good Day Mate</div></test>';
$flower = Flower.new(:template($template));
-is $flower.parse(hello => 'hello world'), $xml~'<test>Good Day Mate</test>', 'petal:omit-tag';
+is $flower.parse(hello => 'hello world'), $xml~'<test>Good Day Mate</test>', 'tal:omit-tag';
-$template = '<test><attrib petal:attributes="hello hello; cya goodbye"/></test>';
+$template = '<test><attrib tal:attributes="hello hello; cya goodbye"/></test>';
$flower = Flower.new(:template($template));
my $matched = False;
my $output = $flower.parse(hello => 'Hello World', goodbye => 'Goodbye Universe');
if $output eq $xml~'<test><attrib hello="Hello World" cya="Goodbye Universe"/></test>' { $matched = True; }
elsif $output eq $xml~'<test><attrib cya="Goodbye Universe" hello="Hello World"/></test>' { $matched = True; }
-ok $matched, 'petal:attributes';
+ok $matched, 'tal:attributes';
-$template = '<test><hello/><goodbye petal:replace=""/></test>';
+$template = '<test><hello/><goodbye tal:replace=""/></test>';
$flower = Flower.new(:template($template));
-is $flower.parse(), $xml~'<test><hello/></test>', 'petal:replace when empty.';
+is $flower.parse(), $xml~'<test><hello/></test>', 'tal:replace when empty.';
+
+$template = '<test xmlns:petal="http://xml.zope.org/namespaces/tal"><div petal:replace="test"/></test>';
+$flower = Flower.new(:template($template));
+is $flower.parse(test=>'Hello World'), $xml~'<test xmlns:petal="http://xml.zope.org/namespaces/tal">Hello World</test>', 'tal:replace with custom namespace.';
View
8 t/02-repeat.t
@@ -9,7 +9,7 @@ plan 2;
my $xml = '<?xml version="1.0"?>';
-my $template = '<test><item petal:repeat="item items" petal:attributes="alt item/alt" petal:content="item/content"/></test>';
+my $template = '<test><item tal:repeat="item items" tal:attributes="alt item/alt" tal:content="item/content"/></test>';
my $flower = Flower.new(:template($template));
my @items = (
{ :alt<One>, :content<First> },
@@ -17,9 +17,9 @@ my @items = (
{ :alt<Three>, :content<Third> },
);
-is $flower.parse(:items(@items)), $xml~'<test><item alt="One">First</item><item alt="Two">Second</item><item alt="Three">Third</item></test>', 'petal:repeat';
+is $flower.parse(:items(@items)), $xml~'<test><item alt="One">First</item><item alt="Two">Second</item><item alt="Three">Third</item></test>', 'tal:repeat';
-$template = '<test><div petal:repeat="item items" petal:omit-tag=""><tr><td petal:content="item/alt"/><td petal:content="item/content"/></tr></div></test>';
+$template = '<test><div tal:repeat="item items" tal:omit-tag=""><tr><td tal:content="item/alt"/><td tal:content="item/content"/></tr></div></test>';
$flower = Flower.new(:template($template));
-is $flower.parse(:items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'petal:repeat with nested elements and omit-tag';
+is $flower.parse(:items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:repeat with nested elements and omit-tag';
View
2  t/03-custom-modifiers.t
@@ -14,7 +14,7 @@ plan 1;
my $xml = '<?xml version="1.0"?>';
-my $template = '<test><upper petal:content="uc:string:A test of ${name}, in uppercase."/></test>';
+my $template = '<test><upper tal:content="uc:string:A test of ${name}, in uppercase."/></test>';
my $flower = Flower.new(:template($template));
$flower.add-modifiers(Flower::Utils::Text::all());
View
4 t/04-methods.t
@@ -16,8 +16,8 @@ plan 1;
my $xml = '<?xml version="1.0"?>';
-my $template = "<test><item petal:content=\"self/talk 'Tim'\"/></test>";
+my $template = "<test><item tal:content=\"self/talk 'Tim'\"/></test>";
my $flower = Flower.new(:template($template));
-is $flower.parse(:self(Person.new)), $xml~'<test><item>Why are you talking to yourself Tim?</item></test>', 'petal:content with method call';
+is $flower.parse(:self(Person.new)), $xml~'<test><item>Why are you talking to yourself Tim?</item></test>', 'tal:content with method call';
View
6 t/05-block.t
@@ -1,6 +1,6 @@
#!/usr/bin/env perl6
-## Based on the second repeat test, but using petal:block instead of omit-tag.
+## Based on the second repeat test, but using tal:block instead of omit-tag.
BEGIN { @*INC.unshift: './lib' }
@@ -17,7 +17,7 @@ my @items = (
{ :alt<Three>, :content<Third> },
);
-my $template = '<test><petal:block petal:repeat="item items"><tr><td petal:content="item/alt"/><td petal:content="item/content"/></tr></petal:block></test>';
+my $template = '<test><tal:block tal:repeat="item items"><tr><td tal:content="item/alt"/><td tal:content="item/content"/></tr></tal:block></test>';
my $flower = Flower.new(:template($template));
-is $flower.parse(:items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'petal:block with a repeated item.';
+is $flower.parse(:items(@items)), $xml~'<test><tr><td>One</td><td>First</td></tr><tr><td>Two</td><td>Second</td></tr><tr><td>Three</td><td>Third</td></tr></test>', 'tal:block with a repeated item.';
Please sign in to comment.
Something went wrong with that request. Please try again.