Permalink
Browse files

Implemented petal:block, based on tal:block from PHPTAL.

  • Loading branch information...
1 parent 95fc91a commit 6c6332fbec2626d8b7c16250762eb0b3f029c612 @supernovus committed Oct 7, 2010
Showing with 31 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 lib/Flower.pm
  3. +23 −0 t/05-block.t
View
@@ -0,0 +1,4 @@
+*.pir
+blib/
+Makefile
+*.swp
View
@@ -119,6 +119,10 @@ method !parse-element($element is rw) {
self!parse-tag($element, $tag, $petal);
if $element !~~ Exemel::Element { last; } # skip if we changed type.
}
+## petal:block borrowed from PHPTAL.
+ if ($element ~~ Exemel::Element && $element.name eq $!petal~':block') {
+ $element = $element.nodes;
+ }
## Haven't figured out METAL stuff entirely yet.
# for @metal -> $metal {
# my $tag = $!metal~':'~$metal;
View
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl6
+
+## Based on the second repeat test, but using petal:block instead of omit-tag.
+
+BEGIN { @*INC.push: './lib' }
+
+use Test;
+use Flower;
+
+plan 1;
+
+my $xml = '<?xml version="1.0"?>';
+
+my @items = (
+ { :alt<One>, :content<First> },
+ { :alt<Two>, :content<Second> },
+ { :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 $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.';
+

0 comments on commit 6c6332f

Please sign in to comment.