<commit_before># -* coding: UTF-8 -*-
###
  # Himle Server -- http://himle.org/
  #
  # Copyright (C) 2009 <NAME>
  #
  # This file is part of Himle Server.
  #
  # Himle Server is free software: you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # Himle server is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  #
  ###

=begin
 IndexHtmlPlugin is the servlet plugin that is responsible for initializing the "boot-strap page".
 
 It just loads, caches and sends the page for now.
=end
class IndexHtmlPlugin < ServletPlugin
  
  def match( uri, method )
    if uri == '/' and method == :get
      return true
    else
      return false
    end
  end
  
  def score
    return 1000 # allows overriding with anything with a score below 0
  end
  
  def set_deps( deps )
    @deps = deps
    render_index_html
  end
  
  def open
    @client_rev = $FILECACHE.client_rev
    @deps = []
    @index_html_src = file_read( 'tmpl/index.html' )
    @loading_gif_id = $TICKETSERVE.serve_rsrc( file_read( 'img/loading.gif' ), 'image/gif' )
    render_index_html
  end
  
  def render_index_html
    
    @index_html = @index_html_src.clone
    
    @index_html.gsub!('__DEFAULT_TITLE__',$config[:indexhtml_conf][:loading_title])
    @index_html.gsub!('__LOADING_GIF_ID__',@loading_gif_id)
    @index_html.gsub!('__CLIENT_REV__',@client_rev)
    
    deps_src = ''
    @deps.each do |dep|
      deps_src += %{<script src="#{dep}" type="text/javascript"></script>}
    end
    @index_html.gsub!('__SCRIPT_DEPS__',deps_src)
    
    @content_size = @index_html.size
  end
  
  def debug_rescan
    
    puts "re-buffering client files"
    begin
      $FILECACHE.check_scan
      @client_rev = $FILECACHE.client_rev<commit_msg>uses ASCII-8BIT for reading the gif (binary mode) for ruby 1.9<commit_after># -* coding: UTF-8 -*-
###
  # Himle Server -- http://himle.org/
  #
  # Copyright (C) 2009 <NAME>
  #
  # This file is part of Himle Server.
  #
  # Himle Server is free software: you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # Himle server is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  #
  ###

=begin
 IndexHtmlPlugin is the servlet plugin that is responsible for initializing the "boot-strap page".
 
 It just loads, caches and sends the page for now.
=end
class IndexHtmlPlugin < ServletPlugin
  
  def match( uri, method )
    if uri == '/' and method == :get
      return true
    else
      return false
    end
  end
  
  def score
    return 1000 # allows overriding with anything with a score below 0
  end
  
  def set_deps( deps )
    @deps = deps
    render_index_html
  end
  
  def open
    @client_rev = $FILECACHE.client_rev
    @deps = []
    @index_html_src = file_read( 'tmpl/index.html' )
    loading_gif_h = File.open( File.join( @path, 'img/loading.gif' ), 'rb' )
    loading_gif = loading_gif_h.read
    loading_gif_h.close
    @loading_gif_id = $TICKETSERVE.serve_rsrc( loading_gif, 'image/gif' )
    render_index_html
  end
  
  def render_index_html
    
    @index_html = @index_html_src.clone
    
    @index_html.gsub!('__DEFAULT_TITLE__',$config[:indexhtml_conf][:loading_title])
    @index_html.gsub!('__LOADING_GIF_ID__',@loading_gif_id)
    @index_html.gsub!('__CLIENT_REV__',@client_rev)
    
    deps_src = ''
    @deps.each do |dep|
      deps_src += %{<script src="#{dep}" type="text/javascript"></script>}
    end
    @index_html.gsub!('__SCRIPT_DEPS__',deps_src)
    
    @content_size = @index_html.size
  end
  
  def debug_rescan
    
    puts "re-buffering client files"
    begin
      $FILECACHE.check_scan
      @client_rev = $FILECACHE.client_rev
{'fraction_non_alphanumeric': 0.09609544468546638, 'fraction_numerical': 0.005422993492407809, 'mean_word_length': 3.066137566137566, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5385700', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1521, 'n_words': 469}