<commit_before>require 'rubygems'
require 'sinatra/base'
require 'json'
require 'nokogiri'
require 'fileutils'
require 'pathname'
require 'logger'
require 'htmlentities'
require 'sinatra-websocket'
require 'tempfile'

require 'i18n'
require 'i18n/backend/fallbacks'
require 'rack'
require 'rack/contrib'
require 'iso-639'

here = File.expand_path(File.dirname(__FILE__))
require "#{here}/showoff_utils"
require "#{here}/commandline_parser"
require "#{here}/keymap"

begin
  require 'pdfkit'
rescue LoadError
  # nop
end

require 'tilt'

class ShowOff < Sinatra::Application

  attr_reader :cached_image_size

  # Set up application variables

  set :views, File.dirname(__FILE__) + '/../views'
  set :public_folder, File.dirname(__FILE__) + '/../public'

  set :statsdir, "stats"
  set :viewstats, "viewstats.json"
  set :feedback, "feedback.json"
  set :forms, "forms.json"

  set :server, 'thin'
  set :sockets, []
  set :presenters, []

  set :verbose, false
  set :review,  false
  set :execute, false
  set :nocache, false

  set :pres_dir, '.'
  set :pres_file, 'showoff.json'
  set :page_size, "Letter"
  set :pres_template, nil
  set :showoff_config, {}
  set :encoding, nil
  set :url, nil

  # automatically select the translation based on the user's configured browser language
  use Rack::Locale

  configure do
    I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
    I18n.load_path += Dir[File.join(settings.root, '..', 'locales', '*.yml')]
    I18n.backend.load_translations
    I18n.enforce_available_locales = false
  end

  def initialize(app=nil)
    super(app)
    @logger = Logger.new(STDOUT)
    @logger.formatter = proc { |severity,datetime,progname,msg| "#{progname} #{msg}\n" }
    @logger.level = settings.verbose ? Logger::DEBUG : Logger::WARN

    @review  = settings.review
    @execute = settings.execute

    settings.pres_dir ||= Dir.pwd
    @root_path = "."

    # Load up the default keymap, then merge in any customizations
    keymapfile   = File.expand_path(File.join('~', '.showoff', 'keymap.json')) rescue nil
    @keymap      = Keymap.default
    @keymap.merge! JSON.parse(File.read(keymapfile)) rescue {}

    # map keys to the labels we're using
    @keycode_dictionary   = Keymap.keycodeDictionary
    @keycode_shifted_keys = Keymap.shiftedKeyDictionary

    settings.pres_dir = File.expand_path(settings.pres_dir)
    if (settings.pres_file and settings.pres_file != 'showoff.json')
      ShowOffUtils.presentation_config_file = settings.pres_file
    end

    # Load configuration for page size and template from the
    # configuration JSON file
    if File.exist?(ShowOffUtils.presentation_config_file)
      showoff_json = JSON.parse(File.read(ShowOffUtils.presentation_config_file))
      settings.showoff_config = showoff_json

      # Set options for encoding, template and page size
      settings.encoding      = showoff_json["encoding"]  || 'UTF-8'<commit_msg>let's put diagnostic infos out on stderr<commit_after>require 'rubygems'
require 'sinatra/base'
require 'json'
require 'nokogiri'
require 'fileutils'
require 'pathname'
require 'logger'
require 'htmlentities'
require 'sinatra-websocket'
require 'tempfile'

require 'i18n'
require 'i18n/backend/fallbacks'
require 'rack'
require 'rack/contrib'
require 'iso-639'

here = File.expand_path(File.dirname(__FILE__))
require "#{here}/showoff_utils"
require "#{here}/commandline_parser"
require "#{here}/keymap"

begin
  require 'pdfkit'
rescue LoadError
  # nop
end

require 'tilt'

class ShowOff < Sinatra::Application

  attr_reader :cached_image_size

  # Set up application variables

  set :views, File.dirname(__FILE__) + '/../views'
  set :public_folder, File.dirname(__FILE__) + '/../public'

  set :statsdir, "stats"
  set :viewstats, "viewstats.json"
  set :feedback, "feedback.json"
  set :forms, "forms.json"

  set :server, 'thin'
  set :sockets, []
  set :presenters, []

  set :verbose, false
  set :review,  false
  set :execute, false
  set :nocache, false

  set :pres_dir, '.'
  set :pres_file, 'showoff.json'
  set :page_size, "Letter"
  set :pres_template, nil
  set :showoff_config, {}
  set :encoding, nil
  set :url, nil

  # automatically select the translation based on the user's configured browser language
  use Rack::Locale

  configure do
    I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
    I18n.load_path += Dir[File.join(settings.root, '..', 'locales', '*.yml')]
    I18n.backend.load_translations
    I18n.enforce_available_locales = false
  end

  def initialize(app=nil)
    super(app)
    @logger = Logger.new(STDERR)
    @logger.formatter = proc { |severity,datetime,progname,msg| "#{progname} #{msg}\n" }
    @logger.level = settings.verbose ? Logger::DEBUG : Logger::WARN

    @review  = settings.review
    @execute = settings.execute

    settings.pres_dir ||= Dir.pwd
    @root_path = "."

    # Load up the default keymap, then merge in any customizations
    keymapfile   = File.expand_path(File.join('~', '.showoff', 'keymap.json')) rescue nil
    @keymap      = Keymap.default
    @keymap.merge! JSON.parse(File.read(keymapfile)) rescue {}

    # map keys to the labels we're using
    @keycode_dictionary   = Keymap.keycodeDictionary
    @keycode_shifted_keys = Keymap.shiftedKeyDictionary

    settings.pres_dir = File.expand_path(settings.pres_dir)
    if (settings.pres_file and settings.pres_file != 'showoff.json')
      ShowOffUtils.presentation_config_file = settings.pres_file
    end

    # Load configuration for page size and template from the
    # configuration JSON file
    if File.exist?(ShowOffUtils.presentation_config_file)
      showoff_json = JSON.parse(File.read(ShowOffUtils.presentation_config_file))
      settings.showoff_config = showoff_json

      # Set options for encoding, template and page size
      settings.encoding      = showoff_json["encoding"]  || 'UTF-8'
{'fraction_non_alphanumeric': 0.11881693013768485, 'fraction_numerical': 0.006119326874043855, 'mean_word_length': 4.1120764552562985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3774468', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1915, 'n_words': 467}