Method: OpenC3::TargetModel#render
- Defined in:
- lib/openc3/models/target_model.rb
#render(template_name, options = {}) ⇒ Object
Called by the ERB template to render a partial
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'lib/openc3/models/target_model.rb', line 579 def render(template_name, = {}) raise "Partial name '#{template_name}' must begin with an underscore." if File.basename(template_name)[0] != '_' b = binding b.local_variable_set(:target_name, @name) if [:locals] [:locals].each { |key, value| b.local_variable_set(key, value) } end # Assume the file is there. If not we raise a pretty obvious error if File.(template_name) == template_name # absolute path path = template_name else # relative to the current @filename path = File.join(File.dirname(@filename), template_name) end begin OpenC3.set_working_dir(File.dirname(path)) do return ERB.new(File.read(path), trim_mode: "-").result(b) end rescue => error raise "ERB error parsing: #{path}: #{error.formatted}" end end |