<commit_before>require "yaml"
require "sinatra"
require "sinatra/base"

class ClientCMS < Sinatra::Base
  def self.add_project(p)
    @@project ||= {}
    @@project[p["name"]] = p
    @@project[p["name"]]["credentials"] = YAML.load_file(p["path"] + "/pwd")
    self
  end

  use Rack::Auth::Basic do |username, password|
    users = @@project.reduce({}) do |result, (_, data)|
      data["credentials"].each do |name, pwd|
        result[name] = pwd
      end
    end
    users[username] == password
  end

  get "/:client/*" do |client, path|
    viewpath = "#{@@project[client]["path"]}/views/#{path}"
    if File.file?(viewpath)
      File.read(viewpath)
    else
      "#{viewpath} does not exist."
    end
  end
end

YAML.load_file("config.yaml").each do |project|
  ClientCMS.add_project(project)
end<commit_msg>Remove extra slashes in path.<commit_after>require "yaml"
require "sinatra"
require "sinatra/base"

class ClientCMS < Sinatra::Base
  def self.add_project(p)
    @@project ||= {}
    @@project[p["name"]] = p
    @@project[p["name"]]["credentials"] = YAML.load_file(p["path"] + "/pwd")
    self
  end

  use Rack::Auth::Basic do |username, password|
    users = @@project.reduce({}) do |result, (_, data)|
      data["credentials"].each do |name, pwd|
        result[name] = pwd
      end
    end
    users[username] == password
  end

  get "/:client/*" do |client, path|
    viewpath = "#{@@project[client]["path"]}/views/#{path}".gsub("//", "/")
    if File.file?(viewpath)
      File.read(viewpath)
    else
      "#{viewpath} does not exist."
    end
  end
end

YAML.load_file("config.yaml").each do |project|
  ClientCMS.add_project(project)
end
{'fraction_non_alphanumeric': 0.18105515587529977, 'fraction_numerical': 0.0, 'mean_word_length': 3.4036939313984167, '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': '1000552', 'n_tokens_mistral': 602, 'n_tokens_neox': 585, 'n_words': 129}