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
#clean_hash_code_system, #clean_hash_id, #code_display, #convert_field_to_hash, #create_code_display_string, #create_code_string, #create_laterality_code_string, #create_translations_code_string, #dose_quantity, #fulfillment_quantity, #identifier_for, #is_bool?, #is_num?, #status_code_for, #time_if_not_nil, #ucum_for_dose_quantity, #value_or_null_flavor
Instance Attribute Details
#extensions ⇒ Object
Returns the value of attribute extensions.
20 21 22 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 20 def extensions @extensions end |
#template_helper ⇒ Object
Returns the value of attribute template_helper.
20 21 22 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 20 def template_helper @template_helper end |
Instance Method Details
#my_binding ⇒ Object
22 23 24 |
# File 'lib/health-data-standards/export/rendering_context.rb', line 22 def my_binding binding end |
#render(params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 |