<commit_before>require 'tilt'

module ErrorPage

  class Renderer

    Default_options = {
      :path => 'views',
      :render_layout => true,
      :layout => :layout
    }
    
    def initialize(options = {})
      @options = Default_options.merge(options)
      @cache = Tilt::Cache.new
    end

    Tilt.mappings.each_key do |key|
      define_method(key.to_sym) do |page|
        layout_path = File.join(@options[:path],
                                "#{@options[:layout]}.#{key}")
        template_path = File.join(@options[:path], "#{page}.#{key}")
        template = compile(template_path)
        if @options[:render_layout]
          layout = compile(layout_path)
          layout.render{ template.render }
        else
          template.render
        end
      end
    end

    private

    def compile(path)
      @cache.fetch(path) { Tilt.new(path)}
    end

    def set(key, value)
      @options[key] = value
    end
    
  end

end
<commit_msg>added some clarity to code.<commit_after>require 'tilt'

module ErrorPage

  class Renderer

    Default_options = {
      :path => 'views',
      :render_layout => true,
      :layout => :layout
    }
    
    def initialize(options = {})
      @options = Default_options.merge(options)
      @cache = Tilt::Cache.new
    end

    Tilt.mappings.each_key do |key|
      define_method(key.to_sym) do |page|
        opt_path = @options[:path]
        layout_name =  "#{@options[:layout]}.#{key}"
        file_name = "#{page}.#{key}"
        
        layout_path = File.join(opt_path, layout_name)
        template_path = File.join(opt_path, file_name)
        template = compile(template_path)

        if @options[:render_layout]
          layout = compile(layout_path)
          layout.render{ template.render }
        else
          template.render
        end
      end
    end

    def set(key, value)
      @options[key] = value
    end

    private

    def compile(path)
      @cache.fetch(path) { Tilt.new(path)}
    end
    
  end

end

{'fraction_non_alphanumeric': 0.11829025844930417, 'fraction_numerical': 0.0, 'mean_word_length': 2.059270516717325, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2981384', 'n_tokens_mistral': 632, 'n_tokens_neox': 627, 'n_words': 128}