App-CatalystStarter-Bloated
view release on metacpan or search on metacpan
lib/App/CatalystStarter/Bloated.pm view on Meta::CPAN
=item *
If using a dbi:Pg dsn, looks in your ~/.pgpass to find usernames
and passwords and even intelligently completes your dsn if you are
missing hostname and or port.
=item *
Sets up a TT wrapper based on a HTML5 template intializr.com and
points its css, js images and fonts to /static
=back
=head1 INTERFACE
=head2 run
The function that does it all.
=head1 DIAGNOSTICS
lib/App/CatalystStarter/Bloated/Initializr.pm view on Meta::CPAN
sub deploy {
_initialize();
_require_az;
my $dir = shift;
_setup_index();
_move_images();
_move_css_js_fonts();
$az->extractTree( "initializr", $dir );
l->info( "HTML5: template unzipped to catalyst root" );
}
sub _initialize_from_cache {
l->debug("Getting template from cache");
_set_az_from_cache();
}
sub _initalize_over_http {
lib/App/CatalystStarter/Bloated/Initializr.pm view on Meta::CPAN
s{(?:\./)?$d/(.*)}{[% c.uri_for(QUOTEHERE/static/$d/$1QUOTEHERE) %]};
$element->attr($key => $new_val);
# print "=> '$new_val'";
}
# print "\n";
}
});
l->debug("HTML5: references to img/ css/ js/ and fonts/ changed to static/*");
(my $new_index_content = "$dom") =~ s/QUOTEHERE/"/g;
## this won't be handled because it's not an html element
## attribute, and we're not parsing javascript (yet?)
$new_index_content =~ s{\Qdocument.write('<script src="js/vendor/jquery-1.10.1.min.js">}
{document.write('<script src="[% c.uri_for("/static/js/vendor/jquery-1.10.1.min.js") %]">};
## replace it into the zip
my $index_member = _safely_search_one_member( qr/index\.html$/ );
lib/App/CatalystStarter/Bloated/Initializr.pm view on Meta::CPAN
for my $m (@img_members) {
(my $new_name = $m->fileName) =~ s|/img/|/static/images/|;
$m->fileName( $new_name );
}
l->debug(sprintf "HTML5: %d image(s) moved from img/ to images/",
scalar(@img_members) );
}
sub _move_css_js_fonts {
_require_az;
## change dir name from img/* to static/images/*
my @static_members = $az->membersMatching(qr(/(?:css|js|fonts)/));
if (not @static_members) {
carp "did not find any js/ or css/ files in zip, that cannot be right";
return;
}
for my $m (@static_members) {
(my $new_name = $m->fileName) =~ s{/(css|js|fonts)/}{/static/$1/};
$m->fileName( $new_name );
}
l->debug(sprintf "HTML5: %d css, js or fonts files moved to static/*",
scalar(@static_members) );
}
## Low level functions:
sub _az {
return $az;
}
sub _set_az_from_cache {
t/initializr/process_zip.t view on Meta::CPAN
lives_ok {App::CatalystStarter::Bloated::Initializr::_move_images()}
"changing img/ to images/ lives";
is( search_one( qr(^/img/), 1 ), undef, "no img/ members found in zip" );
## might be just an empty dir, so ">="
cmp_ok( az()->membersMatching( qr{/static/images/} ), ">=", 1,
"several */static/images/ found in archive" );
## change css and js to /static/(css|js)/ , and also fonts
note( "moves js/, css/ and fonts/ members to static/*" );
lives_ok {App::CatalystStarter::Bloated::Initializr::_move_css_js_fonts()}
"putting js and css and fonts under static/ lives";
## we know for sure that there should be more than just an empty dir, so '>'
cmp_ok( az()->membersMatching( qr{/static/css/} ), ">", 1,
"several */static/css members found in archive" );
cmp_ok( az()->membersMatching( qr{/static/js/} ), ">", 1,
"several */static/js members found in archive" );
cmp_ok( az()->membersMatching( qr{/static/fonts/} ), ">", 1,
"several */static/fonts members found in archive" );
done_testing;
( run in 0.872 second using v1.01-cache-2.11-cpan-5735350b133 )