[Jifty-commit] jifty branch, master, updated. 5ab8de1e66d832aa0a3c39d469abc319d223b912
Jifty commits
jifty-commit at lists.jifty.org
Thu Apr 8 03:48:53 EDT 2010
The branch, master has been updated
via 5ab8de1e66d832aa0a3c39d469abc319d223b912 (commit)
via a4b1b3fb3d07c6e5c42db38b2d414edeb6f0a66b (commit)
from 99425d042432180fa77cf383531c6f4fdf3e648d (commit)
Summary of changes:
Makefile.PL | 4 ++--
lib/Jifty/Handler.pm | 19 +++++++++++++++++--
lib/Jifty/Plugin.pm | 15 +++++++++++++++
lib/Jifty/Plugin/CompressedCSSandJS.pm | 31 +++++++++++++++----------------
4 files changed, 49 insertions(+), 20 deletions(-)
- Log -----------------------------------------------------------------
commit a4b1b3fb3d07c6e5c42db38b2d414edeb6f0a66b
Author: Chia-liang Kao <clkao at clkao.org>
Date: Thu Apr 8 15:38:46 2010 +0800
Construct psgi_app_static with apps provided by the jifty app and plugins.
diff --git a/lib/Jifty/Handler.pm b/lib/Jifty/Handler.pm
index 6b9e7b8..75e6703 100644
--- a/lib/Jifty/Handler.pm
+++ b/lib/Jifty/Handler.pm
@@ -123,14 +123,29 @@ content, including plugins.
sub psgi_app_static {
my $self = shift;
+ # XXX: this is no longer needed, however TestApp-Mason is having a
+ # static::handler-less config
my $view_handler = $self->view('Jifty::View::Static::Handler')
or return;;
require Plack::App::Cascade;
require Plack::App::File;
my $static = Plack::App::Cascade->new;
- $static->add( Plack::App::File->new(root => $_)->to_app)
- for $view_handler->roots;
+
+ my $app_class = Jifty->app_class;
+
+ $static->add( $app_class->psgi_app_static )
+ if $app_class->can('psgi_app_static');
+
+ $static->add( Plack::App::File->new
+ ( root => Jifty->config->framework('Web')->{StaticRoot} )->to_app );
+
+ for ( grep { defined $_ } map { $_->psgi_app_static } Jifty->plugins ) {
+ $static->add( $_ );
+ }
+
+ $static->add( Plack::App::File->new
+ ( root => Jifty->config->framework('Web')->{DefaultStaticRoot} )->to_app );
# the buffering and unsetting of psgi.streaming is to vivify the
# responded res from the $static cascade app.
diff --git a/lib/Jifty/Plugin.pm b/lib/Jifty/Plugin.pm
index 2f85483..cb0b7d1 100644
--- a/lib/Jifty/Plugin.pm
+++ b/lib/Jifty/Plugin.pm
@@ -299,4 +299,19 @@ sub wrap {
return $app;
}
+=head2 psgi_app_static
+
+Returns a PSGI-$app that serves the static content of the plugin if
+any. The default is a <Plack::App::File> app with root set to
+plugin's C<static_root>
+
+=cut
+
+sub psgi_app_static {
+ my $self = shift;
+ my $static_root = $self->static_root;
+ return unless -d $static_root && -r $static_root;
+ Plack::App::File->new(root => $static_root)->to_app
+}
+
1;
commit 5ab8de1e66d832aa0a3c39d469abc319d223b912
Author: Chia-liang Kao <clkao at clkao.org>
Date: Thu Apr 8 15:40:35 2010 +0800
Use psgi_app_static to build compressed js, so users can provided other js files with their psgi_app_static.
diff --git a/Makefile.PL b/Makefile.PL
index 2a86aef..b11d5c8 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -61,7 +61,7 @@ requires('List::MoreUtils');
requires('Locale::Maketext::Extract' => '0.35');
requires('Locale::Maketext::Lexicon' => '0.77');
requires('Log::Log4perl' => '1.11'); # Log::Log4perl::Appender Log::Log4perl::Level
-requires('LWP::UserAgent'); # Net::HTTP LWP::Simple HTTP::Request::Common
+requires('LWP::UserAgent'); # Net::HTTP LWP::Simple HTTP::Request HTTP::Request::Common
requires('MIME::Types');
requires('Module::Pluggable' => '3.7'); # Module::Pluggable::Object
requires('Module::Pluggable::Object');
@@ -70,7 +70,7 @@ requires('Module::Refresh');
requires('Module::ScanDeps');
requires('Object::Declare' => '0.13');
requires('Params::Validate');
-requires('Plack' => '0.9910'); # Plack::Loader Plack::Test Plack::Util Plack::Builder Plack::Request Plack::Handler::FCGI
+requires('Plack' => '0.9910'); # Plack::Loader Plack::Test Plack::Util Plack::Builder Plack::Request Plack::Handler::FCGI HTTP::Message::PSGI
requires('Plack::Middleware::Deflater');
requires('Scalar::Defer' => '0.12');
requires('Shell::Command');
diff --git a/lib/Jifty/Plugin/CompressedCSSandJS.pm b/lib/Jifty/Plugin/CompressedCSSandJS.pm
index 9bdf414..f0c3f8b 100644
--- a/lib/Jifty/Plugin/CompressedCSSandJS.pm
+++ b/lib/Jifty/Plugin/CompressedCSSandJS.pm
@@ -6,6 +6,9 @@ use base 'Jifty::Plugin';
use IPC::Run3 'run3';
use IO::Handle ();
+use Plack::Util;
+use HTTP::Message::PSGI;
+use HTTP::Request;
=head1 NAME
@@ -197,26 +200,22 @@ sub _generate_javascript_nocache {
$self->log->debug("Generating JS...");
# for the file cascading logic
- my $static_handler = Jifty->handler->view('Jifty::View::Static::Handler');
my $js = "";
+ my $static_app = Jifty->handler->psgi_app_static;
+
for my $file ( @{ Jifty::Web->javascript_libs } ) {
next if $self->_js_is_skipped($file);
- my $include = $static_handler->file_path( File::Spec->catdir( 'js', $file ) );
-
- if ( defined $include ) {
- my $fh;
-
- if ( open $fh, '<', $include ) {
- local $_;
- $js .= "/* Including '$file' */\n\n";
- $js .= $_ while <$fh>;
- $js .= "\n/* End of '$file' */\n\n";
- } else {
- $js .= "\n/* Unable to open '$file': $! */\n";
- }
- } else {
- $js .= "\n/* Unable to find '$file' */\n";
+
+ my $res = Plack::Util::run_app
+ ( $static_app,
+ HTTP::Request->new(GET => "/js/$file")->to_psgi );
+ if ($res->[0] == 200) {
+ Plack::Util::foreach($res->[2], sub { $js .= $_[0] } );
+ }
+ else {
+ $self->log->error("Unable to include '$file': $res->[0]");
+ $js .= "\n/* Unable to include '$file': $res->[0] */\n";
}
}
-----------------------------------------------------------------------
More information about the Jifty-commit
mailing list