<commit_before>require "mustache"
require "json"

module Wax
  class PageRenderer
    def initialize(paths)
      @paths = paths
    end

    def render(page)
      content = page.modules.map do |mod|
        template = File.join(@paths[:templates], mod.template) + ".mustache"
        data     = File.join(@paths[:data], mod.data) + ".json"
        Mustache.render File.read(template), JSON.parse(File.read(data))
      end
      Mustache.render File.read(@paths[:layout]), content: content.join("")
    end
  end
end
<commit_msg>Page rendering error messages<commit_after>require "mustache"
require "json"

module Wax
  class PageRenderer
    def initialize(paths)
      @paths = paths
    end

    def render(page)
      begin
        puts "-> Rendering page: #{page.name}"
        content = page.modules.map do |mod|
          template = File.join(@paths[:templates], mod.template) + ".mustache"
          data     = File.join(@paths[:data], mod.data) + ".json"
          puts mod.template + "..."
          Mustache.render File.read(template), JSON.parse(File.read(data, encoding: "bom|utf-8"))
        end
        Mustache.render File.read(@paths[:layout]), content: content.join("")
      rescue => e
        puts "Error rendering page: #{e}"
        puts e.backtrace
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1343054489639294, 'fraction_numerical': 0.0007674597083653108, 'mean_word_length': 2.5726027397260274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6477698', 'n_tokens_mistral': 391, 'n_tokens_neox': 392, 'n_words': 98}