Module: Ruote::TemplateMixin
- Included in:
- SmtpParticipant
- Defined in:
- lib/ruote/part/template.rb
Overview
Template rendering helper.
(Currently only used by the SmtpParticipant, could prove useful for custom participants)
This module expects to find the ruote @context available (probably accessible thanks to the Ruote::LocalParticipant module, see Ruote::SmtpParticipant as an example).
Instance Method Summary collapse
-
#render_default_template(workitem) ⇒ Object
Simply returns a pretty-printed view of the workitem.
-
#render_template(template, flow_expression, workitem) ⇒ Object
Do the rendering.
Instance Method Details
#render_default_template(workitem) ⇒ Object
Simply returns a pretty-printed view of the workitem
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ruote/part/template.rb', line 58 def render_default_template(workitem) workitem = workitem.to_h if workitem.respond_to?(:to_h) s = [] s << "workitem for #{workitem['participant_name']}" s << '' s << Rufus::Json.pretty_encode(workitem['fei']) s << '' workitem['fields'].keys.sort.each do |key| s << " - '#{key}' ==> #{Rufus::Json.encode(workitem['fields'][key])}" end s.join("\n") end |
#render_template(template, flow_expression, workitem) ⇒ Object
Do the rendering.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruote/part/template.rb', line 44 def render_template(template, flow_expression, workitem) template = (File.read(template) rescue nil) if is_a_file?(template) return render_default_template(workitem) unless template template = template.to_s workitem = workitem.to_h if workitem.respond_to?(:to_h) @context.dollar_sub.s(template, flow_expression, workitem) end |