<commit_before>class WikiMounter
  require 'rubygems'
  require 'gollum/app'

  def self.call(env)
    wikis_root = "wikis/"
    wiki_name = env["action_dispatch.request.path_parameters"][:wiki]
    wiki_path = wikis_root + wiki_name
    mount_path = "/wiki/" + wiki_name

    gollums ||= {}
    gollums[:wiki_name] ||= MapGollum.new(wiki_path, mount_path)
    gollums[:wiki_name].call(env)
  end

end


class MapGollum
  def initialize(base_path, mount_path)
    @mg = Rack::Builder.new do

      gollum_path = File.expand_path(base_path)
      wiki_options = { universal_toc: false,
                       live_preview: false,
                       template_dir: './lib/wiki_mounter/templates/'
                     }
      Precious::App.set(:gollum_path, gollum_path)
      Precious::App.set(:default_markup, :markdown)
      Precious::App.set(:wiki_options, wiki_options)

      map '/' do
        run Proc.new { [302, { 'Location' => "http://localhost:3000#{mount_path}" }, []] }
        # run Precious::App
      end

      map mount_path do
        run Precious::App
      end
    end
  end

  def call(env)
    @mg.call(env)
  end
end


# wikis_root = "wikis/"
# wiki_name = env["action_dispatch.request.path_parameters"][:wiki]
# wiki_path = wikis_root + wiki_name

# @@mount_point = "/wiki/" + wiki_name
# load Rails.root + 'lib/gollum/lib/gollum/frontend/app.rb'
# Precious::App.set(:gollum_path, wiki_path)
# Precious::App.set(:wiki_options, {})
# if env['warden'].user && env['warden'].user.wikis.include?(Wiki.find_by_name(wiki_name))
#   Precious::App.call(env)
# else<commit_msg>Set committer info to that of logged-in user<commit_after>class WikiMounter
  require 'rubygems'
  require 'gollum/app'

  def self.call(env)
    wikis_root = "wikis/"
    wiki_name = env["action_dispatch.request.path_parameters"][:wiki]
    wiki_path = wikis_root + wiki_name
    mount_path = "/wiki/" + wiki_name

    gollums ||= {}
    gollums[:wiki_name] ||= MapGollum.new(wiki_path, mount_path)
    gollums[:wiki_name].call(env)
  end

end


class MapGollum
  def initialize(base_path, mount_path)
    @mg = Rack::Builder.new do

      gollum_path = File.expand_path(base_path)
      wiki_options = { universal_toc: false,
                       live_preview: false,
                       template_dir: './lib/wiki_mounter/templates/'
                     }
      Precious::App.set(:gollum_path, gollum_path)
      Precious::App.set(:default_markup, :markdown)
      Precious::App.set(:wiki_options, wiki_options)

      map '/' do
        run Proc.new { [302, { 'Location' => "http://localhost:3000#{mount_path}" }, []] }
        # run Precious::App
      end

      map mount_path do
        run Precious::App
      end
    end
  end

  def call(env)
    @mg.call(env)
  end
end

class Precious::App
  before do
    session['gollum.author'] = {
      :name => "%s %s" % [env['warden'].user.first_name, env['warden'].user.last_name],
      :email => "%s" % env['warden'].user.email,
    }
  end
end


# wikis_root = "wikis/"
# wiki_name = env["action_dispatch.request.path_parameters"][:wiki]
# wiki_path = wikis_root + wiki_name

# @@mount_point = "/wiki/" + wiki_name
# load Rails.root + 'lib/gollum/lib/gollum/frontend/app.rb'
# Precious::App.set(:gollum_path, wiki_path)
# Precious::App.set(:wiki_options, {})
# if env['warden'].user && env['warden'].user.wikis.include?(Wiki.find_by_name(wiki_name))
#   Precious::App.call(env)
# else
{'fraction_non_alphanumeric': 0.14555490993608367, 'fraction_numerical': 0.004067402672864613, 'mean_word_length': 3.0745562130177513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7464844', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1231, 'n_words': 205}