class TavernaPlayer::PortRenderer
This class manages the rendering of many different port types that could be associated with a workflow. It can be configured with new types and the example renderers for each type can also be changed. An example of how to set it up can be found in the taverna_player initializer.
Each renderer has all of the ActionView::Helpers (such as link_to, tag, etc) available to them.
Public Instance Methods
Add a renderer method for the specified MIME type. If you would like the renderer to be the default for that particular media type then pass true in the final parameter - the media type is the part of a MIME type before the slash (/), e.g. “text” or “image”. The MIME type should be specified as a string.
# File lib/taverna_player/port_renderer.rb, line 51 def add(mimetype, method, default = false) type = MIME::Types[mimetype].first @hash[type.media_type] ||= {} @hash[type.media_type][type.sub_type] = method type_default(type.media_type, method) if default end
Set a default renderer for any MIME type not specifically set. This could be used to supply a piece of text and a download link for any type that cannot normally be shown in the browser inline.
# File lib/taverna_player/port_renderer.rb, line 75 def default(method) @hash[:default] = method end
Set a renderer to handle list ports. This will typically format the list somehow and render the list items with further calls to TavernaPlayer.port_renderer.render.
# File lib/taverna_player/port_renderer.rb, line 85 def list(method) @hash[:list] = method end
This is the method that calls the correct renderer for the given port and returns the resultant rendering.
# File lib/taverna_player/port_renderer.rb, line 94 def render(port, index = []) if port.depth > 0 && index.empty? renderer = @hash[:list] else type = MIME::Types[port.value_type(index)].first renderer = @hash[type.media_type][type.sub_type] || @hash[type.media_type][:default] || @hash[:default] end raw(callback(renderer, port, index)) end
This is another way of setting the default renderer method for a whole media type (see the add method for more details).
# File lib/taverna_player/port_renderer.rb, line 64 def type_default(media_type, method) @hash[media_type] ||= {} @hash[media_type][:default] = method end