@color: #1a150d;
body {
- background: @background;
- color: @color;
+ background: @background;
+ color: @color;
}
#site-header h1 {
text-align: center;
}
+article h1 {
+
+}
\ No newline at end of file
--- /dev/null
+package Newslash::Model::Stories;
+use base qw(Newslash::Model::Base);
+
+use Data::Dumper;
+use Mojo::Log;
+
+#========================================================================
+
+=head2 latest(\%options)
+
+get latest stories.
+
+=over 4
+
+=item Parameters
+
+=over 4
+
+=item \%options
+
+options for query.
+
+$options->{show_future}: when 1, return feature stories. default is 0.
+$options->{limit}: number of stories. default is 10.
+
+=back
+
+=item Return value
+
+ARRAY of story contents
+
+=back
+
+=cut
+
+sub latest {
+ my ($self, $options) = @_;
+ $options ||= {};
+
+ my $show_future = $options->{show_future} || 0;
+ my $limit = $options->{limit} || 10;
+
+ my $where_clause = 'WHERE stories.time <= NOW()';;
+ if ($show_future) {
+ $where_clause = '';
+ }
+
+ my $dbh = $self->connect_db;
+ my $sql = <<"EOSQL";
+SELECT *
+ FROM stories INNER JOIN story_text ON stories.stoid = story_text.stoid
+ $where_clause
+ ORDER BY time DESC
+ LIMIT ?
+EOSQL
+
+ my $sth = $dbh->prepare($sql);
+
+ $sth->execute($limit);
+ my $rs = $sth->fetchall_arrayref(+{});
+
+ $sth->finish;
+ $dbh->disconnect();
+
+ if (@$rs == 0) {
+ return [];
+ }
+
+ return $rs;
+}
+
+1;
use Mojo::Base 'Mojolicious';
use Newslash::Model::Users;
+use Newslash::Model::Stories;
# This method will run once at server start
sub startup {
# add Model
$app->helper(users => sub { state $users = Newslash::Model::Users->new });
+ $app->helper(stories => sub { state $stories = Newslash::Model::Stories->new });
# Documentation browser under "/perldoc"
$app->plugin('PODRenderer');
my $c = shift;
my $user = $c->session('user');
- $c->render(user => $user);
+ my $stories = $c->stories->latest;
+ $c->render(user => $user, stories => $stories);
}
1;
<!DOCTYPE html>
<html>
<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>[% title %]</title>
- <link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css" />
+ <link rel="stylesheet" type="text/css" href="[% NS.css_path('bootstrap'); %]" />
<script src="/jquery/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js" ></script>
<link rel="stylesheet" type="text/css" media="screen, projection" href="[% NS.css_path('main'); %]" />
[% WRAPPER common/layout %]
+<div class="index">
+ [%- FOREACH story IN stories -%]
+ <article>
+ <header>
+ <h1>[% story.title %]</h1>
+ <div class="property">
+ ストーリー by [% story.submitter %]
+ [% story.time %]
+ [% story.dept %] 部門より
+ </div>
+ </header>
+ <div class="body">[% story.introtext %]</div>
+ <footer>
+ <div class="link-to-story">記事を読む</div>
+ <div class="tag-bar">
+ <ul class="tags">
+ <li>tag1</li>
+ <li>tag2</li>
+ </ul>
+ </div>
+ </footer>
+ </article>
+ [%- END -%]
+</div><!-- .index -->
[% END %]