Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple preview for layouts - moved to simpler parser for template…
… rendering
- Loading branch information
Showing
13 changed files
with
588 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,103 +1,54 @@ | |||
package OokOok::Base::TagLibrary; | use MooseX::Declare; | ||
|
|
||
use Moose; | class OokOok::Base::TagLibrary { | ||
use MooseX::Types::Moose qw( ArrayRef ); | use MooseX::Types::Moose qw( ArrayRef ); | ||
use namespace::autoclean; | |||
|
|
||
use XML::LibXML; | has c => ( is => 'rw', isa => 'Maybe[Object]',); | ||
|
|
||
has c => ( | has date => ( is => 'rw',); | ||
is => 'rw', | |||
isa => 'Maybe[Object]', | |||
); | |||
|
|
||
has date => ( | method process_node ($ctx, $node) { | ||
is => 'rw', | # we want to pull out attributes and such based on needs of tag | ||
); | my $name = $node -> {local}; | ||
my $einfo = $self -> meta -> element( $name ); | |||
return if !$einfo; # TODO: perhaps throw an error if not a defined element | |||
|
|
||
sub process_node { | return if !$einfo -> {impl}; # Nothing to do, so don't do anything | ||
my($self, $ctx, $node) = @_; | |||
|
|
||
# we want to pull out attributes and such based on needs of tag | my $context = $ctx -> localize; | ||
my $name = (split(":", $node -> nodeName, 2))[1]; | my $xmlns; | ||
my $einfo = $self -> meta -> element( $name ); | my $attributes = {}; | ||
return if !$einfo; # TODO: perhaps throw an error if not a defined element | for my $ns (keys %{$einfo->{attributes}}) { | ||
|
$xmlns = $ns; | ||
return if !$einfo -> {impl}; # Nothing to do, so don't do anything | if($ns eq '') { | ||
|
$xmlns = $self -> meta -> namespace; | ||
my $context = $ctx -> localize; | |||
my $xmlns; | |||
my $attributes = {}; | |||
for my $ns (keys %{$einfo->{attributes}}) { | |||
$xmlns = $ns; | |||
if($ns eq '') { | |||
$xmlns = $self -> meta -> namespace; | |||
} | |||
for my $a (keys %{$einfo->{attributes}->{$ns}||{}}) { | |||
my $value = $node -> getAttributeNS($xmlns, $a); | |||
if($einfo->{attributes}->{$ns}->{$a} eq 'Str') { | |||
if(defined $value) { | |||
$attributes->{$a} = $value; | |||
} | |||
} | |||
elsif($einfo->{attributes}->{$ns}->{$a} eq 'Bool') { | |||
if(defined($value) && $value =~ m{^\s*(yes|true|on|1)\s*$}i) { | |||
$attributes->{$a} = 1; | |||
} | |||
else { | |||
$attributes->{$a} = 0; | |||
} | |||
} | } | ||
} | $xmlns = $context -> get_prefix($xmlns); | ||
} | for my $a (keys %{$einfo->{attributes}->{$ns}||{}}) { | ||
|
my $value = $node -> {attrs} -> {$xmlns} -> {$a}; | ||
my $content; | if($einfo->{attributes}->{$ns}->{$a} eq 'Str') { | ||
if($einfo -> {uses_content} && $node -> hasChildNodes() ) { | if(defined $value) { | ||
$content = sub { | $attributes->{$a} = $value; | ||
my $collector = []; | |||
my $child = $node -> firstChild; | |||
while($child) { | |||
my $r = $context -> process_node( $child ); | |||
if(ref $r) { | |||
if(is_ArrayRef($r)) { | |||
push @$collector, @$r; | |||
} | } | ||
elsif($r -> isa('XML::LibXML::Node')) { | } | ||
push @$collector, $r; | elsif($einfo->{attributes}->{$ns}->{$a} eq 'Bool') { | ||
if(defined($value)) { | |||
$attributes->{$a} = map { | |||
m{^\s*(yes|true|on|1)\s*$} ? 1 : 0 | |||
} @{$value}; | |||
} | } | ||
} | } | ||
$child = $child -> nextSibling; | |||
} | } | ||
return $collector; | |||
}; | |||
} | |||
|
|||
my $impl = $einfo -> {impl}; | |||
my $r; | |||
if(ref $impl) { | |||
$r = $einfo -> {impl} -> ($self, $context, $attributes, $content); | |||
} | |||
else { | |||
$r = $self -> $impl($context, $attributes, $content); | |||
} | |||
|
|||
if(defined($r) && !ref $r) { # $r is a string | |||
if(!defined($einfo -> {escape_text}) || $einfo->{escape_text}) { | |||
$r = $node -> ownerDocument -> createTextNode( $r ); | |||
} | |||
elsif($r ne '') { | |||
$r =~ s{&}{&}g; | |||
$r = XML::LibXML -> new( | |||
expand_entities => 0, | |||
xinclude => 0, | |||
load_ext_dtd => 0, | |||
) -> parse_balanced_chunk( $r ); | |||
} | } | ||
else { |
|
||
$r = undef; | my $content; | ||
if($einfo -> {uses_content} && @{$node -> {children}||[]}) { | |||
$content = sub { | |||
$context -> process_node( $node -> {children} || [''] ); | |||
}; | |||
} | } | ||
|
|||
my $impl = $einfo -> {impl}; | |||
$self -> $impl($context, $attributes, $content); | |||
} | } | ||
$r; | |||
} | } | ||
|
|||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.