} @_
}
+sub to_zoom_events {
+ my @events;
+ while(my $raw = shift) {
+ my $normalized_raw = ref $raw ? (ref $raw eq 'SCALAR' ? $$raw: "$raw") : $raw;
+ my @info = (
+ $normalized_raw =~m{
+ (
+ (?:[^<]*) < (?:
+ ( / )? ( [^/!<>\s"'=]+ )
+ ( (?:"[^"]*"|'[^']*'|[^"'<>])+? )?
+ |
+ (!-- .*? -- | ![^\-] .*? )
+ ) (\s*/\s*)? >
+ )
+ ([^<]*)
+ }x
+ );
+
+ my (
+ $whole,
+ $is_close,
+ $tag_name,
+ $attrs,
+ $comment_or_directive,
+ $in_place_close
+ ) = @info;
+
+ if($comment_or_directive) {
+ if($events[-1] && $events[-1]->{type} eq 'SPECIAL') {
+ $events[-1]->{raw} .= $normalized_raw;
+ } else {
+ push @events, { type => 'SPECIAL', raw => $normalized_raw };
+ }
+ } elsif(!scalar(@info)) {
+ if($events[-1] && $events[-1]->{type} eq 'TEXT') {
+ $events[-1]->{raw} .= $normalized_raw;
+ } elsif(ref $raw && ref $raw eq 'SCALAR' && $events[-1] && $events[-1]->{type} eq 'SPECIAL') {
+ $events[-1]->{raw} .= $normalized_raw;
+ } elsif(ref $raw && ref $raw eq 'SCALAR') {
+ push @events, { type => 'SPECIAL', raw => $normalized_raw };
+ }
+ else {
+ push @events, { type => 'TEXT', raw => $normalized_raw };
+ }
+ } else {
+ if($is_close) {
+ $tag_name =~ tr/A-Z/a-z/;
+ push @events, { type => 'CLOSE', name => $tag_name, raw => $normalized_raw};
+ } else {
+ $attrs = '' if !defined($attrs) or $attrs =~ /^ +$/;
+ push @events, {
+ type => 'OPEN',
+ name => $tag_name,
+ is_in_place_close => $in_place_close,
+ HTML::Zoom::Parser::BuiltIn::_hacky_attribute_parser($attrs),
+ raw_attrs => $attrs||'',
+ raw => $whole,
+ };
+ if($in_place_close) {
+ push @events, {
+ type => 'CLOSE',
+ name => $tag_name,
+ raw => '',
+ is_in_place_close => 1,
+ }
+ }
+ }
+ }
+ }
+ return @events;
+}
+
sub _find_tags { shift; @_ }
sub _find_target {
sub layout {
my (%data) = @_;
- \'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
+ \'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ',
+ \'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
<html>,
<head>,
<!-- here is a comment -->,
<img src="smilyface.png" alt="smiles" />,
<ul>,
<li>, <a href="/user">, "My Users", </li>,
- <li>, <a href="/user/$data{new_user_link}">, "Create New User", </li>,
+ <li>, <a href="/user/$data{new_user_link}">, "Create", "New User", </li>,
</ul>;
}
sub as_events {
my ($template, %data) = @_;
my @content = process_templates([$template, \&layout], %data);
- return [_convert_to_events(@content)];
- }
-
- sub _convert_to_events {
- map {
- my $raw = ref $_ ? (ref $_ eq 'SCALAR' ? $$_: "$_") : $_;
- my @info = (
- $raw =~m{
- (
- (?:[^<]*) < (?:
- ( / )? ( [^/!<>\s"'=]+ )
- ( (?:"[^"]*"|'[^']*'|[^"'<>])+? )?
- |
- (!-- .*? -- | ![^\-] .*? )
- ) (\s*/\s*)? >
- )
- ([^<]*)
- }x
- );
-
- my (
- $whole,
- $is_close,
- $tag_name,
- $attrs,
- $comment_or_directive,
- $in_place_close
- ) = @info;
-
- if($comment_or_directive) {
- +{ type => 'SPECIAL', raw => $raw };
- } elsif(!scalar(@info)) {
- +{ type => 'TEXT', raw => $raw };
- } else {
- if($is_close) {
- $tag_name =~ tr/A-Z/a-z/;
- +{ type => 'CLOSE', name => $tag_name, raw => $raw};
- } else {
- $attrs = '' if !defined($attrs) or $attrs =~ /^ +$/;
- +{
- type => 'OPEN',
- name => $tag_name,
- is_in_place_close => $in_place_close,
- HTML::Zoom::Parser::BuiltIn::_hacky_attribute_parser($attrs),
- raw_attrs => $attrs||'',
- raw => $whole,
- }, $in_place_close ?
- +{
- type => 'CLOSE',
- name => $tag_name,
- raw => '',
- is_in_place_close => 1,
- } :
- +();
- }
- }
- } @_;
+ return [HTML::Tags::to_zoom_events(@content)];
}
}
#use Data::Dump 'dump';
#warn dump $html;
#warn dump $zoom->to_events;
+#warn "======================";
#warn dump $events;
done_testing();