Fix bugs in adding other (CSS, sprite) files to bundles.
This commit is contained in:
parent
98a1e4c409
commit
57c427cb6d
4 changed files with 62 additions and 10 deletions
|
|
@ -255,7 +255,7 @@ EOTABLE
|
|||
my $dt = $session->datetime;
|
||||
my $url = $session->url;
|
||||
my $lastModifiedi18n = $i18n->get('last modified');
|
||||
foreach my $fileType (qw/jsFiles cssFiles/) {
|
||||
foreach my $fileType (qw/jsFiles cssFiles otherFiles/) {
|
||||
my $type = $fileType eq 'jsFiles' ? 'JS'
|
||||
: $fileType eq 'cssFiles' ? 'CSS'
|
||||
: 'OTHER';
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use WebGUI::International;
|
|||
use WebGUI::Utility;
|
||||
use URI;
|
||||
use Path::Class;
|
||||
use File::Basename;
|
||||
use CSS::Minifier::XS;
|
||||
use JavaScript::Minifier::XS;
|
||||
use LWP;
|
||||
|
|
@ -126,6 +127,36 @@ sub build {
|
|||
return (0, $errorMessages);
|
||||
}
|
||||
|
||||
##Copy files over
|
||||
my $otherFiles = $self->get('otherFiles');
|
||||
my $i18n = WebGUI::International->new($self->session, 'FilePump');
|
||||
OTHERFILE: foreach my $file (@{ $otherFiles }) {
|
||||
my $uri = $file->{uri};
|
||||
my $results = $self->fetch($uri);
|
||||
if (! $results->{content}) {
|
||||
$error = $uri;
|
||||
last OTHERFILE;
|
||||
}
|
||||
$file->{lastModified} = $results->{lastModified};
|
||||
my $uriPath = URI->new($uri)->opaque;
|
||||
$uriPath =~ tr{/}{/}s;
|
||||
my $filename = basename($uriPath);
|
||||
my $newFile = $newDir->file($filename);
|
||||
if (-e $newFile->stringify) {
|
||||
$error = join ' ', $uri, $i18n->get('duplicate file');
|
||||
last OTHERFILE;
|
||||
}
|
||||
my $fh = $newFile->open('>');
|
||||
$fh->binmode;
|
||||
print $fh $results->{content};
|
||||
close $fh;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
$newDir->rmtree;
|
||||
return (0, $error);
|
||||
}
|
||||
|
||||
##Minimize files, and write them out.
|
||||
|
||||
my $minimizedJS = JavaScript::Minifier::XS::minify($concatenatedJS);
|
||||
|
|
@ -147,9 +178,10 @@ sub build {
|
|||
##Delete the old build directory and update myself with the new data.
|
||||
$self->deleteBuild();
|
||||
$self->update({
|
||||
jsFiles => $jsFiles,
|
||||
cssFiles => $cssFiles,
|
||||
lastBuild => $newBuild,
|
||||
jsFiles => $jsFiles,
|
||||
cssFiles => $cssFiles,
|
||||
otherFiles => $otherFiles,
|
||||
lastBuild => $newBuild,
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,12 @@ our $I18N = {
|
|||
context => q|Edit bundle label.|
|
||||
},
|
||||
|
||||
'otherFiles' => {
|
||||
message => q|CSS Images|,
|
||||
lastUpdated => 1242681632,
|
||||
context => q|Edit bundle label.|
|
||||
},
|
||||
|
||||
'build this bundle' => {
|
||||
message => q|Build this bundle|,
|
||||
lastUpdated => 1242495011,
|
||||
|
|
@ -94,6 +100,12 @@ our $I18N = {
|
|||
context => q|Meaning that something has not been done at this time. Before the first time.|
|
||||
},
|
||||
|
||||
'duplicate file' => {
|
||||
message => q|A file with the same name already exists in the build directory.|,
|
||||
lastUpdated => 1242515308,
|
||||
context => q|Error message when building a new bundle.|
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue