From 8e5fd2692abec4332e57918f0f631b88110cf422 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 29 Oct 2009 18:20:44 +0100 Subject: [PATCH 33/34] Add images to the wiki export functionality. The images are converted to base64 strings and attached to the html page itself. This fixed Feature #550 --- app/helpers/application_helper.rb | 15 +++++++++++---- app/views/wiki/export.rhtml | 2 +- app/views/wiki/export_multiple.rhtml | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e370aad..d686a0b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -371,10 +371,17 @@ module ApplicationHelper filename = $6.downcase # search for the picture in attachments if found = attachments.detect { |att| att.filename.downcase == filename } - image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found - desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1") - alt = desc.blank? ? nil : "(#{desc})" - "!#{style}#{image_url}#{alt}!" + case options[:wiki_links] + when :local + "!#{style}data:#{found.content_type};base64,#{Base64.b64encode(File.read(found.diskfile)).gsub(/\n/,"")}!" + when :anchor + "!#{style}data:#{found.content_type};base64,#{Base64.b64encode(File.read(found.diskfile)).gsub(/\n/,"")}!" + else + image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found + desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1") + alt = desc.blank? ? nil : "(#{desc})" + "!#{style}#{image_url}#{alt}!" + end else m end diff --git a/app/views/wiki/export.rhtml b/app/views/wiki/export.rhtml index 7f861fa..99c8afd 100644 --- a/app/views/wiki/export.rhtml +++ b/app/views/wiki/export.rhtml @@ -13,6 +13,6 @@ ul.toc li.heading3 { margin-left: 2em; } -<%= textilizable @content, :text, :wiki_links => :local %> +<%= textilizable @content, :text, :wiki_links => :local, :attachments => @content.page.attachments %> diff --git a/app/views/wiki/export_multiple.rhtml b/app/views/wiki/export_multiple.rhtml index a4e4c5e..d69c4c1 100644 --- a/app/views/wiki/export_multiple.rhtml +++ b/app/views/wiki/export_multiple.rhtml @@ -20,7 +20,7 @@ h1, h2, h3, h4 { font-family: "Trebuchet MS",Georgia,"Times New Roman",serif; } <% @pages.each do |page| %>
-<%= textilizable page.content ,:text, :wiki_links => :anchor %> +<%= textilizable page.content ,:text, :wiki_links => :anchor, :attachments => page.attachments %> <% end %> -- 1.6.4.4