diff --git a/lib/Statocles.pm b/lib/Statocles.pm index aa22f17a..b81dcbce 100644 --- a/lib/Statocles.pm +++ b/lib/Statocles.pm @@ -92,6 +92,7 @@ use YAML qw( ); use Text::Markdown; use Time::Piece; use Mojo::Loader qw(load_class); +use Statocles::App; has moniker => 'statocles'; has deploy => sub { die q{"deploy" is required} }; @@ -115,6 +116,14 @@ sub startup { apps => { blog => { route => '/blog', + filter => { date => { '!=' => undef }, status => { '!=' => 'draft'}}, + order_by => { -desc => 'date' }, + }, + other => { + route => '/other', + filter => { -not_bool => 'date' }, + order_by => 'title', + categories => [], }, }, theme => '+Statocles/theme/default', @@ -131,8 +140,15 @@ sub startup { href => '/blog', text => 'Blog', }, + { + href => '/other', + text => 'Other', + }, ], }, + disqus => { + shortname => '', + } }, } ); @@ -155,8 +171,8 @@ sub startup { $app->plugin( Export => ); push @{$app->export->pages}, '/sitemap.xml', '/robots.txt'; $app->plugin( AutoReload => ); - - if ( my $theme = $app->config->{theme} ) { + do { + my $theme = $app->config->{theme} //= '+Statocles/theme/default'; my @theme_dirs = ref $theme eq 'ARRAY' ? @{ $theme } : $theme; for my $theme_dir ( @theme_dirs ) { # Theme may be a module and path instead @@ -173,7 +189,7 @@ sub startup { push @{$app->renderer->paths}, $theme_dir; push @{$app->static->paths}, $theme_dir; } - } + }; # Always fall back to the home dir for templates and static files to # allow for extra content @@ -269,11 +285,7 @@ sub startup { my %apps; for my $moniker ( sort keys %{ $app->config->{apps} } ) { my $conf = $app->config->{apps}{ $moniker }; - my $class = 'Statocles::App::' . ucfirst( $conf->{app} || $moniker ); - if ( my $e = load_class( $class ) ) { - die "Could not load class $class for app $moniker: $e"; - } - my $site_app = $class->new( moniker => $moniker, %$conf ); + my $site_app = Statocles::App->new( moniker => $moniker, %$conf ); $site_app->register( $app, $conf ); $apps{ $moniker } = $site_app; } @@ -289,8 +301,8 @@ sub startup { if ( my $page = $c->yancy->get( pages => $id ) ) { return $c->render( item => $page, - ( template => $page->{template} )x!!$page->{template}, ( layout => $page->{layout} )x!!$page->{layout}, + template => $page->{template} // 'page', title => $page->{title}, ); } @@ -368,31 +380,6 @@ __DATA__ -@@ default.html.ep -%= content 'content_before' -
-

<%= $item->{title} %>

- % if ( $item->{date} ) { - - % } - % if ( $item->{author} ) { - - % } -
-% my $sections = sectionize( $item->{html} ); -% for my $i ( 0 .. $#$sections ) { -
<%== $sections->[ $i ] %>
-% } -%= content 'content_after' - @@ sitemap.xml.ep diff --git a/lib/Statocles/App/Blog.pm b/lib/Statocles/App.pm similarity index 66% rename from lib/Statocles/App/Blog.pm rename to lib/Statocles/App.pm index 8cc96f4d..93e974ae 100644 --- a/lib/Statocles/App/Blog.pm +++ b/lib/Statocles/App.pm @@ -1,6 +1,5 @@ -package Statocles::App::Blog; -our $VERSION = '0.094'; -# ABSTRACT: A blog application +package Statocles::App; +our $VERSION = '2.000'; =head1 SYNOPSIS @@ -12,33 +11,27 @@ our $VERSION = '0.094'; use Mojo::Base 'Mojolicious::Plugin'; use Scalar::Util qw( blessed ); -use Statocles::App::List; # Contains default pager template -has moniker => 'blog'; +has moniker => ''; has categories => sub { [] }; -sub _routify { - my ( $app, $route ) = @_; - return unless $route; - return blessed $route ? $route : $app->routes->any( $route ); -} - sub register { my ( $self, $app, $conf ) = @_; - my $route = _routify( $app, delete $conf->{route} // $conf->{base_url} ); - my $filter = { %{ delete $conf->{filter} // {} }, date => { '!=' => undef }, status => { '!=' => 'draft'}}; - push @{$app->renderer->classes}, __PACKAGE__, 'Statocles::App::List'; + push @{$app->renderer->classes}, __PACKAGE__; + my $route = $app->routes->any( $conf->{route} ); + my $filter = delete $conf->{filter} // {}; + my $order_by = delete $conf->{order_by} // 'path'; my $index_route = $route->get( '' )->to( 'yancy#list', page => 1, - template => 'blog', + template => 'list', schema => 'pages', filter => $filter, - order_by => { -desc => 'date' }, + order_by => $order_by, %$conf, ); # Add the index page to the list of pages to export. The index page - # has links to all the blog posts and all the other pages, so that + # has links to feeds, all the blog posts, and all the other pages, so that # should export the entire blog. push @{ $app->export->pages }, $index_route->render({ page => 1 }); @@ -69,13 +62,13 @@ sub register { : $route->get( ( $category->{route} // $category->{title} ) . '/' )->to( 'yancy#list', page => 1, - template => 'blog', + template => 'list', schema => 'pages', filter => { %$filter, %{ $category->{filter} }, }, - order_by => { -desc => 'date' }, + order_by => $order_by, %$conf, ); push @{ $app->export->pages }, $category_route->render({ page => 1 }); @@ -93,58 +86,7 @@ sub category_links { 1; __DATA__ -@@ blog.html.ep -% content_for head => begin - - -% end -% for my $item ( @$items ) { - -% } - -%= include 'pager', label_prev => 'Newer', label_next => 'Older' - -% if ( config->{data}{disqus}{shortname} ) { - -% } - -@@ blog.rss.ep +@@ list.rss.ep %# RSS requires date/time in the 'C' locale as per RFC822. strftime() is one of %# the few things that actually cares about locale. % use POSIX qw( locale_h ); @@ -179,7 +121,7 @@ __DATA__ % setlocale( LC_TIME, $current_locale ); -@@ blog.atom.ep +@@ list.atom.ep <%= url_for()->to_abs %> @@ -219,3 +161,29 @@ __DATA__ % } + +@@ _item-caption.html.ep +% if ( $item->{tags} ) { +

Tags: + % for my $tag ( @{$item->{tags}} ) { + {apps}{blog}{route}, "tag/$tag") =~ s{//}{/}r) %>" rel="tag"><%== $tag %> + % } +

+% } +% if ( $item->{date} ) { + +% } +% if ( $item->{author} ) { + +% } +% if ( $disqus ) { + {path}" ) %>" href="<%= url_for( "/$item->{path}" ) %>#disqus_thread">0 comments +% } diff --git a/lib/Statocles/App/List.pm b/lib/Statocles/App/List.pm deleted file mode 100644 index 0bd0a1e5..00000000 --- a/lib/Statocles/App/List.pm +++ /dev/null @@ -1,82 +0,0 @@ -package Statocles::App::List; -our $VERSION = '0.094'; -# ABSTRACT: A list of pages - -=head1 SYNOPSIS - -=head1 DESCRIPTION - -=head1 SEE ALSO - -=cut - -use Mojo::Base 'Mojolicious::Plugin'; -use Scalar::Util qw( blessed ); - -has moniker => 'list'; - -sub _routify { - my ( $app, $route ) = @_; - return unless $route; - return blessed $route ? $route : $app->routes->any( $route ); -} - -sub register { - my ( $self, $app, $conf ) = @_; - my $route = _routify( $app, delete $conf->{route} // $conf->{base_url} ); - push @{$app->renderer->classes}, __PACKAGE__; - my $index_route = $route->get( '' )->to( - 'yancy#list', - page => 1, - template => 'list', - schema => 'pages', - order_by => 'title', - %$conf, - ); - # Add the index page to the list of pages to export. The index page - # has links to all the other pages, so that should export the entire set - push @{ $app->export->pages }, $index_route->render({ page => 1 }); -} - -1; -__DATA__ -@@ list.html.ep - - -%= include 'pager' - -@@ pager.html.ep - diff --git a/lib/Statocles/resources/theme/bootstrap/blog.html.ep b/lib/Statocles/resources/theme/bootstrap/blog.html.ep deleted file mode 100644 index 548178cd..00000000 --- a/lib/Statocles/resources/theme/bootstrap/blog.html.ep +++ /dev/null @@ -1,57 +0,0 @@ -% content_for head => begin - - -% end -% for my $item ( @$items ) { -
-
-

{path}" ) %>"><%== $item->{title} %>

- - % if ( $item->{tags} ) { -

Tags: - % for my $tag ( @{$item->{tags}} ) { - " rel="tag"><%== $tag %> - % } -

- % } - - -
- - % my $sections = sectionize( $item->{html} ); -
- %== $sections->[ 0 ] -
- - % if ( @$sections > 1 ) { -

{path}" ) %>#section-2">Continue reading...

- % } - -
-% } - -%= include 'pager', label_next => 'Older', label_prev => 'Newer' - -% if ( config->{data}{disqus}{shortname} ) { - -% } - diff --git a/lib/Statocles/resources/theme/bootstrap/list.html.ep b/lib/Statocles/resources/theme/bootstrap/list.html.ep new file mode 100644 index 00000000..8806944c --- /dev/null +++ b/lib/Statocles/resources/theme/bootstrap/list.html.ep @@ -0,0 +1,21 @@ +% content_for head => begin + + +% end +% for my $item ( @$items ) { + +% } + +%= include 'pager', label_next => 'Older', label_prev => 'Newer' diff --git a/lib/Statocles/resources/theme/bootstrap/page.html.ep b/lib/Statocles/resources/theme/bootstrap/page.html.ep new file mode 100644 index 00000000..62f88729 --- /dev/null +++ b/lib/Statocles/resources/theme/bootstrap/page.html.ep @@ -0,0 +1,20 @@ +
+

<%== $items->[0]->{title} %>

+ %= include '_item-caption', item => $item, disqus => config->{data}{disqus}{shortname} +
+% my $sections = sectionize( $items->[0]->{html} ); +% for my $i ( 0 .. $#$sections ) { +
<%== $sections->[ $i ] %>
+% } + +% if ( config->{data}{disqus}{shortname} ) { + +% } diff --git a/lib/Statocles/resources/theme/default/blog.html.ep b/lib/Statocles/resources/theme/default/blog.html.ep deleted file mode 100644 index 15956e7a..00000000 --- a/lib/Statocles/resources/theme/default/blog.html.ep +++ /dev/null @@ -1,57 +0,0 @@ -% content_for head => begin - - -% end -% for my $item ( @$items ) { -
-
-

{path}" ) %>"><%== $item->{title} %>

- - - % if ( $item->{tags} ) { -

Tags: - % for my $tag ( @{$item->{tags}} ) { - " rel="tag"><%== $tag %> - % } -

- % } -
- - % my $sections = sectionize( $item->{html} ); -
- %== $sections->[ 0 ] -
- - % if ( @$sections > 1 ) { -

{path}" ) %>#section-2">Continue reading...

- % } - -
-% } - -%= include 'pager', label_next => 'Older', label_prev => 'Newer' - -% if ( config->{data}{disqus}{shortname} ) { - -% } - diff --git a/lib/Statocles/resources/theme/default/list.html.ep b/lib/Statocles/resources/theme/default/list.html.ep new file mode 100644 index 00000000..8806944c --- /dev/null +++ b/lib/Statocles/resources/theme/default/list.html.ep @@ -0,0 +1,21 @@ +% content_for head => begin + + +% end +% for my $item ( @$items ) { + +% } + +%= include 'pager', label_next => 'Older', label_prev => 'Newer' diff --git a/lib/Statocles/resources/theme/default/page.html.ep b/lib/Statocles/resources/theme/default/page.html.ep new file mode 100644 index 00000000..868a1c5c --- /dev/null +++ b/lib/Statocles/resources/theme/default/page.html.ep @@ -0,0 +1,20 @@ +
+

<%== $item->{title} %>

+ %= include '_item-caption', item => $item, disqus => config->{data}{disqus}{shortname} +
+% my $sections = sectionize( $item->{html} ); +% for my $i ( 0 .. $#$sections ) { +
<%== $sections->[ $i ] %>
+% } + +% if ( config->{data}{disqus}{shortname} ) { + +% } diff --git a/t/app/blog.t b/t/app/blog.t index beaf3b74..56a28960 100644 --- a/t/app/blog.t +++ b/t/app/blog.t @@ -16,6 +16,7 @@ my $t = Test::Mojo->new( Statocles => { apps => { blog => { route => '/', + order_by => { -desc => 'date'}, limit => 3, }, }, diff --git a/t/app/list.t b/t/app/list.t index 7a060bd6..30c52f08 100644 --- a/t/app/list.t +++ b/t/app/list.t @@ -22,14 +22,14 @@ my $t = Test::Mojo->new( Statocles => { } ); $t->get_ok( '/' )->status_is( 200 ) - ->text_is( 'li:nth-child( 1 ) a', 'Alpha' ) + ->text_is( 'article:nth-child( 1 ) header h1 a', 'Alpha' ) ->or( sub { diag shift->tx->res->dom->at( 'ul' ) } ) - ->text_is( 'li:nth-child( 2 ) a', 'Bravo' ) + ->text_is( 'article:nth-child( 2 ) header h1 a', 'Bravo' ) ->or( sub { diag shift->tx->res->dom->at( 'ul' ) } ) ->element_exists( '.pager .next [rel=next][href=/2]', 'next button is enabled' ) ->element_exists( '.pager .prev button[disabled]', 'previous button is disabled' ) ->get_ok( '/2' )->status_is( 200 ) - ->text_is( 'li:nth-child( 1 ) a', 'Charlie' ) + ->text_is( 'article:nth-child( 1 ) header h1 a', 'Charlie' ) ->or( sub { diag shift->tx->res->dom->at( 'ul' ) } ) ->element_exists( '.pager .next button[disabled]', 'next button is disabled' ) ->element_exists( '.pager .prev [rel=prev][href=/]', 'previous button is enabled' )