OT_LOGO = "http://opentox.informatik.uni-freiburg.de/ot-logo.png" class String # encloses URI in text with with link tag # @return [String] new text with marked links def link_urls self.gsub(/(?i)http:\/\/[^\r\n\s']*/, '\0') end end module OpenTox # produces a html page for making web services browser friendly # format of text (=string params) is preserved (e.g. line breaks) # urls are marked as links # @example post params: # [ [ [:mandatory_param_1], [:mandatory_param_2], [:optional_param,"default_value"] ], # [ [:alteranative_mandatory_param_1], [:alteranative_mandatory_param_2] ] # ] # @param [String] text this is the actual content, # @param [optional,String] related_links info on related resources # @param [optional,String] description general info # @param [optional,Array] post_params, array of arrays containing info on POST operation, see example # @return [String] html page def self.text_to_html( text, related_links=nil, description=nil, post_params=nil ) # TODO add title as parameter title = nil #$sinatra.url_for($sinatra.request.env['PATH_INFO'], :full) if $sinatra html = < EOF html.chomp! html += ""+title+"" if title html += < EOF html.chomp! html += "

Description

"+description.link_urls+"

" if description html += "

Related links

"+related_links.link_urls+"

" if related_links if post_params html += "

POST parameters

" count = 0 post_params.each do |p| html += "

alternatively:

" if count > 0 html += "

" p.each do |k,v| html += "" end html += "
paramdefault_value
"+k.to_s+""+(v!=nil ? v.to_s : "mandatory")+"

" count += 1 end end html += "

Content

" if description || related_links html += <

EOF html.chomp! html += text.link_urls html += < EOF html end end #puts OpenTox.text_to_html("bla")