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
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/openc3/models/target_model.rb', line 684 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 data = File.read(path, mode: "rb") erb_disabled = check_disable_erb(path) begin if erb_disabled return data else OpenC3.set_working_dir(File.dirname(path)) do return ERB.new(data.force_encoding("UTF-8").comment_erb(), trim_mode: "-").result(b) end end rescue => e raise "ERB error parsing: #{path}: #{e.formatted}" end end |