<commit_before><commit_msg>Partial handler for template.<commit_after>require "erb"
require "anypresence_generator/template"

module AnypresenceGenerator
  class Template
    module Partial

      attr_accessor :locals

      # This object responds to local variables for partial rendering.
      def respond_to?(method, include_private = false)
        (locals && locals.last.is_a?(Hash) && locals.last.has_key?(method)) || super
      end

    protected

      # Renders partial templates.
      def render_partial(name: ( raise AnypresenceGenerator::Template::TemplateError.new('Partial name is required.'.freeze) ), locals: nil, indent: 0)
        self.locals ||= []
        self.locals.push locals
        proc = ::Proc.new {}
        output = ERB.new(File.read(partial_file(name: name)),nil,'<>'.freeze).result(proc.binding)
        if indent > 0
          output = output.gsub(/^/, ' ' * indent)
        end
        self.locals.pop
        output
      end

      # The file that contains the partial referenced by the name.
      def partial_file(name: ( raise AnypresenceGenerator::Template::TemplateError.new('Partial name is required.'.freeze) ) )
        raise 'must be implemented by implementation class'
      end

      # The method missing implementation allows access to "local variables" in partials.
      def method_missing(method, *args, &block)
        if respond_to?(method)
          locals.last[method]
        else
          super
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09686038744154976, 'fraction_numerical': 0.0013360053440213762, 'mean_word_length': 2.6987654320987655, 'pattern_counts': {'":': 0, '<': 4, '<?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': '6336222', 'n_tokens_mistral': 416, 'n_tokens_neox': 410, 'n_words': 116}