<commit_before>module HealthDataStandards
  module Export
    module TemplateHelper
      attr_accessor :template_format
      attr_accessor :template_subdir

      def template_root
        if @template_subdir
          return File.join(File.dirname(__FILE__), '..', '..', '..', 'templates', @template_subdir)
        else
          return File.join(File.dirname(__FILE__), '..', '..', '..', 'templates')
        end
      end

      def template(template_name)
        File.read(File.join(template_root, "#{template_name}.#{self.template_format}.erb"))
      end

      def partial(partial_name)
        template("_#{partial_name}")
      end

      def render(params)
        erb = nil
        if params[:template]
          erb = template(params[:template])
        elsif params[:partial]
          erb = partial(params[:partial])
        end
        
        locals = params[:locals]
        locals ||= {}
        rendering_context = RenderingContext.new(locals)
        rendering_context.template_format = self.template_format
        rendering_context.template_subdir = self.template_subdir
        eruby = Erubis::EscapedEruby.new(erb)
        eruby.result(rendering_context.my_binding)
      end
    end
  end
end<commit_msg>Adding an instance variable to capture the template directory. This will make it easier for other gems to extend the TemplateHelper.<commit_after>module HealthDataStandards
  module Export
    module TemplateHelper
      attr_accessor :template_format
      attr_accessor :template_subdir
      attr_accessor :template_directory

      def template_root
        @template_directory ||= File.dirname(__FILE__)

        if @template_subdir
          return File.join(@template_directory, '..', '..', '..', 'templates', @template_subdir)
        else
          return File.join(@template_directory, '..', '..', '..', 'templates')
        end
      end

      def template(template_name)
        File.read(File.join(template_root, "#{template_name}.#{self.template_format}.erb"))
      end

      def partial(partial_name)
        template("_#{partial_name}")
      end

      def render(params)
        erb = nil
        if params[:template]
          erb = template(params[:template])
        elsif params[:partial]
          erb = partial(params[:partial])
        end
        
        locals = params[:locals]
        locals ||= {}
        rendering_context = RenderingContext.new(locals)
        rendering_context.template_format = self.template_format
        rendering_context.template_subdir = self.template_subdir
        rendering_context.template_directory = self.template_directory
        eruby = Erubis::EscapedEruby.new(erb)
        eruby.result(rendering_context.my_binding)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10152838427947598, 'fraction_numerical': 0.0, 'mean_word_length': 2.55627425614489, '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': '130212', 'n_tokens_mistral': 781, 'n_tokens_neox': 778, 'n_words': 149}