diff options
author | mguetlein <martin.guetlein@gmail.com> | 2012-12-07 16:59:56 +0100 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2012-12-07 16:59:56 +0100 |
commit | 7e27259d5db7349e0e29762244298c986146ca37 (patch) | |
tree | 9258561d0693f7b8586392bdfa4c444fe929e707 /lib/utils | |
parent | 4af2fdebf685aa7ab7f5bc7c653fce49a4f1a389 (diff) |
extend html support
get request in service root now returns uri-list
accept header for html requests is fixed in before-method
fix link parsing in to_html method
add png image to to_html method
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/html.rb | 9 | ||||
-rw-r--r-- | lib/utils/shims/feature.rb | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/utils/html.rb b/lib/utils/html.rb index 91dfc64..d74f357 100644 --- a/lib/utils/html.rb +++ b/lib/utils/html.rb @@ -7,15 +7,17 @@ * Date: 10/2012 =end +require "base64" + # AM: needed since this gem has a nested directory structure class String # encloses URI in text with with link tag # @return [String] new text with marked links def link_urls - regex = Regexp.new '(https?:\/\/[\S]+)([>"])' - self.gsub( regex, '<a href="\1">\1</a>\2' ) + self.gsub(/(?i)http(s?):\/\/[^\r\n\s']*/, '<a href="\0">\0</a>') end + end module OpenTox @@ -29,7 +31,7 @@ module OpenTox # @param [optional,String] description general info # @param [optional,Array] post_command, infos for the post operation, object defined below # @return [String] html page - def self.text_to_html( text, subjectid=nil, related_links=nil, description=nil, post_command=nil ) + def self.text_to_html( text, subjectid=nil, related_links=nil, description=nil, post_command=nil, png_image=nil ) # TODO add title as parameter title = nil #$sinatra.url_for($sinatra.request.env['PATH_INFO'], :full) if $sinatra @@ -41,6 +43,7 @@ module OpenTox html += "<h3>Related links</h3><pre><p>"+related_links.link_urls+"</p></pre>" if related_links html += "<h3>Content</h3>" if description || related_links html += "<pre><p style=\"padding:15px; border:10px solid \#5D308A\">" + html += "<img src=\"data:image/png;base64,#{Base64.encode64(png_image)}\">\n" if png_image html += text.link_urls html += "</p></pre></body></html>" html diff --git a/lib/utils/shims/feature.rb b/lib/utils/shims/feature.rb index 297748b..f49bb39 100644 --- a/lib/utils/shims/feature.rb +++ b/lib/utils/shims/feature.rb @@ -30,7 +30,7 @@ module OpenTox metadata[RDF.type] = [] unless metadata[RDF.type] metadata[RDF.type] << RDF::OT.Feature unless metadata[RDF.type].include?(RDF::OT.Feature) metadata[RDF::DC.title] = title unless (metadata[RDF::DC.title]) - feature = feature_new = OpenTox::Feature.new File.join($feature[:uri], SecureRandom.uuid), @subjectid + feature = feature_new = OpenTox::Feature.new(File.join($feature[:uri], SecureRandom.uuid), @subjectid) feature_new.metadata = metadata sparql = "SELECT DISTINCT ?feature WHERE { ?feature <#{RDF.type}> <#{RDF::OT['feature'.capitalize]}>. ?feature <#{RDF::DC.title}> '#{title.to_s}' }" feature_uris = OpenTox::Backend::FourStore.query(sparql,"text/uri-list").split("\n") |