Skip to content
This repository
Browse code

wip

  • Loading branch information...
commit bfc557db580c4898f39b24b9996768fcea9bca42 1 parent 40f079e
Matthew Somerville dracos authored

Showing 1 changed file with 25 additions and 3 deletions. Show diff stats Hide diff stats

  1. +25 3 perllib/FixMyStreet/App/View/Web.pm
28 perllib/FixMyStreet/App/View/Web.pm
@@ -4,6 +4,10 @@ use base 'Catalyst::View::TT';
4 4 use strict;
5 5 use warnings;
6 6
  7 +use Digest::MD5 qw(md5_hex);
  8 +use File::stat;
  9 +use List::Util qw(max);
  10 +
7 11 use mySociety::Locale;
8 12 use mySociety::Web qw(ent);
9 13 use FixMyStreet;
@@ -166,10 +170,28 @@ sub html_filter {
166 170
167 171 my %version_hash;
168 172 sub version {
169   - my ( $self, $c, $file ) = @_;
  173 + my ( $self, $c, $files ) = @_;
  174 + my $file = ref $files
  175 + ? '/js/compiled/' . md5_hex(join "\n", @$files) . '.js'
  176 + : $files;
170 177 unless ($version_hash{$file} && !FixMyStreet->config('STAGING_SITE')) {
171   - my $path = FixMyStreet->path_to('web', $file);
172   - $version_hash{$file} = ( stat( $path ) )[9];
  178 + my $mtime = 0;
  179 + if (ref $files) {
  180 + my $out = '';
  181 + for (@$files) {
  182 + my $path = FixMyStreet->path_to('web', $_);
  183 + $out .= $path->slurp . "\n";
  184 + $mtime = max $mtime, ( stat "$path" )->mtime;
  185 + }
  186 + mkdir FixMyStreet->path_to('web', 'js', 'compiled');
  187 + open(FP, '>', FixMyStreet->path_to('web', $file));
  188 + print FP $out;
  189 + close FP;
  190 + } else {
  191 + my $path = FixMyStreet->path_to('web', $file);
  192 + $mtime = ( stat "$path" )->mtime;
  193 + }
  194 + $version_hash{$file} = $mtime;
173 195 }
174 196 $version_hash{$file} ||= '';
175 197 return "$file?$version_hash{$file}";

0 comments on commit bfc557d

Please sign in to comment.
Something went wrong with that request. Please try again.