Permalink
Browse files

Support blockdiag, seqdiag, actdiag, nwdiag.

  • Loading branch information...
Yoichi Imai
Yoichi Imai committed Nov 17, 2012
1 parent 8b3d944 commit 1bf98a3e727a0ca2bc25cbde4a8e0ca8cca5dcb0
Showing with 116 additions and 0 deletions.
  1. +16 −0 bin/gollum
  2. +5 −0 lib/gollum/frontend/app.rb
  3. +79 −0 lib/gollum/markup.rb
  4. +16 −0 lib/gollum/wiki.rb
View
@@ -73,6 +73,22 @@ opts = OptionParser.new do |opts|
wiki_options[:mathjax] = true
end
opts.on("--blockdiag-path [PATH]", "Specify the 'blockdiag' path") do |path|
wiki_options[:blockdiag_path] = path
end
opts.on("--seqdiag-path [PATH]", "Specify the 'seqdiag' path") do |path|
wiki_options[:seqdiag_path] = path
end
opts.on("--actdiag-path [PATH]", "Specify the 'actdiag' path") do |path|
wiki_options[:actdiag_path] = path
end
opts.on("--nwdiag-path [PATH]", "Specify the 'nwdiag' path") do |path|
wiki_options[:nwdiag_path] = path
end
opts.on("--user-icons [SOURCE]", "Set the history user icons. Valid values: gravatar, identicon, none. Default: none.") do |source|
wiki_options[:user_icons] = source
end
@@ -286,6 +286,11 @@ def wiki_new
halt 404
end
get %r{tmp/([0-9a-f]{40})\.png} do
path = ::File.expand_path ::File.join wiki_new.path, "tmp/#{params[:captures][0]}.png"
send_file path, :type => 'image/png'
end
get %r{/(.+?)/([0-9a-f]{40})} do
file_path = params[:captures][0]
version = params[:captures][1]
View
@@ -55,6 +55,10 @@ def render(no_follow = false, encoding = nil)
@wiki.sanitizer
data = @data.dup
data = process_blockdiag(data) if @wiki.blockdiag_path
data = process_seqdiag(data) if @wiki.seqdiag_path
data = process_actdiag(data) if @wiki.actdiag_path
data = process_nwdiag(data) if @wiki.nwdiag_path
data = extract_metadata(data)
data = extract_gitcode(data)
data = extract_code(data)
@@ -130,6 +134,81 @@ def process_headers(doc)
[doc, toc]
end
#########################################################################
#
# Blockdiag / Seqdiag / Actdiag / Nwdiag
#
#########################################################################
def process_diag_body(tool_name, tool_path, body)
id = Digest::SHA1.hexdigest(body)
tmp = Tempfile.new('diag')
begin
tmp.write(body)
tmp.close
img_dir = ::File.expand_path(::File.join(@wiki.path, 'tmp'))
::Dir.mkdir(img_dir) unless ::File.exists?(img_dir)
out_path = ::File.join(img_dir, "#{id}.png")
system(tool_path, "-Tpng", "-o", out_path, tmp.path)
if !::File.exists?(out_path) || ::File.size(out_path) == 0 then
return "#{tool_name} error: failed to generate an image."
end
ensure
tmp.unlink
end
img_url = ::File.join(@wiki.base_path, "tmp", "#{id}.png")
return %Q(<img alt="#{tool_name} image" src="#{img_url}">)
end
# Replace blockdiag tags to img tags.
#
# data - The raw String data.
#
# Returns the String data contains img tags.
def process_blockdiag(data)
data.gsub(/\<blockdiag\>\s*(.*?)\s*\<\/blockdiag\>/m) do
process_diag_body("blockdiag", @wiki.blockdiag_path, $1)
end
end
# Replace seqdiag tags to img tags.
#
# data - The raw String data.
#
# Returns the String data contains img tags.
def process_seqdiag(data)
data.gsub(/\<seqdiag\>\s*(.*?)\s*\<\/seqdiag\>/m) do
process_diag_body("seqdiag", @wiki.seqdiag_path, $1)
end
end
# Replace actdiag tags to img tags.
#
# data - The raw String data.
#
# Returns the String data contains img tags.
def process_actdiag(data)
data.gsub(/\<actdiag\>\s*(.*?)\s*\<\/actdiag\>/m) do
process_diag_body("actdiag", @wiki.actdiag_path, $1)
end
end
# Replace nwdiag tags to img tags.
#
# data - The raw String data.
#
# Returns the String data contains img tags.
def process_nwdiag(data)
data.gsub(/\<nwdiag\>\s*(.*?)\s*\<\/nwdiag\>/m) do
process_diag_body("nwdiag", @wiki.nwdiag_path, $1)
end
end
#########################################################################
#
# Tags
View
@@ -199,6 +199,10 @@ def initialize(path, options = {})
@live_preview = options.fetch :live_preview, true
@universal_toc = options.fetch :universal_toc, false
@mathjax = options.fetch :mathjax, false
@blockdiag_path = options.fetch :blockdiag_path, nil
@seqdiag_path = options.fetch :seqdiag_path, nil
@actdiag_path = options.fetch :actdiag_path, nil
@nwdiag_path = options.fetch :nwdiag_path, nil
@show_all = options.fetch :show_all, false
@collapse_tree = options.fetch :collapse_tree, false
@css = options.fetch :css, false
@@ -615,6 +619,18 @@ def history_sanitizer
# Toggles mathjax.
attr_reader :mathjax
# Gets the blockdiag location. Default: nil
attr_reader :blockdiag_path
# Gets the seqdiag location. Default: nil
attr_reader :seqdiag_path
# Gets the actdiag location. Default: nil
attr_reader :actdiag_path
# Gets the nwdiag location. Default: nil
attr_reader :nwdiag_path
# Toggles user icons. Default: 'none'
attr_reader :user_icons

0 comments on commit 1bf98a3

Please sign in to comment.