[Catalyst] Help with static and RegEx

Mike McKay mike at vdomck.org
Thu Jun 30 07:46:15 CEST 2005



David Storrs wrote:
> /foo/i  is equivalent to
> /(?i)foo/

Excellent. Attached is a patch that would include the following in the 
Catalyst::Plugin::Static documentation.

# use a Regex to match static content to be served
# want to match foo/image.JPG and image.jpg
# ignore case match anything after the last slash (or no slash) that is 
not a slash
sub images : Regex('(?i)^.*?/*([^/]*\.(jpg|png|gif|ico))$') {
         my ( $self, $c ) = @_;
         my ($file, $extension) = @{ $c->req->snippets };
         $c->req->path( "img/$file" );
         $c->serve_static;
}

Is this is right way to submit patches?

Mike
-------------- next part --------------
--- Static.pm	2005-06-30 06:26:37.000000000 +0100
+++ Static.new	2005-06-30 06:29:14.000000000 +0100
@@ -23,6 +23,17 @@
 
     # or specify explicitly if you know better
     $c->serve_static('text/css');
+    
+    # use a Regex to match static content to be served
+    # want to match foo/image.JPG and image.jpg
+    # ignore case match anything after the last slash (or no slash) that is not a slash
+    sub images : Regex('(?i)^.*?/*([^/]*\.(jpg|png|gif|ico))$') {          
+        my ( $self, $c ) = @_;                                             
+        my ($file, $extension) = @{ $c->req->snippets };
+        $c->req->path( "img/$file" );                                      
+        $c->serve_static;
+    }   
+
 
 =head1 DESCRIPTION
 


More information about the Catalyst mailing list