<commit_before>package EnsEMBL::Web::Tools::DHTMLmerge;

use strict;
use warnings;

use Digest::MD5 qw(md5_hex);
use JavaScript::Minifier;
use CSS::Minifier;

use EnsEMBL::Web::Tools::MethodMaker(copy => ['merge_all','_merge_all2']);

sub merge_all {
  my ($sd) = @_;
  $sd->{'_storage'}{'SOLR_JS_NAME'} = merge_solr_js($sd);
  $sd->{'_storage'}{'SOLR_CSS_NAME'} = merge_solr_css($sd);
  _merge_all2($sd);
}

sub merge_solr_js {
  my ($sd) = @_;

  my $dir = [split 'modules',__FILE__]->[0] . "htdocs";
  my ($contents) = get_contents('js',$dir,'solr');
  my $root_dir = $sd->ENSEMBL_SERVERROOT;
  my $compression_dir = "$root_dir/utils/compression/";
  my $filename = md5_hex($contents);
  my $minified = "$root_dir/htdocs/minified/$filename.js";
  my $tmp = "$minified.tmp";

  return $filename if(-e $minified);
  open(OUT,">$tmp") or die "Cannot open $tmp for writing";
  print OUT '(function($,window,document,undefined){'.$contents.'})(jQuery,this,document)';
  close OUT;
  system($sd->ENSEMBL_JAVA,"-jar","$compression_dir/compiler.jar",
         "--js",$tmp,"--js_output_file",$minified,
         "--compilation_level","SIMPLE_OPTIMIZATIONS",
         "--warning_level","QUIET");
  unlink $tmp;
  unless(-s $minified) {
    open(OUT,">$minified") or die "Cannot open $minified for writing";
    print OUT JavaScript::Minifier::minify(input => $contents);
    close OUT;
  }
  return $filename;
}

sub merge_solr_css {
  my ($sd) = @_;

  my $dir = [split 'modules',__FILE__]->[0] . "htdocs";
  my ($contents) = get_contents('css',$dir,'solr');
  my $root_dir = $sd->ENSEMBL_SERVERROOT;
  my $filename = md5_hex($contents);

  my $seqmark = $sd->colour('sequence_markup') || {};
  my %colours = (%{$sd->ENSEMBL_STYLE || {}}, map { $_ => $seqmark->{$_}{'default'} } keys %$seqmark);
  $colours{$_} =~ s/^([0-9A-F]{6})$/#$1/i for keys %colours;
  $contents =~ s/\[\[(\w+)\]\]/$colours{$1}||"\/* ARG MISSING DEFINITION $1 *\/"/eg; 
  my $minified = "$root_dir/htdocs/minified/$filename.css";
  unless(-s $minified) {
    open(OUT,">$minified") or die "Cannot open $minified for writing";
    print OUT CSS::Minifier::minify(input => $contents);
    close OUT;
  } 
  return $filename;
}

1;

<commit_msg>revert ds23's accidental commit<commit_after>package EnsEMBL::Web::Tools::DHTMLmerge;

use strict;

sub merge_plugin_solr {
  my $species_defs = shift;
  my $dir          = [split 'modules', __FILE__]->[0] . 'htdocs';
  
  $species_defs->{'_storage'}{'SOLR_JS_NAME'}  = merge($species_defs, 'js',  $dir, 'solr');
  $species_defs->{'_storage'}{'SOLR_CSS_NAME'} = merge($species_defs, 'css', $dir, 'solr');
}

1;

{'fraction_non_alphanumeric': 0.21183206106870228, 'fraction_numerical': 0.007251908396946565, 'mean_word_length': 4.722707423580786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '360557', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1011, 'n_words': 187}