<commit_before># frozen_string_literal: true

module Dimples
  module Renderable
    def render(context = {}, body = nil)
      context[:site] ||= @site
      context[type] = Hashie::Mash.new(@metadata)

      output = engine.render(scope, context) { body }

      return output unless (template = @site.templates[@metadata[:layout]])
      template.render(context, output)
    end

    def scope
      @scope ||= Object.new.tap do |scope|
        scope.instance_variable_set(:@site, @site)
        scope.instance_variable_set(:@metadata, {})

        scope.class.send(:define_method, :render) do |layout, locals = {}|
          @site.templates[layout]&.render(locals)
        end
      end
    end

    def engine
      @engine ||= begin
        callback = proc { @contents }

        if @path
          extension = File.extname(@path)
          options = @site.config.rendering[extension.to_sym] || {}

          Tilt.new(@path, options, &callback)
        else
          Tilt::StringTemplate.new(&callback)
        end
      end
    end
  end
end<commit_msg>Remove the metadata instance variable<commit_after># frozen_string_literal: true

module Dimples
  module Renderable
    def render(context = {}, body = nil)
      context[:site] ||= @site
      context[type] = Hashie::Mash.new(@metadata)

      output = engine.render(scope, context) { body }

      return output unless (template = @site.templates[@metadata[:layout]])
      template.render(context, output)
    end

    def scope
      @scope ||= Object.new.tap do |scope|
        scope.instance_variable_set(:@site, @site)

        scope.class.send(:define_method, :render) do |layout, locals = {}|
          @site.templates[layout]&.render(locals)
        end
      end
    end

    def engine
      @engine ||= begin
        callback = proc { @contents }

        if @path
          extension = File.extname(@path)
          options = @site.config.rendering[extension.to_sym] || {}

          Tilt.new(@path, options, &callback)
        else
          Tilt::StringTemplate.new(&callback)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.12225405921680993, 'fraction_numerical': 0.0, 'mean_word_length': 2.4120521172638436, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2611706', 'n_tokens_mistral': 619, 'n_tokens_neox': 607, 'n_words': 138}