<commit_before>require 'rubygems'
require 'sinatra/base'
require 'json'
require 'nokogiri'
require 'fileutils'

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

begin
  require 'RMagick'
rescue LoadError
  $stderr.puts 'image sizing disabled - install rmagick'
end

begin
  require 'pdfkit'
rescue LoadError
  $stderr.puts 'pdf generation disabled - install pdfkit'
end

begin
  require 'rdiscount'
rescue LoadError
  require 'bluecloth'
  Object.send(:remove_const,:Markdown)
  Markdown = BlueCloth
end
require 'pp'

class ShowOff < Sinatra::Application

  Version = VERSION = '0.5.0'

  attr_reader :cached_image_size

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

  def initialize(app=nil)
    super(app)
    showoff_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
    if Dir.pwd == showoff_dir
      options.pres_dir = "#{showoff_dir}/example"
      @root_path = "."
    else
      options.pres_dir ||= Dir.pwd
      @root_path = ".."
    end
    options.pres_dir = File.expand_path(options.pres_dir)
    if (options.pres_file)
      puts "Using #{options.pres_file}"
      ShowOffUtils.presentation_config_file = options.pres_file
    end
    puts "Serving presentation from #{options.pres_dir}"
    @cached_image_size = {}
    @pres_name = options.pres_dir.split('/').pop
    require_ruby_files
  end

  def require_ruby_files
    Dir.glob("#{options.pres_dir}/*.rb").map { |path| require path }
  end

  helpers do
    def load_section_files(section)
      section = File.join(options.pres_dir, section)
      files = Dir.glob("#{section}/**/*").sort
      pp files
      files
    end

    def css_files
      Dir.glob("#{options.pres_dir}/*.css").map { |path| File.basename(path) }
    end

    def js_files
      Dir.glob("#{options.pres_dir}/*.js").map { |path| File.basename(path) }
    end


    def preshow_files
      Dir.glob("#{options.pres_dir}/_preshow/*").map { |path| File.basename(path) }.to_json
    end

    # todo: move more behavior into this class
    class Slide
      attr_reader :classes, :text
      def initialize classes = ""
        @classes = ["content"] + classes.strip.split
        @text = ""
      end
      def <<(s)
        @text << s
        @text << "\n"
      end
      def empty?
        @text.strip == ""
      end
    end


    def process_markdown(name, content, static=false, pdf=false)

      # if there are no !SLIDE markers, then make every H1 define a new slide
      unless content =~ /^\<?!SLIDE/m
        content = content.gsub(/^# /m, "<!SLIDE>\n# ")
      end<commit_msg>bugfix in new slide code<commit_after>require 'rubygems'
require 'sinatra/base'
require 'json'
require 'nokogiri'
require 'fileutils'

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

begin
  require 'RMagick'
rescue LoadError
  $stderr.puts 'image sizing disabled - install rmagick'
end

begin
  require 'pdfkit'
rescue LoadError
  $stderr.puts 'pdf generation disabled - install pdfkit'
end

begin
  require 'rdiscount'
rescue LoadError
  require 'bluecloth'
  Object.send(:remove_const,:Markdown)
  Markdown = BlueCloth
end
require 'pp'

class ShowOff < Sinatra::Application

  Version = VERSION = '0.5.0'

  attr_reader :cached_image_size

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

  def initialize(app=nil)
    super(app)
    showoff_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
    if Dir.pwd == showoff_dir
      options.pres_dir = "#{showoff_dir}/example"
      @root_path = "."
    else
      options.pres_dir ||= Dir.pwd
      @root_path = ".."
    end
    options.pres_dir = File.expand_path(options.pres_dir)
    if (options.pres_file)
      puts "Using #{options.pres_file}"
      ShowOffUtils.presentation_config_file = options.pres_file
    end
    puts "Serving presentation from #{options.pres_dir}"
    @cached_image_size = {}
    @pres_name = options.pres_dir.split('/').pop
    require_ruby_files
  end

  def require_ruby_files
    Dir.glob("#{options.pres_dir}/*.rb").map { |path| require path }
  end

  helpers do
    def load_section_files(section)
      section = File.join(options.pres_dir, section)
      files = Dir.glob("#{section}/**/*").sort
      pp files
      files
    end

    def css_files
      Dir.glob("#{options.pres_dir}/*.css").map { |path| File.basename(path) }
    end

    def js_files
      Dir.glob("#{options.pres_dir}/*.js").map { |path| File.basename(path) }
    end


    def preshow_files
      Dir.glob("#{options.pres_dir}/_preshow/*").map { |path| File.basename(path) }.to_json
    end

    # todo: move more behavior into this class
    class Slide
      attr_reader :classes, :text
      def initialize classes = ""
        @classes = ["content"] + classes.strip.chomp('>').split
        @text = ""
      end
      def <<(s)
        @text << s
        @text << "\n"
      end
      def empty?
        @text.strip == ""
      end
    end


    def process_markdown(name, content, static=false, pdf=false)

      # if there are no !SLIDE markers, then make every H1 define a new slide
      unless content =~ /^\<?!SLIDE/m
        content = content.gsub(/^# /m, "<!SLIDE>\n# ")
      end
{'fraction_non_alphanumeric': 0.1342557965594615, 'fraction_numerical': 0.0014958863126402393, 'mean_word_length': 2.9388807069219443, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 6, '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': '6386237', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1784, 'n_words': 409}