summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorAlexander Tsvyashchenko <ndl@ndl.kiev.ua>2010-03-26 22:33:50 (GMT)
committerAlexander Tsvyashchenko <ndl@ndl.kiev.ua>2010-03-26 22:33:50 (GMT)
commit5a6f81888fa0ab73fe539117650cc99eb459ad15 (patch)
tree976fabdfab830b6cc80b6191277c987e13f7ea56 /app
parent8cfa874772765e14fa00be565d85c19c5183f00a (diff)
downloadwiki_external_filter-5a6f81888fa0ab73fe539117650cc99eb459ad15.zip
wiki_external_filter-5a6f81888fa0ab73fe539117650cc99eb459ad15.tar.gz
wiki_external_filter-5a6f81888fa0ab73fe539117650cc99eb459ad15.tar.bz2
- Unified block/inline rendering.
- Split views to separate files. - Added PNG fallback for SVG displaying. - Improved SVG compliance.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/wiki_external_filter_controller.rb2
-rw-r--r--app/helpers/wiki_external_filter_helper.rb38
-rw-r--r--app/views/wiki_external_filter/block.html.erb5
-rw-r--r--app/views/wiki_external_filter/headers.html.erb10
-rw-r--r--app/views/wiki_external_filter/macro_block.html.erb64
-rw-r--r--app/views/wiki_external_filter/macro_flash-video.html.erb22
-rw-r--r--app/views/wiki_external_filter/macro_image.html.erb1
-rw-r--r--app/views/wiki_external_filter/macro_inline.html.erb61
-rw-r--r--app/views/wiki_external_filter/macro_svg.html.erb27
-rw-r--r--app/views/wiki_external_filter/macro_text.html.erb1
10 files changed, 92 insertions, 139 deletions
diff --git a/app/controllers/wiki_external_filter_controller.rb b/app/controllers/wiki_external_filter_controller.rb
index 94a25bd..af0e553 100644
--- a/app/controllers/wiki_external_filter_controller.rb
+++ b/app/controllers/wiki_external_filter_controller.rb
@@ -13,7 +13,7 @@ class WikiExternalFilterController < ApplicationController
content = read_fragment cache_key
if (content)
- send_data content[index], :type => config[macro]['content_type'], :disposition => 'inline', :filename => filename
+ send_data content[index], :type => config[macro]['outputs'][index]['content_type'], :disposition => 'inline', :filename => filename
else
render_404
end
diff --git a/app/helpers/wiki_external_filter_helper.rb b/app/helpers/wiki_external_filter_helper.rb
index 431a93f..d65bf41 100644
--- a/app/helpers/wiki_external_filter_helper.rb
+++ b/app/helpers/wiki_external_filter_helper.rb
@@ -47,7 +47,6 @@ module WikiExternalFilterHelper
if content
result[:source] = text
result[:content] = content
- result[:content_type] = info['content_type']
RAILS_DEFAULT_LOGGER.debug "from cache: #{name}"
else
result = self.build_forced(text, attachments, info)
@@ -63,6 +62,8 @@ module WikiExternalFilterHelper
result[:name] = name
result[:macro] = macro
+ result[:content_types] = info['outputs'].map { |out| out['content_type'] }
+ result[:template] = info['template']
return result
end
@@ -79,18 +80,16 @@ module WikiExternalFilterHelper
content = []
errors = ""
- commands = info['commands']? info['commands'] : [info['command']]
-
- commands.each do |command|
- RAILS_DEFAULT_LOGGER.info "executing command: #{command}"
+ info['outputs'].each do |out|
+ RAILS_DEFAULT_LOGGER.info "executing command: #{out['command']}"
c = nil
e = nil
- Open4::popen4(command) { |pid, fin, fout, ferr|
- fin.write info[:prolog] if info.key?(:prolog)
+ Open4::popen4(out['command']) { |pid, fin, fout, ferr|
+ fin.write out['prolog'] if out.key?('prolog')
fin.write CGI.unescapeHTML(text)
- fin.write info[:epilog] if info.key?(:epilog)
+ fin.write out['epilog'] if out.key?('epilog')
fin.close
c, e = [fout.read, ferr.read]
}
@@ -103,7 +102,6 @@ module WikiExternalFilterHelper
result[:content] = content
result[:errors] = errors
- result[:content_type] = info['content_type']
result[:source] = text
result[:status] = $?.exitstatus == 0
@@ -111,21 +109,35 @@ module WikiExternalFilterHelper
end
def render_tag(result)
- render_to_string :template => 'wiki_external_filter/macro_inline', :layout => false, :locals => result
+ result = result.dup
+ result[:render_type] = 'inline'
+ html = render_common(result).chop
+ html << headers_common(result).chop
+ html
end
def render_block(result, wiki_name)
result = result.dup
+ result[:render_type] = 'block'
result[:wiki_name] = wiki_name
- render_to_string :template => 'wiki_external_filter/macro_block', :layout => false, :locals => result
+ result[:inside] = render_common(result)
+ html = render_to_string(:template => 'wiki_external_filter/block', :layout => false, :locals => result).chop
+ html << headers_common(result).chop
+ html
+ end
+
+ def render_common(result)
+ render_to_string :template => "wiki_external_filter/macro_#{result[:template]}", :layout => false, :locals => result
+ end
+
+ def headers_common(result)
+ render_to_string :template => 'wiki_external_filter/headers', :layout => false, :locals => result
end
class Macro
def initialize(view, source, attachments, macro, info)
@view = view
@view.controller.extend(WikiExternalFilterHelper)
- source.gsub!(/<br \/>/, "")
- source.gsub!(/<\/?p>/, "")
@result = @view.controller.build(source, attachments, macro, info)
end
diff --git a/app/views/wiki_external_filter/block.html.erb b/app/views/wiki_external_filter/block.html.erb
new file mode 100644
index 0000000..d613651
--- /dev/null
+++ b/app/views/wiki_external_filter/block.html.erb
@@ -0,0 +1,5 @@
+<div class='externalfilterblock'>
+ <%= inside %>
+ <br/>
+ <span class='wiki_page'>Goto source: [[<%= wiki_name %>]]</span>
+</div>
diff --git a/app/views/wiki_external_filter/headers.html.erb b/app/views/wiki_external_filter/headers.html.erb
new file mode 100644
index 0000000..8354618
--- /dev/null
+++ b/app/views/wiki_external_filter/headers.html.erb
@@ -0,0 +1,10 @@
+<%
+ content_for :header_tags do
+ if not @stylesheets_included
+ @stylesheets_included = true
+%>
+ <%= stylesheet_link_tag "wiki_external_filter.css", :plugin => "wiki_external_filter", :media => :all %>
+<%
+ end
+ end
+%>
diff --git a/app/views/wiki_external_filter/macro_block.html.erb b/app/views/wiki_external_filter/macro_block.html.erb
deleted file mode 100644
index 03f3949..0000000
--- a/app/views/wiki_external_filter/macro_block.html.erb
+++ /dev/null
@@ -1,64 +0,0 @@
-<div class='externalfilterblock'>
-<%
- case content_type
- when /image\// then
-%>
- <img src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name) %>' alt="<%= h source %>" />
-<%
- when /text\/plain/ then
-%>
- <pre><%= h content %></pre>
-<%
- when /\/.*(x|ht)ml/ then
-%>
- <div><%= content %></div>
-<%
- when /video\/x\-flv/ then
- require 'RMagick'
- image = Magick::Image::from_blob(content[0]).first
-%>
- <a class='flowplayer-video' href='<%= ActionController::Base.relative_url_root + "/wiki_external_filter/video.flv?name=#{name}" %>' alt='<%= h source %>' style='display:block;width:<%= image.columns %>px;height:<%= image.rows + 24 %>px;background-image:url(<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>);background-repeat:no-repeat'><%= image_tag 'play_large.png', :plugin => 'wiki_external_filter', :style => "display:block;position:relative;left:#{image.columns / 2 - 83 / 2}px;top:#{image.rows / 2 - 83 / 2}px" %></a>
-<%
- @flowplayer_used = true
-%>
-<%
- else
-%>
- <object class='externalfilterinline' name='<%= name %>' data='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name) %>' type='<%= content_type %>' title="<%= h source %>">
- <embed name='<%= name %>-2' src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name) %>' type='<%= content_type %>' title="<%= h source %>" />
- </object>
-<%
- end
-%>
- <br/>
- <span class='wiki_page'>Goto source: [[<%= wiki_name %>]]</span>
-</div>
-<%
- content_for :header_tags do
-%>
-<%
- if not @stylesheets_included
- @stylesheets_included = true
-%>
- <%= stylesheet_link_tag "wiki_external_filter.css", :plugin => "wiki_external_filter", :media => :all %>
-<%
- end
-%>
-<%
- if @flowplayer_used
- if not @flowplayer_scripts_included
- @flowplayer_scripts_included = true
-%>
- <%= javascript_include_tag 'flowplayer.min.js', :plugin => 'wiki_external_filter' %>
- <script language="JavaScript">
- //<![CDATA[
- window.onload = function () {
- flowplayer("a.flowplayer-video", "<%= ActionController::Base.relative_url_root + Engines::RailsExtensions::AssetHelpers.plugin_asset_path('wiki_external_filter', 'javascripts', 'flowplayer.swf') %>", { clip: { bufferLength: 1 } });
- };
- //]]>
- </script>
-<%
- end
- end
- end
-%>
diff --git a/app/views/wiki_external_filter/macro_flash-video.html.erb b/app/views/wiki_external_filter/macro_flash-video.html.erb
new file mode 100644
index 0000000..d390975
--- /dev/null
+++ b/app/views/wiki_external_filter/macro_flash-video.html.erb
@@ -0,0 +1,22 @@
+<%
+ require 'RMagick'
+ image = Magick::Image::from_blob(content[0]).first
+%>
+ <a class='flowplayer-video<%= render_type == 'inline' ? " externalfilterinline" : "" %>' href='<%= ActionController::Base.relative_url_root + "/wiki_external_filter/#{macro}.flv?name=#{name}" %>' title='<%= h source %>' style='display:block;width:<%= image.columns %>px;height:<%= image.rows + 24 %>px;background-image:url(<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>);background-repeat:no-repeat'><%= image_tag 'play_large.png', :plugin => 'wiki_external_filter', :style => "display:block;position:relative;left:#{image.columns / 2 - 83 / 2}px;top:#{image.rows / 2 - 83 / 2}px" %></a>
+<%
+ content_for :header_tags do
+ if not @flowplayer_scripts_included
+ @flowplayer_scripts_included = true
+%>
+ <%= javascript_include_tag 'flowplayer.min.js', :plugin => 'wiki_external_filter' %>
+ <script language="JavaScript" type="text/javascript">
+ //<![CDATA[
+ window.onload = function () {
+ flowplayer("a.flowplayer-video", "<%= ActionController::Base.relative_url_root + Engines::RailsExtensions::AssetHelpers.plugin_asset_path('wiki_external_filter', 'javascripts', 'flowplayer.swf') %>", { clip: { bufferLength: 1 } });
+ };
+ //]]>
+ </script>
+<%
+ end
+ end
+%>
diff --git a/app/views/wiki_external_filter/macro_image.html.erb b/app/views/wiki_external_filter/macro_image.html.erb
new file mode 100644
index 0000000..dfb52fd
--- /dev/null
+++ b/app/views/wiki_external_filter/macro_image.html.erb
@@ -0,0 +1 @@
+<img <%= render_type == 'inline' ? "class='externalfilterinline'" : "" %> src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>' alt="<%= h source %>" />
diff --git a/app/views/wiki_external_filter/macro_inline.html.erb b/app/views/wiki_external_filter/macro_inline.html.erb
deleted file mode 100644
index 8dd3c2f..0000000
--- a/app/views/wiki_external_filter/macro_inline.html.erb
+++ /dev/null
@@ -1,61 +0,0 @@
-<%
- case content_type
- when /image\// then
-%>
- <img class='externalfilterinline' src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>' alt="<%= h source %>" />
-<%
- when /text\/plain/ then
-%>
- <pre class='externalfilterinline'><%= h content[0] %></pre>
-<%
- when /\/.*(x|ht)ml/ then
-%>
- <div class='externalfilterinline'><%= content[0] %></div>
-<%
- when /video\/x\-flv/ then
- require 'RMagick'
- image = Magick::Image::from_blob(content[0]).first
-%>
- <a class='flowplayer-video externalfilterinline' href='<%= ActionController::Base.relative_url_root + "/wiki_external_filter/video.flv?name=#{name}" %>' alt='<%= h source %>' style='display:block;width:<%= image.columns %>px;height:<%= image.rows + 24 %>px;background-image:url(<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>);background-repeat:no-repeat'><%= image_tag 'play_large.png', :plugin => 'wiki_external_filter', :style => "display:block;position:relative;left:#{image.columns / 2 - 83 / 2}px;top:#{image.rows / 2 - 83 / 2}px" %></a>
-
-<%
- @flowplayer_used = true
-%>
-<%
- else
-%>
- <object class='externalfilterinline' name='<%= name %>' data='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>' type='<%= content_type %>' title="<%= h source %>">
- <embed name='<%= name %>-2' src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>' type='<%= content_type %>' title="<%= h source %>" />
- </object>
-<%
- end
-%>
-<%
- content_for :header_tags do
-%>
-<%
- if not @stylesheets_included
- @stylesheets_included = true
-%>
- <%= stylesheet_link_tag "wiki_external_filter.css", :plugin => "wiki_external_filter", :media => :all %>
-<%
- end
-%>
-<%
- if @flowplayer_used
- if not @flowplayer_scripts_included
- @flowplayer_scripts_included = true
-%>
- <%= javascript_include_tag 'flowplayer.min.js', :plugin => 'wiki_external_filter' %>
- <script language="JavaScript">
- //<![CDATA[
- window.onload = function () {
- flowplayer("a.flowplayer-video", "<%= ActionController::Base.relative_url_root + Engines::RailsExtensions::AssetHelpers.plugin_asset_path('wiki_external_filter', 'javascripts', 'flowplayer.swf') %>", { clip: { bufferLength: 1 } });
- };
- //]]>
- </script>
-<%
- end
- end
- end
-%>
diff --git a/app/views/wiki_external_filter/macro_svg.html.erb b/app/views/wiki_external_filter/macro_svg.html.erb
new file mode 100644
index 0000000..ee9f751
--- /dev/null
+++ b/app/views/wiki_external_filter/macro_svg.html.erb
@@ -0,0 +1,27 @@
+<img class='svg <%= render_type == 'inline' ? "externalfilterinline" : "" %>' src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>' alt='<%= h source %>' />
+<object class='svgobject <%= render_type == 'inline' ? "externalfilterinline" : "" %>' name='<%= name %>' data='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 0) %>' type='<%= content_types[0] %>' title="<%= h source %>">
+<%
+ if content.size > 1
+%>
+ <img<%= render_type == 'inline' ? " class='externalfilterinline'" : "" %> src='<%= url_for(:controller => 'wiki_external_filter', :action => 'filter', :macro => macro, :name => name, :index => 1) %>' alt='<%= h source %>' />
+<%
+ end
+%>
+</object>
+<%
+ content_for :header_tags do
+ if not @svg_scripts_included
+ @svg_scripts_included = true
+%>
+ <%= javascript_include_tag 'css_browser_selector.js', :plugin => 'wiki_external_filter' %>
+ <style type="text/css">
+ .svgobject { display: none }
+ .ie .svgobject { display: inline }
+ .ie img.svg { display: none }
+ .gecko .svgobject { display: inline }
+ .gecko img.svg { display: none }
+ </style>
+<%
+ end
+ end
+%>
diff --git a/app/views/wiki_external_filter/macro_text.html.erb b/app/views/wiki_external_filter/macro_text.html.erb
new file mode 100644
index 0000000..a1628b4
--- /dev/null
+++ b/app/views/wiki_external_filter/macro_text.html.erb
@@ -0,0 +1 @@
+<span<%= render_type == 'inline' ? " class='externalfilterinline'" : "" %>><%= h content[0] %></span>