From 7f0ab9818534c6720aff98d10eb6e55aa63dbeee Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 17 Sep 2010 23:50:22 -0500 Subject: basic sketch of the site rendering code --- .gitignore | 1 + bin/preview | 30 +++++++++++++++++ bin/render | 10 ++++++ dist.ini | 7 ++++ lib/Tozt.pm | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ root/static/style.css | 84 ++++++++++++++++++++++++++++++++++++++++++++++ root/template/index.tt | 50 ++++++++++++++++++++++++++++ root/template/wrapper.tt | 31 +++++++++++++++++ 8 files changed, 299 insertions(+) create mode 100644 bin/preview create mode 100644 bin/render create mode 100644 root/static/style.css create mode 100644 root/template/index.tt create mode 100644 root/template/wrapper.tt diff --git a/.gitignore b/.gitignore index a90c767..a799609 100644 --- a/.gitignore +++ b/.gitignore @@ -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; diff --git a/dist.ini b/dist.ini index e1307ac..d080eca 100644 --- a/dist.ini +++ b/dist.ini @@ -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 = <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 @@ +
+

work

+I'm currently working for Infinity Interactive, and not seeking another position. My (out of date) resume can be found here: +

+My resume +(LaTeX source) +plaintext version +
+ +
+

talks i've given

+ +
+
+

other communities i'm a part of

+ +
+
+

contact info

+
    +
  • Email: doy at tozt dot net
  • +
  • AIM: thedoyster
  • +
  • IRC: doy (on irc.freenode.net and irc.perl.org)
  • +
+
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 @@ + + + + + + + + Jesse Luehrs + + +
+
+

Jesse Luehrs

+ gravatar +
+
+
+ +
+[% content %] +
+ + -- cgit v1.2.3-54-g00ecf