Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New refactoring branch is done and all tests pass.

  • Loading branch information...
commit cb401184675082e7aef5b3c9c090b8e830594a3f 1 parent 85d8307
@supernovus authored
View
13 lib/Flower.pm6
@@ -53,17 +53,8 @@ multi method parse (Exemel::Document $template, *%data) {
%.data = %data;
## Let's see if the namespaces has been renamed.
- my %rootattrs;
- for $template.root.attribs.kv -> $key, $val {
- %rootattrs{$val} = $key; ## Yeah, we're reversing it.
- }
for @.plugins -> $plugin {
- $plugin.custom-tag = Nil;
- if %rootattrs.exists($plugin.ns) {
- my $tag = %rootattrs{$plugin.ns};
- $tag ~~ s/^xmlns\://;
- $plugin.custom-tag = $tag;
- }
+ $plugin.custom-tag = $template.root.nsPrefix($plugin.ns);
}
## Okay, now let's parse the elements.
@@ -87,7 +78,7 @@ multi method parse (Stringy $template, *%data) {
## Parse a template using a filename. The filename is passed to find().
method parse-file ($filename, *%data) {
- my $file = $.find($filename);
+ my $file = $.find.($filename);
if $file {
my $template = Exemel::Document.parse(slurp($file));
if $template {
View
2  lib/Flower/TAL/METAL.pm6
@@ -43,7 +43,7 @@ method load-xml-file ($filename) {
return %.file{$filename};
}
- my $file = $.flower.find($filename);
+ my $file = $.flower.find.($filename);
if ($file) {
my $xml = Exemel::Document.parse(slurp($file));
%.file{$filename} = $xml;
View
1  lib/Flower/TAL/TALES.pm6
@@ -38,6 +38,7 @@ method add-plugin ($plugin) {
# $object = ::($plugname).new(:tales(self), :flower($.flower));
### So we use the evil workaround instead.
eval("use $plugname; \$object = {$plugname}.new;"); ## EVIL!
+ if $object ~~ Str { die "Loading '$plugname' failed."; }
$object.tales = self; ## More evil, $.tales should not be rw.
$object.flower = $.flower; ## Yet more evil, $.flower should not be rw.
}
View
2  lib/Flower/TAL/TALES/List.pm6
@@ -3,7 +3,7 @@ class Flower::TAL::TALES::List;
has $.flower is rw;
has $.tales is rw;
-my %modifiers =
+has %.handlers =
'group' => 'list_group',
'sort' => 'list_sort',
'reverse' => 'list_reverse',
View
2  lib/Flower/TAL/TALES/Text.pm6
@@ -3,7 +3,7 @@ class Flower::TAL::TALES::Text;
has $.flower is rw;
has $.tales is rw;
-has %.modifiers =
+has %.handlers =
'uppercase' => 'text_uc',
'upper' => 'text_uc',
'uc' => 'text_uc',
View
38 t/06-utils-date.t
@@ -3,7 +3,7 @@
BEGIN { @*INC.unshift: './lib' }
use Test;
-use Flower;
+use Flower::TAL;
plan 10;
@@ -21,76 +21,68 @@ my %date = {
'day' => 10,
};
+my $tal = Flower::TAL.new();
+
+$tal.add-tales('Date');
+
## test 1
my $template = '<date tal:content="dateof: 2010 10 10"/>';
-my $flower = Flower.new(:template($template));
-
-$flower.load-modifiers('Date');
-is $flower.parse(), $xml~'<date>2010-10-10T00:00:00Z</date>', 'dateof: modifier';
+is ~$tal.parse($template), $xml~'<date>2010-10-10T00:00:00Z</date>', 'dateof: modifier';
## test 2
$template = '<date tal:content="dateof: ${date/year} ${date/month} ${date/day}"/>';
-$flower.=another(:template($template));
-is $flower.parse(:date(%date)), $xml~'<date>2010-10-10T00:00:00Z</date>', 'dateof: modifier using string parsing';
+is ~$tal.parse($template, :date(%date)), $xml~'<date>2010-10-10T00:00:00Z</date>', 'dateof: modifier using string parsing';
## test 3
$template = '<date tal:content="time: \'1286666133\'"/>';
-$flower.=another(:template($template));
-is $flower.parse(), $xml~'<date>2010-10-09T23:15:33Z</date>', 'time: modifier';
+is ~$tal.parse($template), $xml~'<date>2010-10-09T23:15:33Z</date>', 'time: modifier';
## test 4
$template = '<date tal:content="strftime: \'%Y_%m_%d-%T\' date/datetime"/>';
-$flower.=another(:template($template));
-is $flower.parse(:date(%date)), $xml~'<date>2010_10_11-13:17:14</date>', 'strftime: modifier on a datetime object';
+is ~$tal.parse($template, :date(%date)), $xml~'<date>2010_10_11-13:17:14</date>', 'strftime: modifier on a datetime object';
## test 5
$template = '<date tal:content="strftime: \'%b %d, %Y\' date/date"/>';
-$flower.=another(:template($template));
-is $flower.parse(:date(%date)), $xml~'<date>Oct 09, 2010</date>', 'strftime: modifier on a date object';
+is ~$tal.parse($template, :date(%date)), $xml~'<date>Oct 09, 2010</date>', 'strftime: modifier on a date object';
## test 6
$template = "<date tal:content=\"strftime: rfc: \{\{dateof: 2010 10 10 :tz('-0800')}}\"/>";
-$flower.=another(:template($template));
-is $flower.parse(), $xml~'<date>Sun, 10 Oct 2010 00:00:00 -0800</date>', 'strftime: with rfc: modifier';
+is ~$tal.parse($template), $xml~'<date>Sun, 10 Oct 2010 00:00:00 -0800</date>', 'strftime: with rfc: modifier';
## test 7
$template = '<date tal:content="strftime: \'%Y-%m-%d\' now:"/>';
my $now = Date.today();
-$flower.=another(:template($template));
-is $flower.parse(), $xml~'<date>'~$now~'</date>', 'strftime: with now: modifier';
+is $tal.parse($template), $xml~'<date>'~$now~'</date>', 'strftime: with now: modifier';
## test 8
$template = '<date tal:content="date: \'2011-01-12T15:15:00-0800\'"/>';
-$flower.=another(:template($template));
-is $flower.parse(:date(%date)), $xml~'<date>2011-01-12T15:15:00-0800</date>', 'date: modifier';
+is $tal.parse($template, :date(%date)), $xml~'<date>2011-01-12T15:15:00-0800</date>', 'date: modifier';
## test 9
$template = '<date tal:content="strftime: \'%b %d, %Y\' {{date: \'2011-01-12T15:15:00-0800\'}}"/>';
-$flower.=another(:template($template));
-is $flower.parse(:date(%date)), $xml~'<date>Jan 12, 2011</date>', 'strftime: with date: modifier';
+is $tal.parse($template, :date(%date)), $xml~'<date>Jan 12, 2011</date>', 'strftime: with date: modifier';
## test 10
$template = '<date tal:content="strftime: \'%b %d, %Y\' \'2011-01-12T15:15:00-0800\'"/>';
-$flower.=another(:template($template));
-is $flower.parse(:date(%date)), $xml~'<date>Jan 12, 2011</date>', 'strftime: with iso date string';
+is $tal.parse($template, :date(%date)), $xml~'<date>Jan 12, 2011</date>', 'strftime: with iso date string';
View
8 t/06-utils-debug.t
@@ -3,20 +3,20 @@
BEGIN { @*INC.unshift: './lib' }
use Test;
-use Flower;
+use Flower::TAL;
plan 1;
my $xml = '<?xml version="1.0"?>';
my $template = '<test><dump tal:content="dump:object" tal:attributes="type what:object"/></test>';
-my $flower = Flower.new(:template($template));
+my $tal = Flower::TAL.new();
my %ahash = {
'anarray' => [ 'one', 'two', 'three' ],
}
-$flower.load-modifiers('Debug');
+$tal.add-tales('Debug');
-is $flower.parse(object => %ahash), $xml~'<test><dump type="Hash">{"anarray" => ["one", "two", "three"]}</dump></test>', 'dump: and what: modifiers';
+is ~$tal.parse($template, object => %ahash), $xml~'<test><dump type="Hash">{"anarray" => ["one", "two", "three"]}</dump></test>', 'dump: and what: modifiers';
View
33 t/06-utils-list.t
@@ -3,7 +3,7 @@
BEGIN { @*INC.unshift: './lib' }
use Test;
-use Flower;
+use Flower::TAL;
use Exemel;
plan 7;
@@ -14,61 +14,52 @@ my $xml = '<?xml version="1.0"?>';
my $template = '<table><tr tal:repeat="row group:items 2"><td tal:repeat="col row" tal:content="col"/></tr></table>';
-my $flower = Flower.new(:template($template));
+my $tal = Flower::TAL.new();
-$flower.load-modifiers('List');
+$tal.add-tales('List');
-is $flower.parse(:items(['a'..'d'])), $xml~'<table><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table>', 'group: modifier';
+is ~$tal.parse($template, :items(['a'..'d'])), $xml~'<table><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table>', 'group: modifier';
## test 2, sort
$template = '<fresh><i tal:repeat="item sort:items" tal:content="item"/></fresh>';
-$flower.=another(:template($template));
-
my @items = 5,3,7,1,2;
-is $flower.parse(:items(@items)), $xml~'<fresh><i>1</i><i>2</i><i>3</i><i>5</i><i>7</i></fresh>', 'sort: modifier';
+is ~$tal.parse($template, :items(@items)), $xml~'<fresh><i>1</i><i>2</i><i>3</i><i>5</i><i>7</i></fresh>', 'sort: modifier';
## test 3, reverse
$template = '<reverse><i tal:repeat="item reverse:items" tal:content="item"/></reverse>';
-$flower.=another(:template($template));
-is $flower.parse(:items(@items)), $xml~'<reverse><i>2</i><i>1</i><i>7</i><i>3</i><i>5</i></reverse>', 'reverse: modifier';
+is ~$tal.parse($template, :items(@items)), $xml~'<reverse><i>2</i><i>1</i><i>7</i><i>3</i><i>5</i></reverse>', 'reverse: modifier';
## test 4, limit
$template = '<limit><i tal:repeat="item limit: items 2" tal:content="item"/></limit>';
-$flower.=another(:template($template));
-is $flower.parse(:items(@items)), $xml~'<limit><i>5</i><i>3</i></limit>', 'limit: modifier';
+is ~$tal.parse($template, :items(@items)), $xml~'<limit><i>5</i><i>3</i></limit>', 'limit: modifier';
## test 5, limit using a variable
$template = '<limit><i tal:repeat="item limit: items ${limit}" tal:content="item"/></limit>';
-$flower.=another(:template($template));
-is $flower.parse(:items(@items), :limit(3)), $xml~'<limit><i>5</i><i>3</i><i>7</i></limit>', 'limit: modifier using a variable';
+is ~$tal.parse($template, :items(@items), :limit(3)), $xml~'<limit><i>5</i><i>3</i><i>7</i></limit>', 'limit: modifier using a variable';
## test 6, shuffle
$template = '<shuffle><i tal:repeat="item shuffle: items" tal:content="item"/></shuffle>';
-$flower.=another(:template($template));
-my $doc = $flower.parse(:items(@items));
-my $xdoc = Exemel::Element.parse($doc);
+my $doc = $tal.parse($template, :items(@items));
-my @is = $xdoc.elements(:TAG<i>);
+my @is = $doc.root.elements(:TAG<i>);
is @is.elems, 5, 'shuffle: proper number of elements returned';
## test 7, pick
$template = '<shuffle><i tal:repeat="item pick: items 3" tal:content="item"/></shuffle>';
-$flower.=another(:template($template));
-$doc = $flower.parse(:items(@items));
-$xdoc = Exemel::Element.parse($doc);
+$doc = $tal.parse($template, :items(@items));
-@is = $xdoc.elements(:TAG<i>);
+@is = $doc.root.elements(:TAG<i>);
is @is.elems, 3, 'pick: proper number of elements returned';
View
58 t/06-utils-perl.t
@@ -1,58 +0,0 @@
-#!/usr/bin/env perl6
-
-class FooBar {
- method amethod ($name) {
- return "Hello $name";
- }
-}
-
-BEGIN { @*INC.unshift: './lib' }
-
-use Test;
-use Flower;
-
-plan 5;
-
-my $xml = '<?xml version="1.0"?>';
-
-## test 1
-
-my $template = '<test><query tal:replace="perl:ahash<anobj>.amethod(\'world\')"/></test>';
-my $flower = Flower.new(:template($template));
-
-my %ahash = {
- 'anobj' => FooBar.new,
- 'anum' => 2.5,
- 'abad' => '5 * 5',
-}
-
-$flower.load-modifiers('Perl');
-
-is $flower.parse(ahash => %ahash), $xml~'<test>Hello world</test>', 'perl: modifier';
-
-## test 2, oh God this is dangerous.
-
-$template = '<test tal:content="perlx: ahash/anum.Num * 2"/>';
-$flower.=another(:template($template));
-$flower.add-modifier('perlx', &Flower::Utils::Perl::perl_lookup);
-is $flower.parse(ahash => %ahash), $xml~'<test>5</test>', 'perl_lookup modifier (dangerous)';
-
-## test 3, please, don't enable this, it's a security hole waiting to happen.
-
-$template = '<test tal:content="perlxx: pi.fmt(\'%0.4f\')"/>';
-$flower.=another(:template($template));
-$flower.add-modifier('perlxx', &Flower::Utils::Perl::perl_execute);
-is $flower.parse(), $xml~'<test>3.1416</test>', 'perl_execute modifier (really dangerous)';
-
-## test 4, let's try using an illegal word.
-
-$template = '<test tal:content="perl: ahash<abad>.eval"/>';
-$flower.=another(:template($template));
-is $flower.parse(ahash => %ahash), $xml~'<test>5 * 5</test>', 'perl: filtered out an attempt to eval a string';
-
-## test 5, another illegal one.
-
-$template = '<test tal:content="perlxx: run \'ls\'"/>';
-$flower.=another(:template($template));
-is $flower.parse(), $xml~'<test/>', 'filtered out an attempt to use run().';
-
View
31 t/06-utils-text.t
@@ -3,7 +3,7 @@
BEGIN { @*INC.unshift: './lib' }
use Test;
-use Flower;
+use Flower::TAL;
plan 7;
@@ -12,56 +12,45 @@ my $xml = '<?xml version="1.0"?>';
## test 1
my $template = '<test><upper tal:content="uc:string:A test of ${name}, in uppercase."/></test>';
-my $flower = Flower.new(:template($template));
+my $tal = Flower::TAL.new();
-$flower.load-modifiers('Text');
+$tal.add-tales('Text');
-is $flower.parse(name => 'Flower'), $xml~'<test><upper>A TEST OF FLOWER, IN UPPERCASE.</upper></test>', 'uc: modifier';
+is ~$tal.parse($template, name => 'Flower'), $xml~'<test><upper>A TEST OF FLOWER, IN UPPERCASE.</upper></test>', 'uc: modifier';
## test 2
$template = '<test><lower tal:content="lc:default">I AM NOT YELLING</lower></test>';
-$flower.=another(:template($template));
-
-is $flower.parse(), $xml~'<test><lower>i am not yelling</lower></test>', 'lc: modifier';
+is ~$tal.parse($template), $xml~'<test><lower>i am not yelling</lower></test>', 'lc: modifier';
## test 3
$template = '<test><ucfirst tal:replace="ucfirst:\'bob\'"/></test>';
-$flower.=another(:template($template));
-
-is $flower.parse(), $xml~'<test>Bob</test>', 'ucfirst: modifier';
+is ~$tal.parse($template), $xml~'<test>Bob</test>', 'ucfirst: modifier';
## test 4
$template = '<test><substr tal:replace="substr:\'theendoftheworld\' 3 5"/></test>';
-$flower.=another(:template($template));
-
-is $flower.parse(), $xml~'<test>endof</test>', 'substr: modifier';
+is ~$tal.parse($template), $xml~'<test>endof</test>', 'substr: modifier';
## test 5
$template = '<test><substr tal:replace="substr:\'theendoftheworld\' 3 5 1"/></test>';
-$flower.=another(:template($template));
-
-is $flower.parse(), $xml~'<test>endof...</test>', 'substr: modifier with ellipsis';
+is ~$tal.parse($template), $xml~'<test>endof...</test>', 'substr: modifier with ellipsis';
## test 6
$template = '<test><substr tal:replace="substr:\'theendoftheworld\' 3"/></test>';
-$flower.=another(:template($template));
-is $flower.parse(), $xml~'<test>endoftheworld</test>', 'substr: modifier without length';
+is ~$tal.parse($template), $xml~'<test>endoftheworld</test>', 'substr: modifier without length';
## test 7
$template = '<test><printf tal:replace="printf: \'$%0.2f\' \'2.5\'"/></test>';
-$flower.=another(:template($template));
-
-is $flower.parse(), $xml~'<test>$2.50</test>', 'printf: modifier';
+is ~$tal.parse($template), $xml~'<test>$2.50</test>', 'printf: modifier';
View
4 t/07-metal.t
@@ -12,8 +12,8 @@ my $xml = '<?xml version="1.0"?>';
## test 1, basic define and use.
my $template = '<test><zool metal:define-macro="hello">Hello World</zool><zed metal:use-macro="hello">Goodbye Universe</zed></test>';
-my $tal = Flower.new();
-is ~$flower.parse($template), $xml~'<test><zool>Hello World</zool><zool>Hello World</zool></test>', 'metal:define-macro and metal:use-macro';
+my $tal = Flower::TAL.new();
+is ~$tal.parse($template), $xml~'<test><zool>Hello World</zool><zool>Hello World</zool></test>', 'metal:define-macro and metal:use-macro';
## test 2, using from an external file.
Please sign in to comment.
Something went wrong with that request. Please try again.