Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tx移動

  • Loading branch information...
commit 3f3a83e00cf776f1434d9fdd3c0fb28d6f7be8f5 1 parent f348b5d
Masahiro Nagano authored
Showing with 68 additions and 46 deletions.
  1. +10 −4 htdocs/static/css/default.css
  2. +58 −42 lib/Shirahata.pm
View
14 htdocs/static/css/default.css
@@ -70,11 +70,12 @@ fieldset {
/* page layout */
body {
text-align: center;
- background-color: #fff;
+ background-color: #333;
background-repeat: no-repeat;
background-image: -webkit-gradient( linear, left top, left bottom,
- from(rgba(33,33,33,1)), color-stop(0.8, rgba(255,255,255,1)), to(rgba(255,255,255,1)) );
- background-image: -moz-linear-gradient(top, rgba(33,33,33,1), rgba(255,2555,255,1) 90%, rgba(255,255,255,1));
+ from(rgba(33,33,33,1)), color-stop(0.2, rgba(255,255,255,1)), color-stop(0.5, rgba(51,51,51,1)), to(rgba(51,51,51,1)) );
+ background-image: -moz-linear-gradient(top, rgba(33,33,33,1), rgba(255,2555,255,1) 20%, rgba(51,51,51,1));
+ background-attachment: fixed;
height: 100%;
}
@@ -86,7 +87,7 @@ body {
max-width: 750px;
margin: 0px auto;
text-align: left;
- background-color:#fff;
+ background-color: rgba(255,255,255,0.7);
border-right: 1px solid #000;
border-left: 1px solid #000;
}
@@ -213,5 +214,10 @@ p.paging a {
pre.prettyprint {
border: none;
+ white-space: -moz-pre-wrap; /* Mozilla */
+ white-space: -pre-wrap; /* Opera 4-6 */
+ white-space: -o-pre-wrap; /* Opera 7 */
+ white-space: pre-wrap; /* CSS3 */
+ word-wrap: break-word; /* IE 5.5+ */
}
View
100 lib/Shirahata.pm
@@ -8,8 +8,6 @@ use base qw/Class::Accessor::Fast/;
use Plack::Builder;
use Router::Simple;
use Data::Section::Simple;
-use Text::Xslate qw(mark_raw);
-use HTML::FillInForm::Lite qw(fillinform);
use Path::Class;
use Net::IP;
@@ -86,40 +84,10 @@ sub psgi {
};
}
-sub build_template {
- my $self = shift;
- if ( !$self->{_templates_dir} ) {
- my $reader = Data::Section::Simple->new(ref $self);
- my $all = $reader->get_data_section;
- $self->{_template_dir} = File::Temp::tempdir( CLEANUP => 1 );
- for my $section ( keys %$all ) {
- my $fh = Path::Class::file( $self->{_template_dir}, $section )->openw;
- print $fh $all->{$section};
- }
- }
- $self->{_template_dir};
-}
sub build_app {
my $self = shift;
-
- my $tx = Text::Xslate->new(
- path => [ $self->build_template ],
- cache_dir => File::Temp::tempdir( CLEANUP => 1 ),
- cache => 2,
- input_layer => ':raw',
- function => {
- fillinform => sub {
- my $q = shift;
- return sub {
- my $fif = HTML::FillInForm::Lite->new(layer => ':raw');
- my $output = $fif->fill(\$_[0], $q);
- mark_raw( $output )
- };
- },
- },
- );
-
+
sub {
my $env = shift;
my $psgi_res;
@@ -129,7 +97,7 @@ sub build_app {
$s_res->content_type('text/html; charset=UTF-8');
my $c = Shirahata::Connection->new({
- _tx => $tx,
+ klass => ref $self,
req => $s_req,
res => $s_res,
stash => {},
@@ -161,20 +129,20 @@ sub build_app {
}
else {
# router not match
- $psgi_res = $c->res->not_found->finalize;
+ $psgi_res = $c->res->not_found('no route')->finalize;
}
$psgi_res;
};
}
-my $_ROUTER;
+my $_ROUTER={};
sub router {
- my $class = shift;
- if ( !$_ROUTER ) {
- $_ROUTER = Router::Simple->new();
+ my $class = ref $_[0] ? ref $_[0] : $_[0];
+ if ( !$_ROUTER->{$class} ) {
+ $_ROUTER->{$class} = Router::Simple->new();
}
- $_ROUTER;
+ $_ROUTER->{$class};
}
sub _any($$$;$) {
@@ -218,8 +186,12 @@ package Shirahata::Connection;
use strict;
use warnings;
use base qw/Class::Accessor::Fast/;
+use Text::Xslate qw(mark_raw);
+use HTML::FillInForm::Lite qw(fillinform);
+use Path::Class;
+use File::Temp;
-__PACKAGE__->mk_accessors(qw/req res stash args _tx/);
+__PACKAGE__->mk_accessors(qw/req res stash args klass/);
*request = \&req;
*response = \&res;
@@ -235,13 +207,57 @@ sub render {
stash => $self->stash,
%args,
);
- my $body = $self->_tx->render($file, \%vars);
+ my $body = $self->tx->render($file, \%vars);
$self->res->status( 200 );
$self->res->content_type('text/html; charset=UTF-8');
$self->res->body( $body );
$self->res;
}
+my $template_dir = {};
+sub build_template {
+ my $self = shift;
+ if ( ! $template_dir->{$self->klass} ) {
+ my $reader = Data::Section::Simple->new($self->klass);
+ my $all = $reader->get_data_section;
+ $template_dir->{$self->klass} = File::Temp::tempdir( CLEANUP => 1 );
+warn $template_dir->{$self->klass};
+ for my $section ( keys %$all ) {
+ my $fh = Path::Class::file( $template_dir->{$self->klass}, $section )->openw;
+ print $fh $all->{$section};
+ }
+ }
+ $template_dir->{$self->klass};
+}
+
+my $tx_cache = {};
+sub tx {
+ my $self = shift;
+
+ return $tx_cache->{$self->klass}
+ if $tx_cache->{$self->klass};
+
+ my $template_dir = $self->build_template;
+ $tx_cache->{$self->klass} = Text::Xslate->new(
+ path => [ $template_dir ],
+ cache_dir => $template_dir,
+ cache => 2,
+ input_layer => ':raw',
+ function => {
+ fillinform => sub {
+ my $q = shift;
+ return sub {
+ my $fif = HTML::FillInForm::Lite->new(layer => ':raw');
+ my $output = $fif->fill(\$_[0], $q);
+ mark_raw( $output )
+ };
+ },
+ },
+ );
+ $tx_cache->{$self->klass};
+}
+
+
1;
package Shirahata::Request;
Please sign in to comment.
Something went wrong with that request. Please try again.