Permalink
Browse files

When previewing wiki content, graphviz_me macro renders the image int…

…o img@src using data scheme.
  • Loading branch information...
1 parent b3f61c5 commit a403f4ccbc9125fcc540262da995909210927a3c @tckz committed with aki-blizzard6 Feb 16, 2012
Showing with 35 additions and 21 deletions.
  1. +6 −14 README.rdoc
  2. +21 −4 app/helpers/wiki_graphviz_helper.rb
  3. +6 −1 app/views/wiki_graphviz/macro.rhtml
  4. +2 −2 init.rb
View
@@ -40,7 +40,7 @@ Redmine Wiki Graphviz-macro plugin will allow Redmine's wiki to render graph ima
// {{graphviz_me(option=value)}}
* options: See graphviz macro.
-* Cause of specification about redmine's wiki macro, the macro can't render previewing wiki content.
+* When previewing, this macro output the image into img@src with data scheme. Thus, old browsers can't render it.
== Tips
@@ -52,7 +52,7 @@ Redmine Wiki Graphviz-macro plugin will allow Redmine's wiki to render graph ima
== Requirement
-* Redmine 1.1.0 or later.
+* Redmine 1.3.0 or later.
* Graphviz http://www.graphviz.org
* There are 2ways about setting up graphviz for this plugin.
* The one is using Gv which is ruby binding of graphviz.
@@ -119,18 +119,10 @@ This plugin is licensed under the GNU GPL v2. See COPYRIGHT.txt and GPL.txt for
== My environment
-* CentOS 5.5 x64
-* ruby-1.8.7-p248
-* MySQL-server-5.0.67-tritonn.1.0.12
+* CentOS 6.0 x64
+* ruby-1.8.7-p352
+* mysql-server-5.1.61
* graphviz-2.26.0
-* redmine-1.1.0
-
-== My environment 2
-
-* Windows XP Pro SP3(ja)
-* ruby-1.8.7-p299(provided by rumix. http://ruby.morphball.net/rumix/)
-* sqlite-3.7.0
-* graphviz-2.26.3
-* redmine-1.1.0
+* redmine-1.3.0
@@ -2,6 +2,7 @@
require 'tempfile'
require 'kconv'
require 'fileutils'
+require 'base64'
module WikiGraphvizHelper
@@ -64,10 +65,10 @@ def make_macro_output_by_title(macro_params, project_id)
end
content = page.content_for_version(macro_params[:version])
- self.make_macro_output_by_text(content.text, macro_params, project_id)
+ self.make_macro_output_by_text(content.text, macro_params, project_id, false)
end
- def make_macro_output_by_text(dottext, macro_params, project_id)
+ def make_macro_output_by_text(dottext, macro_params, project_id, using_data_scheme)
graph = self.render_graph(macro_params, dottext)
if !graph[:image]
raise "page=#{macro_params[:title]}, error=#{graph[:message]}"
@@ -81,6 +82,11 @@ def make_macro_output_by_text(dottext, macro_params, project_id)
:map_index => @index_macro,
}
+ if using_data_scheme
+ macro[:data_scheme] = "data:#{graph[:format][:content_type]};base64,#{Base64.encode64(graph[:image]).chomp}"
+ end
+
+
render_to_string :template => 'wiki_graphviz/macro', :layout => false, :locals => {:macro => macro}
end
@@ -310,15 +316,26 @@ def graphviz(args, project_id)
def graphviz_me(args, project_id, title)
begin
- if @content.nil?
+ using_data_scheme = false
+ # want to use previewing text.
+ text = @view.controller.params[:content] && @view.controller.params[:content][:text]
+ if !text.nil?
+ using_data_scheme = true
+ end
+
+ if text.nil? && !@content.nil?
+ text = @content.text
+ end
+
+ if text.nil?
return ""
end
set_macro_params(args)
macro_params = @macro_params.clone
macro_params[:title] = title
@view.controller.countup_macro_index()
- @view.controller.make_macro_output_by_text(@content.text, macro_params, project_id)
+ @view.controller.make_macro_output_by_text(text, macro_params, project_id, using_data_scheme)
rescue => e
# wiki_formatting.rb(about redmine 1.0.0) catch exception and write e.to_s into HTML. so escape message.
ex = RuntimeError.new(ERB::Util.html_escape(e.message))
@@ -24,14 +24,19 @@
:format => macro[:params][:format]
)
end
+
+ img_src = url_for_rendered_img
+ if !macro[:data_scheme].nil?
+ img_src = macro[:data_scheme]
+ end
%>
<% if !href.nil? %>
<a href="<%= href %>" <% if macro[:params][:target] != "" %> target="<%= h macro[:params][:target] %>" <% end %> >
<% end %>
<img <% if use_map %> usemap="#<%= h "wiki-graphviz-map-#{macro[:map_index]}" %>" <% end %> <% [:align, :width, :height].each do |img_attr| %>
<% if macro[:params][img_attr].to_s != "" %> <%= img_attr.to_s %>="<%= h macro[:params][img_attr].to_s %>" <% end %>
- <% end %> class="graphviz-macro-image" src="<%= url_for_rendered_img %>"/>
+ <% end %> class="graphviz-macro-image" src="<%= img_src %>"/>
<% if !href.nil? %>
</a>
View
@@ -7,9 +7,9 @@
author 'tckz'
url "http://passing.breeze.cc/mt/" if respond_to?(:url)
description 'Render graph image from the wiki contents by Graphviz(http://www.graphviz.org/)'
- version '0.2.1'
+ version '0.2.2'
settings :default => {'cache_seconds' => '0'}, :partial => 'wiki_graphviz/settings'
- requires_redmine :version_or_higher => '1.1.0'
+ requires_redmine :version_or_higher => '1.3.0'
Redmine::WikiFormatting::Macros.register do

0 comments on commit a403f4c

Please sign in to comment.