Created
March 29, 2012 07:25
-
-
Save sshaw/2234505 to your computer and use it in GitHub Desktop.
Mojolicious Static Includes
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
sub register | |
{ | |
my ($self, $app) = @_; | |
$self->helper(include_static => sub { | |
my ($c, $path) = @_; | |
return unless $path; | |
if($path !~ m|^/|) { | |
my $root = first { -f "$_/$path" } @{$c->app->renderer->paths}; | |
$path = "$root/$path" if $root; | |
} | |
open my $in, '<', $path or die "can't include file '$path': $!"; | |
my $content = do { local $/; <$in> }; | |
return $content; | |
}); | |
} |
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
sub register | |
{ | |
my ($self, $app) = @_; | |
$self->helper(include_static => sub { | |
my ($c, $path) = @_; | |
return unless $path; | |
if($path !~ m|^/|) { | |
my $root = first { -f "$_/$path" } @{$c->app->renderer->paths}; | |
$path = "$root/$path" if $root; | |
} | |
open my $in, '<', $path or die "can't include file '$path': $!"; | |
my $content = do { local $/; <$in> }; | |
return $content; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment