Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statocles app gets generic #586

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 21 additions & 34 deletions lib/Statocles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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} };
Expand All @@ -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',
Expand All @@ -131,8 +140,15 @@ sub startup {
href => '/blog',
text => 'Blog',
},
{
href => '/other',
text => 'Other',
},
],
},
disqus => {
shortname => '',
}
},
} );

Expand All @@ -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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helped with the unit tests, if it's a clue to why the tests are broken

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Might be that the config_override in Test::Mojo doesn't work the way I assumed it did (which, I don't know why I assumed it would merge with the defaults, because the docs explicitly say it does not)...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It merges with the default when making a statocles.conf, which could be added to each each share directory. Providing a hash to Test::Mojo makes a new config.

my @theme_dirs = ref $theme eq 'ARRAY' ? @{ $theme } : $theme;
for my $theme_dir ( @theme_dirs ) {
# Theme may be a module and path instead
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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},
);
}
Expand Down Expand Up @@ -368,31 +380,6 @@ __DATA__
</footer>
</body>

@@ default.html.ep
%= content 'content_before'
<header>
<h1><%= $item->{title} %></h1>
% if ( $item->{date} ) {
<aside>
<time datetime="<%= strftime('%Y-%m-%d', $item->{date} ) %>">
Posted on <%= strftime('%Y-%m-%d', $item->{date} ) %>
</time>
</aside>
% }
% if ( $item->{author} ) {
<aside>
%= content author => begin
<span class="author">by <%= $item->{author} %></span>
% end
</aside>
% }
</header>
% my $sections = sectionize( $item->{html} );
% for my $i ( 0 .. $#$sections ) {
<section id="section-<%= $i + 1 %>"><%== $sections->[ $i ] %></section>
% }
%= content 'content_after'

@@ sitemap.xml.ep
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
Expand Down
112 changes: 40 additions & 72 deletions lib/Statocles/App/Blog.pm → lib/Statocles/App.pm
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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( '<page:num>' )->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 });

Expand Down Expand Up @@ -69,13 +62,13 @@ sub register {
: $route->get( ( $category->{route} // $category->{title} ) . '/<page:num>' )->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 });
Expand All @@ -93,58 +86,7 @@ sub category_links {

1;
__DATA__
@@ blog.html.ep
% content_for head => begin
<link rel="alternate" type="application/rss+xml" href="<%= url_for( page => 1, format => 'rss' ) %>"/>
<link rel="alternate" type="application/atom+xml" href="<%= url_for( page => 1, format => 'atom' ) %>"/>
% end
% for my $item ( @$items ) {
<article>
<header>
<h1><a href="<%= url_for( "/$item->{path}" ) %>"><%== $item->{title} %></a></h1>

<aside>
<time datetime="<%= strftime('%Y-%m-%d', $item->{date}) %>">
Posted on <%= strftime('%Y-%m-%d', $item->{date}) %>
</time>
% if ( $item->{author} ) {
<span class="author">
by <%= $item->{author} %>
</span>
% }
% if ( config->{data}{disqus}{shortname} ) {
<a data-disqus-identifier="<%= url_for( $item->{path} ) %>" href="<%= url_for( "/$item->{path}" ) %>#disqus_thread">0 comments</a>
% }
</aside>
</header>

% my $sections = sectionize( $item->{html} );
<section>
%== $sections->[ 0 ]
</section>

% if ( @$sections > 1 ) {
<p><a href="<%= url_for( "/$item->{path}" ) %>#section-2">Continue reading...</a></p>
% }

</article>
% }

%= include 'pager', label_prev => 'Newer', label_next => 'Older'

% if ( config->{data}{disqus}{shortname} ) {
<script type="text/javascript">
var disqus_shortname = '<%= config->{data}{disqus}{shortname} %>';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
% }

@@ 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 );
Expand Down Expand Up @@ -179,7 +121,7 @@ __DATA__
</rss>
% setlocale( LC_TIME, $current_locale );

@@ blog.atom.ep
@@ list.atom.ep
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id><%= url_for()->to_abs %></id>
Expand Down Expand Up @@ -219,3 +161,29 @@ __DATA__
</entry>
% }
</feed>

@@ _item-caption.html.ep
% if ( $item->{tags} ) {
<p class="tags">Tags:
% for my $tag ( @{$item->{tags}} ) {
<a href="<%= url_for( join ("/", $config->{apps}{blog}{route}, "tag/$tag") =~ s{//}{/}r) %>" rel="tag"><%== $tag %></a>
% }
</p>
% }
% if ( $item->{date} ) {
<aside>
<time datetime="<%= strftime('%Y-%m-%d', $item->{date} ) %>">
Posted on <%= strftime('%Y-%m-%d', $item->{date} ) %>
</time>
</aside>
% }
% if ( $item->{author} ) {
<aside>
%= content author => begin
<span class="author">by <%= $item->{author} %></span>
% end
</aside>
% }
% if ( $disqus ) {
<a data-disqus-identifier="<%= url_for( "/$item->{path}" ) %>" href="<%= url_for( "/$item->{path}" ) %>#disqus_thread">0 comments</a>
% }
82 changes: 0 additions & 82 deletions lib/Statocles/App/List.pm

This file was deleted.

Loading