Created
March 8, 2013 14:31
-
-
Save mix3/5116797 to your computer and use it in GitHub Desktop.
Plack::App::Directoryで(gif|png|jpe?g)を展開するだけ ついでにswfもswfobject.jsで展開してみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Plack::App::Directory::ImageView; | |
use parent qw(Plack::App::Directory); | |
sub serve_path { | |
my($self, $env, $dir, $fullpath) = @_; | |
my $ret = $self->SUPER::serve_path($env, $dir, $fullpath); | |
return $ret if (ref($ret->[2]) eq 'Plack::Util::IOWithPath'); | |
$ret->[2][0] =~ s!</head>!<script type="text/javascript" src="http://swfobject.googlecode.com/svn/trunk/swfobject/swfobject.js"></script>\n</head>!g; | |
$ret->[2][0] =~ s!<a href='(.+?)'>(.+?)\.(gif|png|jpe?g)</a>!<a href='\1'><img src='\1' /></a><br />\2\.\3!g; | |
$ret->[2][0] =~ s!<a href='(.+?)'>(.+?)\.(swf)</a>!<a href='\1'><div id="\2"><script type="text/javascript">swfobject.embedSWF("\2\.\3", "\2", "320", "240", "9.0.0", "#ffffff");</script></div></a><br />\2\.\3!g; | |
$ret; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment