Sha256: 6ffe37acab61015db7e02e451fdd720eaa45ed48e166b0d1782ebf4cc53a35b4

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
health-data-standards-2.1.4 lib/health-data-standards/export/template_helper.rb
health-data-standards-2.1.3 lib/health-data-standards/export/template_helper.rb
health-data-standards-2.1.2 lib/health-data-standards/export/template_helper.rb
health-data-standards-2.1.1 lib/health-data-standards/export/template_helper.rb
health-data-standards-2.1.0 lib/health-data-standards/export/template_helper.rb
health-data-standards-2.0.0 lib/health-data-standards/export/template_helper.rb