Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add simple preview for layouts - moved to simpler parser for template…

… rendering
  • Loading branch information...
commit 44535dc29a3e1e91688abc3228a859ab967e6a66 1 parent 9763b49
@jgsmith authored
View
1  lib/OokOok.pm
@@ -19,6 +19,7 @@ use Catalyst::Runtime 5.80;
#-Debug
use Catalyst qw/
+ -Debug
ConfigLoader
Static::Simple
View
127 lib/OokOok/Base/TagLibrary.pm
@@ -1,103 +1,54 @@
-package OokOok::Base::TagLibrary;
+use MooseX::Declare;
-use Moose;
-use MooseX::Types::Moose qw( ArrayRef );
-use namespace::autoclean;
+class OokOok::Base::TagLibrary {
+ use MooseX::Types::Moose qw( ArrayRef );
-use XML::LibXML;
+ has c => ( is => 'rw', isa => 'Maybe[Object]',);
-has c => (
- is => 'rw',
- isa => 'Maybe[Object]',
-);
+ has date => ( is => 'rw',);
-has date => (
- is => 'rw',
-);
+ method process_node ($ctx, $node) {
+ # 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 {
- my($self, $ctx, $node) = @_;
+ return if !$einfo -> {impl}; # Nothing to do, so don't do anything
- # we want to pull out attributes and such based on needs of tag
- my $name = (split(":", $node -> nodeName, 2))[1];
- my $einfo = $self -> meta -> element( $name );
- return if !$einfo; # TODO: perhaps throw an error if not a defined element
-
- return if !$einfo -> {impl}; # Nothing to do, so don't do anything
-
- 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;
- }
+ my $context = $ctx -> localize;
+ my $xmlns;
+ my $attributes = {};
+ for my $ns (keys %{$einfo->{attributes}}) {
+ $xmlns = $ns;
+ if($ns eq '') {
+ $xmlns = $self -> meta -> namespace;
}
- }
- }
-
- my $content;
- if($einfo -> {uses_content} && $node -> hasChildNodes() ) {
- $content = sub {
- my $collector = [];
- my $child = $node -> firstChild;
- while($child) {
- my $r = $context -> process_node( $child );
- if(ref $r) {
- if(is_ArrayRef($r)) {
- push @$collector, @$r;
+ $xmlns = $context -> get_prefix($xmlns);
+ for my $a (keys %{$einfo->{attributes}->{$ns}||{}}) {
+ my $value = $node -> {attrs} -> {$xmlns} -> {$a};
+ if($einfo->{attributes}->{$ns}->{$a} eq 'Str') {
+ if(defined $value) {
+ $attributes->{$a} = $value;
}
- 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;
View
16 lib/OokOok/Controller/Admin/Theme.pm
@@ -198,6 +198,22 @@ controller OokOok::Controller::Admin::Theme
}
$ctx -> stash -> {template} = "/admin/theme/content/layout/edit";
}
+
+ final action theme_layout_preview as 'preview' {
+ my $context = OokOok::Template::Context -> new(
+ c => $ctx,
+ is_mockup => 1,
+ );
+ my $layout = $ctx -> stash -> {theme_layout};
+ $ctx -> stash -> {rendering} = $layout -> render($context);
+ $ctx -> stash -> {stylesheets} = [
+ map {
+ $ctx -> uri_for( "/ts/".$layout->theme->id."/style/$_" )
+ } $layout -> stylesheets
+ ];
+ $ctx -> stash -> {template} = "view/play.tt2";
+ $ctx -> forward( $ctx -> view('HTML') );
+ }
}
under theme_style_base {
View
33 lib/OokOok/Controller/Style.pm
@@ -16,6 +16,35 @@ controller OokOok::Controller::Style
c => $ctx,
);
}
+
+ action tbase as 'ts' {
+ $ctx -> stash -> {collection} = OokOok::Collection::Theme -> new(
+ c => $ctx,
+ );
+ }
+ }
+
+ under tbase {
+ action play_tbase ($uuid) as '' {
+ $self -> play_base($ctx, $uuid);
+ }
+ }
+
+ under play_tbase {
+ action tstyle_base ($uuid) as 'style' {
+ my $theme = $ctx -> stash -> {theme};
+ my $style = $theme -> style($uuid);
+
+ if(!$style) {
+ $ctx -> detach(qw/Controller::Root default/);
+ }
+
+ $ctx -> stash -> {resource} = $style;
+ }
+ }
+
+ under tstyle_base {
+ final action tstyle as '' isa REST;
}
under play_base {
@@ -41,4 +70,8 @@ controller OokOok::Controller::Style
$ctx -> stash -> {template} = 'style/style.tt2';
$ctx -> forward( $ctx -> view('HTML') );
}
+
+ method tstyle_GET ($ctx) {
+ $self -> style_GET($ctx);
+ }
}
View
15 lib/OokOok/Resource/Page.pm
@@ -153,20 +153,11 @@ sub can_DELETE {
sub stylesheets {
my($self) = @_;
- #my $theme = $self -> project -> theme;
- #return unless $theme;
- #my $layout_uuid = $self -> source_version -> layout;
- #my $layout = $theme -> layout( $layout_uuid );
my $layout = $self -> get_layout;
- my @stylesheets;
- while($layout) {
- my $s = $layout -> theme_style;
- if($s) {
- push @stylesheets, $s -> id;
- }
- $layout = $layout -> parent_layout;
+ if($layout) {
+ return $layout -> stylesheets;
}
- return reverse @stylesheets;
+ return;
}
sub get_layout {
View
38 lib/OokOok/Resource/ThemeLayout.pm
@@ -53,6 +53,20 @@ sub can_PUT {
$self -> theme -> can_PUT;
}
+sub stylesheets {
+ my($layout) = @_;
+
+ my @stylesheets;
+ while($layout) {
+ my $s = $layout -> theme_style;
+ if($s) {
+ push @stylesheets, $s -> id;
+ }
+ $layout = $layout -> parent_layout;
+ }
+ return reverse @stylesheets;
+}
+
#
# For now, we place the rendering stuff here since it depends on the
# Catalyst context, which means we want to avoid putting it in the
@@ -64,28 +78,22 @@ sub render {
my $layout = $self -> source_version;
if($layout) {
my $template = $layout -> layout;
- my $processor = OokOok::Template::Processor -> new(
- c => $self -> c,
- );
# now load in taglibs and prefixes
+
my %ns;
for my $lib ($self -> theme -> libraries) {
my $prefix = $lib -> prefix;
my $uin = "uin:uuid:" . $lib -> id;
$ns{$prefix} = $uin;
}
- my $div = "<div";
- for my $p (keys %ns) {
- $div .= " xmlns:$p='" . $ns{$p} . "'";
- }
- $div .= ">";
- my $doc = $processor -> parse($div . $template . "</div>");
- my $ret = $doc -> render($context);
- # we want to remove the outer div
- #print STDERR "Returned doc: [$ret]\n";
- $ret =~ s{\s*<div.*?>}{}s;
- $ret =~ s{</div>$}{}s;
- #print STDERR "After regex doc: [$ret]\n";
+
+ my $processor = OokOok::Template::Processor -> new(
+ c => $self -> c,
+ namespaces => \%ns,
+ );
+
+ my $ret = $processor -> parse($template) -> render($context);
+
# now worry about parent layout
if($self -> parent_layout) {
$context = $context -> localize;
View
223 lib/OokOok/Template/Context.pm
@@ -1,142 +1,133 @@
-package OokOok::Template::Context;
-
-use Moose;
-use MooseX::Types::Moose qw/CodeRef ArrayRef/;
-
-use XML::LibXML;
-use namespace::autoclean;
-
-has parent => (
- isa => 'Maybe[OokOok::Template::Context]',
- is => 'ro',
- predicate => 'has_parent',
-);
-
-has document => (
- isa => 'Maybe[OokOok::Template::Document]',
- is => 'ro',
- predicate => 'has_document',
-);
-
-has vars => (
- isa => 'HashRef',
- is => 'ro',
- default => sub { +{ } },
- lazy => 1,
-);
-
-has resources => (
- isa => 'HashRef',
- is => 'ro',
- default => sub { +{ } },
- lazy => 1,
-);
-
-sub localize {
- my($self) = @_;
-
- OokOok::Template::Context -> new(
- parent => $self,
- document => $self -> document,
- );
-}
+use MooseX::Declare;
-sub delocalize {
- my($self) = @_;
+class OokOok::Template::Context {
+ use MooseX::Types::Moose qw/CodeRef ArrayRef Str HashRef/;
- if($self -> has_parent) { return $self -> parent; }
- else { return $self; }
-}
+ has parent => (
+ isa => 'Maybe[OokOok::Template::Context]',
+ is => 'ro',
+ predicate => 'has_parent',
+ );
-sub get_resource {
- my($self, $key) = @_;
+ has document => (
+ isa => 'Maybe[OokOok::Template::Document]',
+ is => 'ro',
+ predicate => 'has_document',
+ );
- if(!exists($self -> resources -> {$key}) && $self -> parent) {
- $self -> parent -> get_resource($key);
- }
- else {
- $self -> resources -> {$key};
- }
-}
+ has namespaces => (
+ isa => 'HashRef',
+ is => 'ro',
+ default => sub { +{} },
+ );
-sub set_resource {
- my($self, $key, $value) = @_;
+ has vars => (
+ isa => 'HashRef',
+ is => 'ro',
+ default => sub { +{ } },
+ lazy => 1,
+ );
- $self -> resources -> {$key} = $value;
-}
+ has is_mockup => (
+ isa => 'Bool',
+ is => 'rw',
+ default => 0,
+ );
-sub set_var {
- my($self, $key, $val) = @_;
+ has resources => (
+ isa => 'HashRef',
+ is => 'ro',
+ default => sub { +{ } },
+ lazy => 1,
+ );
- $self -> vars -> {$key} = $val;
-}
+ method localize {
+ OokOok::Template::Context -> new(
+ parent => $self,
+ document => $self -> document,
+ is_mockup => $self -> is_mockup,
+ );
+ }
-sub get_var {
- my($self, $key) = @_;
+ method delocalize {
+ if($self -> has_parent) { return $self -> parent; }
+ else { return $self; }
+ }
- if(!exists($self -> vars -> {$key})) {
- if($self -> has_parent) {
- return $self -> parent -> get_var($key);
+ method get_resource ($key) {
+ if(!exists($self -> resources -> {$key}) && $self -> parent) {
+ $self -> parent -> get_resource($key);
+ }
+ else {
+ $self -> resources -> {$key};
}
}
- my $val = $self -> vars -> {$key};
- if(is_CodeRef($val)) {
- return $val->();
- }
- return $val;
-}
-sub has_var {
- my($self, $key) = @_;
+ method set_resource ($key, $value) {
+ $self -> resources -> {$key} = $value;
+ }
- return 1 if exists($self -> vars -> {$key});
+ method set_var ($key, $val) {
+ $self -> vars -> {$key} = $val;
+ }
- return 0 unless $self -> parent;
+ method get_var ($key) {
+ if(!exists($self -> vars -> {$key})) {
+ if($self -> has_parent) {
+ return $self -> parent -> get_var($key);
+ }
+ }
+ my $val = $self -> vars -> {$key};
+ if(is_CodeRef($val)) {
+ return $val->();
+ }
+ return $val;
+ }
- return $self -> parent -> has_var($key);
-}
+ method has_var ($key) {
+ return 1 if exists($self -> vars -> {$key});
-sub process_node {
- my($self, $node) = @_;
+ return 0 unless $self -> parent;
- # text nodes pass through
- my $nodeType = $node -> nodeType;
- if($nodeType == XML_TEXT_NODE
- || $nodeType == XML_COMMENT_NODE
- || $nodeType == XML_CDATA_SECTION_NODE
- ) {
- return $node -> cloneNode;
+ return $self -> parent -> has_var($key);
}
- elsif($node -> nodeType == XML_ELEMENT_NODE) {
- # we want to run the code associated with the node and replace the node
- # with the results
- my $local = $node -> localname;
- my $ns = $node -> namespaceURI;
- if($ns) {
- my $taglib = $self -> document -> taglibs -> {$ns};
- if($taglib) {
- return $taglib -> process_node($self, $node);
+
+ method get_namespace ($prefix) {
+ if(!exists($self -> namespaces -> {$prefix})) {
+ if($self -> has_parent) {
+ return $self -> parent -> get_namespace($prefix);
}
}
- else { # in HTML5
- # we need to descend
- my $collector = $node -> cloneNode;
- my $child = $node -> firstChild;
- while($child) {
- my $r = $self -> process_node( $child );
- if(ref $r) {
- if(is_ArrayRef($r)) {
- $collector -> appendChild( $_ ) for @$r;
- }
- elsif($r -> isa('XML::LibXML::Node')) {
- $collector -> appendChild( $r );
- }
+ return $self -> namespaces -> {$prefix};
+ }
+
+ method get_prefix ($ns) {
+ for my $p (keys %{$self -> namespaces}) {
+ return $p if $self -> namespaces -> {$p} eq $ns;
+ }
+ return $self -> parent -> get_prefix($ns)
+ if $self -> has_parent;
+ }
+
+ method process_node ($node) {
+ if(is_Str($node)) {
+ return $node;
+ }
+ elsif(is_HashRef($node)) {
+ my $local = $node->{local};
+ my $ns = $self -> get_namespace($node->{prefix});
+ if($ns) {
+ my $taglib = $self -> document -> taglibs -> {$ns};
+ if($taglib) {
+ return $taglib -> process_node($self, $node);
}
- $child = $child -> nextSibling;
}
- return $collector;
+ return ''; # unrecognized tag/namespace
+ }
+ elsif(is_ArrayRef($node)) {
+ return join '', map {
+ $self -> process_node($_)
+ } @{$node};
}
}
}
-
-1;
View
73 lib/OokOok/Template/Document.pm
@@ -1,56 +1,35 @@
-package OokOok::Template::Document;
+use MooseX::Declare;
-use Moose;
-use XML::LibXML;
-use OokOok::Template::Context;
+class OokOok::Template::Document {
-use namespace::autoclean;
+ use OokOok::Template::Context;
-has content => (
- is => 'ro',
- required => 1,
- isa => 'Object', # should be a parsed XML document
-);
-
-has taglibs => (
- is => 'ro',
- isa => 'HashRef',
- default => sub { +{ } },
-);
-
-sub render {
- my($self, $parent_context) = @_;
-
- # we want to run through the document looking for elements that are
- # provided by taglibs - we want to work from the top down - kind of like
- # an XSLT
-
- my $rendering = XML::LibXML::Document -> new;
- my $context = OokOok::Template::Context -> new(
- parent => $parent_context,
- document => $self,
+ has content => (
+ is => 'ro',
+ required => 1,
+ isa => 'ArrayRef',
);
- $rendering -> setDocumentElement(
- $context -> process_node(
- $self -> content -> documentElement
- )
+ has taglibs => (
+ is => 'ro',
+ isa => 'HashRef',
+ default => sub { +{ } },
);
-
- my $r = $rendering -> toStringHTML;
+ has namespaces => (
+ is => 'ro',
+ isa => 'HashRef',
+ default => sub { +{ } },
+ );
- #
- # we get rid of any <?xml...?> element at the beginning since we'll be
- # embedding this in an HTML document
- #
- $r =~ s{^\s*<\?xml\b.*?\?>\s*}{};
- #
- # now get rid of namespace declarations
- #$r =~ s{\s*xmlns:.*?="[^"]*"}{}g;
- #$r =~ s{\s*xmlns:.*?='[^']*'}{}g;
- $r =~ s{&amp;}{&}g;
- $r;
+ method render ($parent_context) {
+ OokOok::Template::Context -> new(
+ parent => $parent_context,
+ namespaces => $self -> namespaces,
+ document => $self,
+ is_mockup => $parent_context -> is_mockup
+ ) -> process_node(
+ $self -> content
+ );
+ }
}
-
-1;
View
89 lib/OokOok/Template/Parser.pm
@@ -0,0 +1,89 @@
+use MooseX::Declare;
+
+class OokOok::Template::Parser {
+
+ use Text::Balanced qw(extract_delimited);
+ use Data::Dumper ();
+
+ # we're essentially running through emitting events for things we
+ # think are special - not really doing a full XML type parse
+ # the result is a stack machine that produces the final content
+
+ has prefixes => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
+
+ has _buffer => ( is => 'rw', isa => 'Str', default => '' );
+
+ has _el_stack => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
+
+ method parse ($text) {
+ push @{$self -> _el_stack}, {
+ prefix => '',
+ local => '',
+ attrs => {},
+ children => []
+ };
+
+ my $prefix_regex = '(' . join('|', @{$self -> prefixes}) . '):';
+ $prefix_regex = qr{$prefix_regex};
+
+ while(length($text) && $text =~ m{</?$prefix_regex}s) {
+ if($text =~ m{\A(.*?)</?$prefix_regex}s) {
+ my $c = $1;
+ $self -> characters($c);
+ $text = substr($text, length($c));
+ }
+ if($text =~ m{\A<(/?)$prefix_regex(\S+)}s) {
+ my($ending, $prefix, $local) = ($1, $2, $3);
+ $text = substr($text, length($prefix) + length($local)
+ + ($ending ? 3 : 2));
+ if($ending) {
+ $self -> end_element( $prefix, $local );
+ }
+ else {
+ $self -> start_element( $prefix, $local );
+ # now parse attributes
+ while($text && $text =~ m{\A(\s*$prefix_regex(\S+)\s*=\s*)}s) {
+ my($ent, $aprefix, $attr) = ($1, $2, $3);
+ $text = substr($text, length($ent));
+ # now parse out balanced quotation
+ ($ent, $text) = extract_delimited($text, q{'"});
+ $ent = substr($ent, 1, length($ent)-2);
+ $self -> attribute( $aprefix, $attr, $ent );
+ }
+ if($text =~ s{\A\s*/>}{}s) {
+ $self -> end_element( $prefix, $local );
+ }
+ elsif(!($text =~ s{\A\s*>}{}s)) {
+ # error parsing
+ }
+ }
+ }
+ }
+ push @{$self -> _el_stack -> [0] -> {children}}, $text if length($text);
+ return $self -> _el_stack -> [0] -> {children};
+ }
+
+ method characters ($chars) {
+ $self -> _buffer( $self -> _buffer . $chars );
+ }
+
+ method start_element ($prefix, $el) {
+ push @{$self -> _el_stack -> [0] -> {children}}, $self -> _buffer;
+ $self -> _buffer('');
+ unshift @{$self -> _el_stack}, { prefix => $prefix, local => $el, attrs => {}, children => [] };
+ }
+
+ # we allow attributes to be specified multiple times
+ method attribute ($prefix, $name, $value) {
+ $self -> _el_stack -> [0] -> {attrs} -> {$prefix} -> {$name} ||= [];
+ push @{$self -> _el_stack -> [0] -> {attrs} -> {$prefix} -> {$name}}, $value;
+ }
+
+ method end_element ($prefix, $el) {
+ # we make sure the end matches
+ push @{$self -> _el_stack -> [0] -> {children}}, $self -> _buffer;
+ $self -> _buffer('');
+ my $info = shift @{$self -> _el_stack};
+ push @{$self -> _el_stack -> [0] -> {children}}, $info;
+ }
+}
View
120 lib/OokOok/Template/Processor.pm
@@ -1,80 +1,74 @@
-package OokOok::Template::Processor;
+use MooseX::Declare;
-use Moose;
+class OokOok::Template::Processor {
-use namespace::autoclean;
-use OokOok::Template::Document;
-use Carp;
+ use OokOok::Template::Document;
+ use OokOok::Template::Parser;
+ use Carp;
-use XML::LibXML;
-use Module::Load ();
+ use XML::LibXML;
+ use Module::Load ();
-has c => (
- is => 'rw',
- isa => 'Maybe[Object]',
-);
+ has c => ( is => 'rw', isa => 'Maybe[Object]', );
-has date => (
- is => 'rw',
- lazy => 1,
- default => sub { $_[0] -> c -> stash -> {date} },
-);
-
-has _taglibs => (
- is => 'rw',
- isa => 'HashRef',
- default => sub { +{ } }
-);
+ has date => ( is => 'rw', lazy => 1,
+ default => sub { $_[0] -> c -> stash -> {date} },
+ );
-sub BUILD {
- my($self) = @_;
+ has namespaces => ( is => 'rw', isa => 'HashRef', default => sub { +{} } );
- for my $taglib (keys %{$self -> c -> config -> {'OokOok::Template::TagLibs'} -> {module} || {}}) {
- $self -> register_taglib($taglib);
- }
-}
+ has _taglibs => ( is => 'rw', isa => 'HashRef', default => sub { +{ } });
-sub register_taglib {
- my($self, $taglib) = @_;
+ has _parser => ( is => 'rw', isa => 'OokOok::Template::Parser' );
- Module::Load::load $taglib;
+ method BUILD {
+ for my $taglib (keys %{$self -> c -> config -> {'OokOok::Template::TagLibs'} -> {module} || {}}) {
+ $self -> register_taglib($taglib);
+ }
- my $ns = $taglib -> meta -> namespace;
- if(!$ns) {
- # get NS from config
- $ns = $self -> c -> config -> {"OokOok::Template::TagLibs"} -> {module} -> {$taglib} -> {namespace};
- $taglib -> meta -> namespace($ns); # save it for later
- }
- if($ns) {
- $self -> _taglibs -> {$ns} = $taglib;
+ $self -> _parser(
+ OokOok::Template::Parser -> new(
+ prefixes => [ keys %{$self -> namespaces} ],
+ )
+ );
}
-}
-# we expect XML coming in - not free-form text
-sub parse {
- my($self, $content) = @_;
-
- my $dom = eval { XML::LibXML -> load_xml( string => $content ) };
-
- if($@) {
- croak "Unable to parse document ($@):\n$content\n\n";
+ method register_taglib ($taglib) {
+ Module::Load::load $taglib;
+
+ my $ns = $taglib -> meta -> namespace;
+ if(!$ns) {
+ # get NS from config
+ $ns = $self -> c -> config -> {"OokOok::Template::TagLibs"} -> {module} -> {$taglib} -> {namespace};
+ $taglib -> meta -> namespace($ns); # save it for later
+ }
+ if($ns) {
+ $self -> _taglibs -> {$ns} = $taglib;
+ }
}
- # we need to handle taglibs
- my %taglibs;
- foreach my $ns (keys %{$self -> _taglibs}) {
- $taglibs{$ns} = $self -> _taglibs -> {$ns} -> new(
- c => $self -> c,
- date => $self -> date,
+ method parse ($content) {
+ my $dom = eval { $self -> _parser -> parse($content) };
+
+ if($@) {
+ croak "Unable to parse document ($@):\n$content\n\n";
+ }
+
+ # we need to handle taglibs
+ my %taglibs;
+ foreach my $ns (keys %{$self -> _taglibs}) {
+ $taglibs{$ns} = $self -> _taglibs -> {$ns} -> new(
+ c => $self -> c,
+ date => $self -> date,
+ );
+ }
+
+ my $doc = OokOok::Template::Document -> new(
+ content => $dom,
+ taglibs => \%taglibs,
+ namespaces => $self -> namespaces,
);
- }
- my $doc = OokOok::Template::Document -> new(
- content => $dom,
- taglibs => \%taglibs,
- );
-
- $doc;
+ $doc;
+ }
}
-
-1;
View
12 lib/OokOok/Template/TagLibrary.pm
@@ -9,7 +9,7 @@ use OokOok::Base::TagLibrary;
use namespace::autoclean;
Moose::Exporter -> setup_import_methods(
- with_meta => [ 'namespace', 'element' ],
+ with_meta => [ 'element' ],
as_is => [ ],
also => 'Moose',
);
@@ -34,11 +34,11 @@ sub init_meta {
return $meta;
}
-sub namespace {
- my($meta, $ns) = @_;
-
- $meta -> namespace($ns);
-}
+#sub namespace {
+# my($meta, $ns) = @_;
+#
+# $meta -> namespace($ns);
+#}
sub element {
my($meta, $name, %options) = @_;
View
184 lib/OokOok/Template/TagLibrary/Core.pm
@@ -2,6 +2,165 @@ package OokOok::Template::TagLibrary::Core;
use OokOok::Template::TagLibrary;
+my $SAMPLE_CONTENT = <<'EOHTML';
+<p>The purpose of this HTML is to help determine what default settings are with CSS and to make sure that all possible HTML Elements are included in this HTML so as to not miss any possible Elements when designing a site.</p>
+<hr/>
+<h1>Heading 1</h1>
+<h2>Heading 2</h2>
+<h3>Heading 3</h3>
+<h4>Heading 4</h4>
+<h5>Heading 5</h5>
+<h6>Heading 6</h6>
+<hr/>
+<h2>Paragraph</h2>
+<p>Lorem ipsum dolor sit amet, <a href="#" title="test link">test link</a> adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</p>
+<p>Lorem ipsum dolor sit amet, <em>emphasis</em> consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</p>
+<hr/>
+<h2>List Types</h2>
+<h3>Definition List</h3>
+<dl>
+<dt>Definition List Title</dt>
+<dd>This is a definition list division.</dd>
+</dl>
+<h3>Ordered List</h3>
+<ol>
+<li>List Item 1</li>
+<li>List Item 2</li>
+<li>List Item 3</li>
+</ol>
+<h3>Unordered List</h3>
+<ul>
+<li>List Item 1</li>
+<li>List Item 2</li>
+<li>List Item 3</li>
+</ul>
+<hr/>
+<h2>Forms</h2>
+<fieldset>
+<legend>Legend</legend>
+<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</p>
+<form>
+<h2>Form Element</h2>
+<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.</p>
+<p><label for="text_field">Text Field:</label><br/>
+ <input type="text"/></p>
+<p><label for="text_area">Text Area:</label><br/>
+ <textarea></textarea></p>
+<p><label for="select_element">Select Element:</label></p>
+<select name="select_element">
+ <optgroup label="Option Group 1">
+<option value="1">Option 1</option>
+<option value="2">Option 2</option>
+<option value="3">Option 3</option>
+ </optgroup>
+ <optgroup label="Option Group 2">
+<option value="1">Option 1</option>
+<option value="2">Option 2</option>
+<option value="3">Option 3</option>
+ </optgroup><br/>
+ </select>
+
+<p><label for="radio_buttons">Radio Buttons:</label></p>
+<p> <input type="radio" class="radio" name="radio_button" value="radio_1"/> Radio 1<br/><br/>
+ <input type="radio" class="radio" name="radio_button" value="radio_2"/> Radio 2<br/><br/>
+ <input type="radio" class="radio" name="radio_button" value="radio_3"/> Radio 3<br/>
+ </p>
+<p><label for="checkboxes">Checkboxes:</label></p>
+<p> <input type="checkbox" class="checkbox" name="checkboxes" value="check_1"/> Radio 1<br/><br/>
+ <input type="checkbox" class="checkbox" name="checkboxes" value="check_2"/> Radio 2<br/><br/>
+ <input type="checkbox" class="checkbox" name="checkboxes" value="check_3"/> Radio 3<br/>
+ </p>
+<p><label for="password">Password:</label></p>
+<p> <input type="password" class="password" name="password"/>
+ </p>
+<p><label for="file">File Input:</label><br/>
+ <input type="file" class="file" name="file"/>
+ </p>
+<p><input class="button" type="reset" value="Clear"/> <input class="button" type="submit" value="Submit"/>
+ </p>
+</form>
+</fieldset>
+<hr/>
+<h2>Tables</h2>
+<table cellspacing="0" cellpadding="0">
+<tr>
+<th>Table Header 1</th>
+<th>Table Header 2</th>
+<th>Table Header 3</th>
+</tr>
+<tr>
+<td>Division 1</td>
+<td>Division 2</td>
+<td>Division 3</td>
+</tr>
+<tr class="even">
+<td>Division 1</td>
+<td>Division 2</td>
+<td>Division 3</td>
+</tr>
+<tr>
+<td>Division 1</td>
+<td>Division 2</td>
+<td>Division 3</td>
+</tr>
+</table>
+<hr/>
+<h2>Misc Stuff &#x2013; abbr, acronym, pre, code, sub, sup, etc.</h2>
+<p>Lorem <sup>superscript</sup> dolor <sub>subscript</sub> amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. <cite>cite</cite>. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. <acronym title="National Basketball Association">NBA</acronym> Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. <abbr title="Avenue">AVE</abbr></p>
+<pre>
+
+<p>
+
+Lorem ipsum dolor sit amet,
+
+ consectetuer adipiscing elit.
+
+ Nullam dignissim convallis est.
+
+ Quisque aliquam. Donec faucibus.
+
+Nunc iaculis suscipit dui.
+
+Nam sit amet sem.
+
+Aliquam libero nisi, imperdiet at,
+
+ tincidunt nec, gravida vehicula,
+
+ nisl.
+
+Praesent mattis, massa quis
+
+luctus fermentum, turpis mi
+
+volutpat justo, eu volutpat
+
+enim diam eget metus.
+
+Maecenas ornare tortor.
+
+Donec sed tellus eget sapien
+
+ fringilla nonummy.
+
+<acronym title="National Basketball Association">NBA</acronym>
+
+Mauris a ante. Suspendisse
+
+ quam sem, consequat at,
+
+commodo vitae, feugiat in,
+
+nunc. Morbi imperdiet augue
+
+ quis tellus.
+
+<abbr title="Avenue">AVE</abbr></p></pre>
+<blockquote><p>
+ &#x201C;This stylesheet is going to help so freaking much.&#x201D; <br/>-Blockquote
+</p></blockquote>
+EOHTML
+
# processes content
element 'snippet' => (
uses_content => 1, # we'll get the node for further processing
@@ -54,7 +213,14 @@ element 'unless-content' => (
sub element_snippet {
my($self, $context, $attr) = @_;
- my $name = $attr -> {"name"};
+ my $name = $attr -> {"name"} -> [0];
+
+ if($context -> is_mockup) {
+ return <<EOS;
+<h1>$name</h1>
+<p>Snippet with the name "$name"</p>
+EOS
+ }
# we want to render the snippet with the current context
my $project = $context -> get_resource("project");
@@ -81,7 +247,7 @@ sub element_snippet {
sub element_content {
my($self, $context, $attr) = @_;
- my $name = $attr -> {"part"};
+ my $name = $attr -> {"part"} -> [0];
if(!defined($name) || $name eq '') {
if($context -> has_var('content')) {
return $context -> get_var('content');
@@ -89,6 +255,14 @@ sub element_content {
$name = 'body';
}
+ if($context -> is_mockup) {
+ return <<EOP
+<h3>$name</h3>
+
+$SAMPLE_CONTENT
+EOP
+ }
+
my $inherit = $attr -> {'inherit'};
# we want to render the page part with the current context
@@ -115,8 +289,8 @@ sub element_content {
sub has_content_q {
my($self, $context, $attr) = @_;
- my $name = $attr -> {"part"};
- my $has_content;
+ my $name = $attr -> {"part"} -> [0];
+ my $has_content = $context -> is_mockup;
if(!defined($name) || $name eq '') {
if($context -> has_var('content')) {
$has_content = 1;
@@ -152,6 +326,7 @@ sub element_if_content {
if($self -> has_content_q($context, $attr)) {
return $yield->();
}
+ return '';
}
sub element_unless_content {
@@ -159,6 +334,7 @@ sub element_unless_content {
if(!$self -> has_content_q($context, $attr)) {
return $yield->();
}
+ return '';
}
1;
View
8 root/comps/admin/theme/content/layout/index.mc
@@ -31,6 +31,14 @@ $.layouts => sub { [] }
"Discard Changes"
) %>
% }}
+% $.IndexItemActions {{
+ <% $.IndexItemAction(
+ 0,
+ "/admin/theme/".$.theme_id."/layout/$layout_id/preview",
+ "screenshot",
+ "Preview"
+ ) %>
+% }}
% }}
% }
% }}
Please sign in to comment.
Something went wrong with that request. Please try again.