diff --git a/lib/OokOok.pm b/lib/OokOok.pm index 1fb21d8..98ac843 100644 --- a/lib/OokOok.pm +++ b/lib/OokOok.pm @@ -19,6 +19,7 @@ use Catalyst::Runtime 5.80; #-Debug use Catalyst qw/ + -Debug ConfigLoader Static::Simple diff --git a/lib/OokOok/Base/TagLibrary.pm b/lib/OokOok/Base/TagLibrary.pm index a4eb02d..9b85052 100644 --- a/lib/OokOok/Base/TagLibrary.pm +++ b/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; diff --git a/lib/OokOok/Controller/Admin/Theme.pm b/lib/OokOok/Controller/Admin/Theme.pm index 875a85a..a398f9c 100644 --- a/lib/OokOok/Controller/Admin/Theme.pm +++ b/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 { diff --git a/lib/OokOok/Controller/Style.pm b/lib/OokOok/Controller/Style.pm index 85a4868..1696bec 100644 --- a/lib/OokOok/Controller/Style.pm +++ b/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); + } } diff --git a/lib/OokOok/Resource/Page.pm b/lib/OokOok/Resource/Page.pm index 8f00e6e..79ef366 100644 --- a/lib/OokOok/Resource/Page.pm +++ b/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 { diff --git a/lib/OokOok/Resource/ThemeLayout.pm b/lib/OokOok/Resource/ThemeLayout.pm index 1af27dd..5a14ff3 100644 --- a/lib/OokOok/Resource/ThemeLayout.pm +++ b/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 = " parse($div . $template . ""); - my $ret = $doc -> render($context); - # we want to remove the outer div - #print STDERR "Returned doc: [$ret]\n"; - $ret =~ s{\s*}{}s; - $ret =~ s{$}{}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; diff --git a/lib/OokOok/Template/Context.pm b/lib/OokOok/Template/Context.pm index 81d7227..9c5989e 100644 --- a/lib/OokOok/Template/Context.pm +++ b/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; diff --git a/lib/OokOok/Template/Document.pm b/lib/OokOok/Template/Document.pm index c76cbc6..b52649d 100644 --- a/lib/OokOok/Template/Document.pm +++ b/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 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{&}{&}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; diff --git a/lib/OokOok/Template/Parser.pm b/lib/OokOok/Template/Parser.pm new file mode 100644 index 0000000..9327924 --- /dev/null +++ b/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{ 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; + } +} diff --git a/lib/OokOok/Template/Processor.pm b/lib/OokOok/Template/Processor.pm index f5787ea..a948ff8 100644 --- a/lib/OokOok/Template/Processor.pm +++ b/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; diff --git a/lib/OokOok/Template/TagLibrary.pm b/lib/OokOok/Template/TagLibrary.pm index 6267c66..1246e99 100644 --- a/lib/OokOok/Template/TagLibrary.pm +++ b/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) = @_; diff --git a/lib/OokOok/Template/TagLibrary/Core.pm b/lib/OokOok/Template/TagLibrary/Core.pm index e6101ad..d4e61ca 100644 --- a/lib/OokOok/Template/TagLibrary/Core.pm +++ b/lib/OokOok/Template/TagLibrary/Core.pm @@ -2,6 +2,165 @@ package OokOok::Template::TagLibrary::Core; use OokOok::Template::TagLibrary; +my $SAMPLE_CONTENT = <<'EOHTML'; +

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.

+
+

Heading 1

+

Heading 2

+

Heading 3

+

Heading 4

+
Heading 5
+
Heading 6
+
+

Paragraph

+

Lorem ipsum dolor sit amet, test link 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.

+

Lorem ipsum dolor sit amet, emphasis 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.

+
+

List Types

+

Definition List

+
+
Definition List Title
+
This is a definition list division.
+
+

Ordered List

+
    +
  1. List Item 1
  2. +
  3. List Item 2
  4. +
  5. List Item 3
  6. +
+

Unordered List

+ +
+

Forms

+
+Legend +

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.

+
+

Form Element

+

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.

+


+

+


+

+

+ + +

+

Radio 1

+ Radio 2

+ Radio 3
+

+

+

Radio 1

+ Radio 2

+ Radio 3
+

+

+

+

+


+ +

+

+

+
+
+
+

Tables

+ + + + + + + + + + + + + + + + + + + + + +
Table Header 1Table Header 2Table Header 3
Division 1Division 2Division 3
Division 1Division 2Division 3
Division 1Division 2Division 3
+
+

Misc Stuff – abbr, acronym, pre, code, sub, sup, etc.

+

Lorem superscript dolor subscript amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. 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. NBA Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. AVE

+
+
+

+ +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. + +NBA + +Mauris a ante. Suspendisse + + quam sem, consequat at, + +commodo vitae, feugiat in, + +nunc. Morbi imperdiet augue + + quis tellus. + +AVE

+

+ “This stylesheet is going to help so freaking much.”
-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 <$name +

Snippet with the name "$name"

+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 <$name + +$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; diff --git a/root/comps/admin/theme/content/layout/index.mc b/root/comps/admin/theme/content/layout/index.mc index 9121aaa..7e1913a 100644 --- a/root/comps/admin/theme/content/layout/index.mc +++ b/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" + ) %> +% }} % }} % } % }}