<commit_before>require 'erb'

module CartoDB
  class ApiDocumentationServer

    def initialize(app)
      @app = app
    end

    def call(env)
      if env['HTTP_HOST'] =~ /^developers\./ && authenticated?(env)
        begin
          layout_path = "#{Rails.root}/app/views/layouts/developers.html.erb"
          file_path = "#{Rails.root}/app/views/developers/#{env['PATH_INFO']}"
          file_path =~ /\/$/ ? file_path += 'index.html' : file_path += '.html'

          html = File.read(layout_path).gsub(/\{\{yield\}\}/,File.open(file_path).read).
                                        gsub(/\{\{sidebar\}\}/,File.open("#{Rails.root}/app/views/developers/api/_sidebar.html").read)
          unless File.file?(layout_path) and File.file?(file_path)
            [ 404, {'Content-Type' => 'text/html'}, File.read("#{Rails.root}/public/404.html") ]
          else
            [ 200, {'Content-Type' => 'text/html'}, ERB.new(html).result(binding) ]
          end
        rescue
          [ 404, {'Content-Type' => 'text/html'}, File.read("#{Rails.root}/public/404.html") ]<commit_msg>Bufix: 404 file path<commit_after>require 'erb'

module CartoDB
  class ApiDocumentationServer

    def initialize(app)
      @app = app
    end

    def call(env)
      if env['HTTP_HOST'] =~ /^developers\./ && authenticated?(env)
        begin
          layout_path = "#{Rails.root}/app/views/layouts/developers.html.erb"
          file_path = "#{Rails.root}/app/views/developers/#{env['PATH_INFO']}"
          file_path =~ /\/$/ ? file_path += 'index.html' : file_path += '.html'

          html = File.read(layout_path).gsub(/\{\{yield\}\}/,File.open(file_path).read).
                                        gsub(/\{\{sidebar\}\}/,File.open("#{Rails.root}/app/views/developers/api/_sidebar.html").read)
          unless File.file?(layout_path) and File.file?(file_path)
            [ 404, {'Content-Type' => 'text/html'}, File.read("#{Rails.root}/public/404.html.erb") ]
          else
            [ 200, {'Content-Type' => 'text/html'}, ERB.new(html).result(binding) ]
          end
        rescue
          [ 404, {'Content-Type' => 'text/html'}, File.read("#{Rails.root}/public/404.html.erb") ]
{'fraction_non_alphanumeric': 0.19232526267702146, 'fraction_numerical': 0.01507537688442211, 'mean_word_length': 2.3181818181818183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306317', 'n_tokens_mistral': 757, 'n_tokens_neox': 721, 'n_words': 101}