Project

General

Profile

Feature #3228 ยป inline-html-images.diff

Patch to inline images as Base64 encoded in exported HTML - Jak Charlton, 2010-08-22 01:21

View differences:

app/helpers/application_helper.rb
attachments ||= (options[:attachments] || obj.attachments).sort_by(&:created_on).reverse
# 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('"', '')
if !desc.blank? && alttext.blank?
if !desc.blank? && alttext.blank?
alt = " title=\"#{desc}\" alt=\"#{desc}\""
end
"src=\"#{image_url}\"#{alt}"
else
alt = ""
end
case options[:wiki_links]
when :local
"src=\"data:#{found.content_type};base64,#{Base64.b64encode(File.read(found.diskfile)).gsub(/\n/,"")}\"#{alt}"
when :anchor
"src=\"data:#{found.content_type};base64,#{Base64.b64encode(File.read(found.diskfile)).gsub(/\n/,"")}\"#{alt}"
else
image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
"src=\"#{image_url}#{alt}\""
end
else
m
end
app/views/wiki/export.rhtml
</style>
</head>
<body>
<%= textilizable @content, :text, :wiki_links => :local %>
<%= textilizable @content, :text, :wiki_links => :local, :attachments => @content.page.attachments %>
</body>
</html>
app/views/wiki/export_multiple.rhtml
<% @pages.each do |page| %>
<hr />
<a name="<%= page.title %>" />
<%= textilizable page.content ,:text, :wiki_links => :anchor %>
<%= textilizable page.content ,:text, :wiki_links => :anchor, :attachments => page.attachments %>
<% end %>
</body>
    (1-1/1)