diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-09-17 23:50:22 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-09-18 11:34:55 -0500 |
commit | 7f0ab9818534c6720aff98d10eb6e55aa63dbeee (patch) | |
tree | ca483c234279eb3570b7f0172c248a5238d09808 | |
parent | a3ac0614071f5935f3c6754fbc2e498bddc9d692 (diff) | |
download | tozt.net-7f0ab9818534c6720aff98d10eb6e55aa63dbeee.tar.gz tozt.net-7f0ab9818534c6720aff98d10eb6e55aa63dbeee.zip |
basic sketch of the site rendering code
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | bin/preview | 30 | ||||
-rw-r--r-- | bin/render | 10 | ||||
-rw-r--r-- | dist.ini | 7 | ||||
-rw-r--r-- | lib/Tozt.pm | 86 | ||||
-rw-r--r-- | root/static/style.css | 84 | ||||
-rw-r--r-- | root/template/index.tt | 50 | ||||
-rw-r--r-- | root/template/wrapper.tt | 31 |
8 files changed, 299 insertions, 0 deletions
@@ -11,3 +11,4 @@ MANIFEST.bak *.sw[po] .build Tozt-* +site diff --git a/bin/preview b/bin/preview new file mode 100644 index 0000000..aebeaa3 --- /dev/null +++ b/bin/preview @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +use Plack::App::Directory; +use Plack::Builder; +use Plack::Request; +use Plack::Response; +use Plack::Runner; + +my $site_root = 'site'; +my $dir_app = Plack::App::Directory->new(root => $site_root)->to_app; +my $app = sub { + my ($env) = @_; + my $req = Plack::Request->new($env); + if (-d ("$site_root" . $req->path)) { + my $resp = Plack::Response->new(302); + my $path = $req->path; + $path .= '/' unless $path =~ m:/$:; + $resp->location("${path}index.html"); + return $resp->finalize; + } + else { + return $dir_app->($env); + } +}; + +my $runner = Plack::Runner->new; +$runner->parse_options(@ARGV); +$runner->run($app); diff --git a/bin/render b/bin/render new file mode 100644 index 0000000..859c5a1 --- /dev/null +++ b/bin/render @@ -0,0 +1,10 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use lib 'lib'; + +use Tozt; + +my $site = Tozt->new; +$site->render_all; +$site->update_static; @@ -7,3 +7,10 @@ copyright_holder = Jesse Luehrs dist = Tozt [Prereq] +File::Copy::Recursive = 0 +Moose = 0 +MooseX::Types::Path::Class = 0 +namespace::autoclean = 0 +Path::Class = 0 +Plack = 0 +Template = 0 diff --git a/lib/Tozt.pm b/lib/Tozt.pm index e69de29..e8034b8 100644 --- a/lib/Tozt.pm +++ b/lib/Tozt.pm @@ -0,0 +1,86 @@ +package Tozt; +use Moose; +use MooseX::Types::Path::Class qw(Dir); +use namespace::autoclean; + +use File::Copy::Recursive qw(rcopy); +use Path::Class (); +use Template; + +has output_dir => ( + is => 'ro', + isa => Dir, + coerce => 1, + default => 'site', +); + +has template_dir => ( + is => 'ro', + isa => Dir, + coerce => 1, + default => 'root/template', +); + +has static_dir => ( + is => 'ro', + isa => Dir, + coerce => 1, + default => 'root/static', +); + +has templater => ( + is => 'ro', + isa => 'Template', + lazy => 1, + default => sub { + Template->new( + INCLUDE_PATH => shift->template_dir, + ); + }, +); + +sub pages { + my $self = shift; + map { substr($_->basename, 0, -3) } + grep { $_->isa('Path::Class::File') + && $_->basename =~ /\.tt$/ + && $_->basename ne 'wrapper.tt' } $self->template_dir->children; +} + +sub render_page { + my $self = shift; + my ($page) = @_; + my $contents = $self->template_dir->file("$page.tt")->slurp; + my $wrapper = <<WRAPPER; +[% WRAPPER wrapper.tt %] +$contents +[% END %] +WRAPPER + + mkdir $self->output_dir unless -d $self->output_dir; + $self->templater->process( + \$wrapper, + { page => $page }, + $self->output_dir->file("$page.html")->stringify, + ); +} + +sub render_all { + my $self = shift; + for my $page ($self->pages) { + print "Rendering $page...\n"; + $self->render_page($page); + } +} + +sub update_static { + my $self = shift; + for my $file ($self->static_dir->children) { + rcopy($file, $self->output_dir); + } +} + +__PACKAGE__->meta->make_immutable; +no Moose; + +1; diff --git a/root/static/style.css b/root/static/style.css new file mode 100644 index 0000000..6561432 --- /dev/null +++ b/root/static/style.css @@ -0,0 +1,84 @@ +body { + background-color: #345; + font-family: sans; + margin: 0 auto; + width: 600px; +} + +a:link { + color: #123; +} + +a:visited { + color: #153; +} + +.header { + border-bottom: 1px solid; + position: relative; +} + +.header .name { + float: left; + margin-top: 0px; + position: absolute; + bottom: 0px; + left: 0px; +} + +.header .name h1 { + margin-bottom: 0px; + padding-bottom: 0px; +} + +.gravatar { + float: right; + vertical-align: bottom; +} + +.clear { + clear: both; +} + +.nav { + text-align: center; +} + +.nav a:link { + text-decoration: none; +} + +.nav a:visited { + text-decoration: none; +} + +.nav ul { + font-weight: bold; + font-size: small; + margin-bottom: 0px; + padding-left: 0px; +} + +.nav li { + background-color: #8c8; + border: 1px solid black; + display: inline; + padding: 2px; + padding-bottom: 0px; +} + +.main_content { + background-color: #8c8; + border: 1px solid; + padding: 5px; +} + +.main_content > div { + border-bottom: 1px dotted; + padding-bottom: 16px; +} + +.main_content #contact { + border-bottom: 0px; + padding-bottom: 0px; +} diff --git a/root/template/index.tt b/root/template/index.tt new file mode 100644 index 0000000..e73d567 --- /dev/null +++ b/root/template/index.tt @@ -0,0 +1,50 @@ +<div id="work"> +<h4>work</h4> +I'm currently working for <a href="http://iinteractive.com/">Infinity Interactive</a>, and not seeking another position. My (out of date) resume can be found here: +<br /><br /> +<strong><a href="resume.pdf">My resume</a></strong> +<a href="resume.tex" style="font-size: smaller">(LaTeX source)</a> +<a href="resume.txt" style="font-size: smaller">plaintext version</a> +</div> +<div id="profiles"> +<h4>me elsewhere on the web</h4> +<ul> + <li><a href="http://github.com/doy">GitHub</a></li> + <li><a href="http://search.cpan.org/~doy/">CPAN</a></li> + <li><a href="http://last.fm/user/doyster">last.fm</a></li> + <li><a href="http://www.couchsurfing.org/people/doy/">CouchSurfing</a></li> + <li><a href="http://twitter.com/doyster">Twitter</a></li> + <li><a href="http://www.flixster.com/user/doyster">Flixster</a></li> + <li><a href="http://taeb.sartak.org/">TAEB</a></li> + <li><a href="http://interhack.us/">Interhack</a></li> + <li><a href="http://luaforge.net/users/doy/">LuaForge</a></li> + <li><a href="http://projecteuler.net/index.php?section=profile&profile=doy">Project Euler</a></li> + <li><a href="http://alt.org/nethack/plr.php?player=doy">nethack.alt.org</a></li> + <li><a href="http://crawl.akrasiac.org/scoring/players/doy.html">crawl.akrasiac.org</a></li> + <li><a href="http://www.kongregate.com/accounts/doyster">Kongregate</a></li> +</ul> +</div> +<div id="talks"> +<h4>talks i've given</h4> +<ul> + <li><a href="http://yapc2010.com/yn2010/talk/2646">YAPC::NA 2010 - Extending Moose</a> (<a href="/talks/extending_moose_yapc_na_2010/">slides</a>)</li> +</ul> +</div> +<div id="communities"> +<h4>other communities i'm a part of</h4> +<ul> + <li><a href="http://moose.perl.org/">Moose</a></li> + <li><a href="http://crawl.develz.org/">Crawl DevTeam</a></li> + <li><a href="http://source.bungie.org/">Aleph One</a></li> + <li><a href="http://fallingillini.org/">Falling Illini</a></li> + <li><a href="http://www.facebook.com/pages/Urbana-IL/Inline-Insomniacs/23716792059">Inline Insomniacs</a></li> +</ul> +</div> +<div id="contact"> +<h4>contact info</h4> +<ul> + <li>Email: doy at tozt dot net</li> + <li>AIM: thedoyster</li> + <li>IRC: doy (on irc.freenode.net and irc.perl.org)</li> +</ul> +</div> diff --git a/root/template/wrapper.tt b/root/template/wrapper.tt new file mode 100644 index 0000000..4b568c9 --- /dev/null +++ b/root/template/wrapper.tt @@ -0,0 +1,31 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> + <link rel="stylesheet" href="style.css" type="text/css" /> + <link rel="openid.server" href="http://www.livejournal.com/openid/server.bml" /> + <link rel="openid.delegate" href="http://doyster.livejournal.com/" /> + <title>Jesse Luehrs</title> +</head> +<body> +<div class="header"> + <div> + <div class="name"><h1>Jesse Luehrs</h1></div> + <img src="http://www.gravatar.com/avatar/dd9aceaf17982bc33972b3bb8701cd19.jpg" alt="gravatar" class="gravatar" /> + </div> + <div class="clear"></div> +</div> +<div class="nav"> +<ul> + <li><a href="#work">Work</a></li> + <li><a href="#profiles">Me elsewhere</a></li> + <li><a href="#talks">Talks</a></li> + <li><a href="#communities">Communities</a></li> + <li><a href="#contact">Contact</a></li> +</ul> +</div> +<div class="main_content"> +[% content %] +</div> +</body> +</html> |