Class | OpenWFE::Extras::AtomFeedParticipant |
In: |
lib/openwfe/extras/participants/atomfeed_participants.rb
|
Parent: | Object |
Stores the incoming workitem into an ‘atom feed‘
An example :
feed0 = AtomFeedParticipant.new( 20, # no more than 20 entries are kept """ <p> <h1>${f:colour}</h1> </p> """) # the template for each entry
The ‘template’ parameter may contain an instance of File instead of an instance of String.
feed0 = AtomFeedParticipant.new( 20, File.new("path/to/my/atom/template.txt")
The template can be passed as the second parameter (after the max entry count) or as a block :
feed1 = AtomFeedParticipant.new(20) do |flow_expression, atom_participant, workitem| # # usually only the workitem parameter is used # but the other two allow for advanced tricks... atom_participant.content_type = "xml" # by default, it's "xhtml" s = "<task>" s << "<name>#{workitem.task_name}</name>" s << "<assignee>#{workitem.task_assignee}</assignee>" s << "<duedate>#{workitem.task_duedate}</duedate>" s << "</task>" # the block is supposed to 'return' a string which is the # effective template end
This participant uses "atom-tools" from code.necronomicorp.com/trac/atom-tools
content_type | [RW] | Made accessible so that blocks may set it. |
# File lib/openwfe/extras/participants/atomfeed_participants.rb, line 112 112: def initialize (max_item_count, template=nil, &block) 113: 114: super() # very important as this class includes MonitorMixin 115: 116: @template = template 117: @max_item_count = max_item_count 118: @block_template = block 119: 120: @feed = Atom::Collection.new("http://localhost") 121: @content_type = "xhtml" 122: end
# File lib/openwfe/extras/participants/atomfeed_participants.rb, line 124 124: def consume (workitem) 125: 126: e = Atom::Entry.new 127: 128: e.id = \ 129: "#{workitem.fei.workflow_instance_id}--" + 130: "#{workitem.fei.expression_id}" 131: 132: e.title = workitem.atom_entry_title 133: e.content = render(workitem) 134: 135: e.content["type"] = @content_type 136: 137: @feed << e 138: 139: @feed = @feed[0, @max_item_count] \ 140: if @feed.length > @max_item_count 141: 142: publish workitem 143: 144: reply_to_engine workitem 145: end
For the moment, just dumps the feed into a file.
# File lib/openwfe/extras/participants/atomfeed_participants.rb, line 163 163: def publish (workitem) 164: synchronize do 165: filename = "work/atom_#{workitem.participant_name}.xml" 166: f = File.open(filename, "w") 167: f << @feed.to_s 168: f.close() 169: end 170: end
This base implementation simply calls the eval_template() method of the TemplateMixin. Feel free to override this render() method for custom representations.
# File lib/openwfe/extras/participants/atomfeed_participants.rb, line 155 155: def render (workitem) 156: 157: eval_template workitem 158: end