class HealthDataStandards::Export::RenderingContext
Used to actually render stuff. A RenderingContext
needs to be set up with a template helper and may be provided with extensions.
:call-seq:
template_helper = HealthDataStandards::Export::TemplateHelper.new('cat1', 'cat1') rendering_context = HealthDataStandards::Export::RenderingContext.new rendering_context.template_helper = template_helper rendering_context.extensions = [HealthDataStandards::Export::Helper::Cat1ViewHelper]
In this case, a RenderingContext
is being set up to generate Category 1 files. It is passed a template helper to finds the correct ERb templates to render from. It is also given an extension. This is just a Ruby Module which will have its methods exposed to the templates. RenderingContext
will assume that extensions is an Array and will include multiple extensions if more than one is provided.
Attributes
extensions[RW]
template_helper[RW]
Public Instance Methods
my_binding()
click to toggle source
# File lib/health-data-standards/export/rendering_context.rb, line 22 def my_binding binding end
render(params)
click to toggle source
# File lib/health-data-standards/export/rendering_context.rb, line 28 def render(params) erb = nil ident = nil if params[:template] erb = @template_helper.template(params[:template]) elsif params[:partial] erb = @template_helper.partial(params[:partial]) if params[:collection] ident = params[:id] || params[:partial] end end collection = params[:collection] || [true] collection.map do |item| locals = params[:locals] locals ||= {} if ident locals[ident] = item end rendering_context = RenderingContext.new(locals) rendering_context.template_helper = @template_helper if @extensions.present? rendering_context.extensions = @extensions @extensions.each do |extension| rendering_context.extend(extension) end end erb.result(rendering_context.my_binding) end.join end