Class: HealthDataStandards::Export::RenderingContext
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- HealthDataStandards::Export::RenderingContext
- Includes:
- ViewHelper
- Defined in:
- lib/health-data-standards/export/rendering_context.rb
Overview
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.
Instance Attribute Summary collapse
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#template_helper ⇒ Object
Returns the value of attribute template_helper.
Instance Method Summary collapse
Methods included from ViewHelper
#code_display, #convert_field_to_hash, #is_bool?, #is_num?, #status_code_for, #time_if_not_nil, #value_or_null_flavor
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
19 20 21 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 19 def extensions @extensions end |
#template_helper ⇒ Object
Returns the value of attribute template_helper.
19 20 21 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 19 def template_helper @template_helper end |
Instance Method Details
#my_binding ⇒ Object
21 22 23 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 21 def my_binding binding end |
#render(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 25 def render(params) erb = nil if params[:template] erb = @template_helper.template(params[:template]) elsif params[:partial] erb = @template_helper.partial(params[:partial]) end locals = params[:locals] locals ||= {} 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 eruby = Erubis::EscapedEruby.new(erb) # TODO: cache these eruby.result(rendering_context.my_binding) end |