Skip to content

Commit

Permalink
asciidoctor#118 Add support for Erd
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnve committed Sep 26, 2016
1 parent c2a8d13 commit a296714
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ before_install:
- gem --version
- gem install bundler
- sudo apt-get update -qq
install:
- wget -O phantomjs-2.1.1-linux-x86_64.tar.bz2 https://github.com/pepijnve/asciidoctor-diagram-build/blob/master/linux/x86_64/phantomjs-2.1.1-linux-x86_64.tar.bz2?raw=true
- tar jxf phantomjs-2.1.1-linux-x86_64.tar.bz2
- export PHANTOMJS_2=$PWD/phantomjs-2.1.1-linux-x86_64/bin/phantomjs
- wget -O phantomjs-1.9.8-linux-x86_64.tar.bz2 https://github.com/pepijnve/asciidoctor-diagram-build/blob/master/linux/x86_64/phantomjs-1.9.8-linux-x86_64.tar.bz2?raw=true
- tar jxf phantomjs-1.9.8-linux-x86_64.tar.bz2
- export PHANTOMJS_19=$PWD/phantomjs-1.9.8-linux-x86_64/bin/phantomjs
install:
- sudo apt-get install -qq graphviz
- sudo apt-get install -qq python-gtk2
- pip install --user blockdiag actdiag seqdiag nwdiag
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Enhancements::

* Apply anti-aliasing to blockdiag generated images
* Issue #118: Add support for Erd.

Bug Fixes::

Expand Down
5 changes: 4 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ifndef::env-site[:status:]
:uri-blockdiag: http://blockdiag.com
:uri-ditaa: http://ditaa.sourceforge.net/
:uri-dot: http://www.graphviz.org/content/dot-language
:uri-erd: https://github.com/BurntSushi/erd
:uri-graphviz: http://www.graphviz.org
:uri-imagemagick: http://www.imagemagick.org
:uri-java: http://java.sun.com
Expand Down Expand Up @@ -108,6 +109,7 @@ The following diagram types and output formats are available:
|{uri-actdiag}[actdiag] | |{check}|{check}|
|{uri-blockdiag}[blockdiag] | |{check}|{check}|
|{uri-ditaa}[ditaa] | |{check}| |
|{uri-erd}[erd] | |{check}|{check}|
|{uri-dot}[graphviz] | |{check}|{check}|
|<<meme,meme>> |{check}|{check}| |
|{uri-mermaid}[mermaid] | |{check}|{check}|
Expand Down Expand Up @@ -229,7 +231,7 @@ or load and register each extension individually.
require 'asciidoctor-diagram/<extension_name>'
----

`<extension_name>` can be one of `blockdiag`, `ditaa`, `graphviz`, `meme`, `mermaid`, `plantuml`, `shaape`, or `wavedrom`.
`<extension_name>` can be one of `blockdiag`, `ditaa`, `erd`, `graphviz`, `meme`, `mermaid`, `plantuml`, `shaape`, or `wavedrom`.

Requiring one or more of these files will automatically register the extensions for all processed documents.

Expand Down Expand Up @@ -275,6 +277,7 @@ The following table lists the tools that are required for each diagram type, the
|actdiag |{uri-actdiag}[ActDiag] |`actdiag`
|blockdiag |{uri-blockdiag}[BlockDiag] |`blockdiag`
|ditaa |{uri-java}[Java] |`java`
|erd |{uri-erd}[Erd] |`erd`
|graphviz |{uri-graphviz}[GraphViz] |`dot` or `graphvizdot`
|meme |{uri-imagemagick}[ImageMagick] |`convert` and `identify`
|mermaid |{uri-mermaid}[Mermaid] |`mermaid`
Expand Down
1 change: 1 addition & 0 deletions lib/asciidoctor-diagram.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative 'asciidoctor-diagram/blockdiag'
require_relative 'asciidoctor-diagram/ditaa'
require_relative 'asciidoctor-diagram/erd'
require_relative 'asciidoctor-diagram/graphviz'
require_relative 'asciidoctor-diagram/meme'
require_relative 'asciidoctor-diagram/mermaid'
Expand Down
7 changes: 7 additions & 0 deletions lib/asciidoctor-diagram/erd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_relative 'extensions'

Asciidoctor::Extensions.register do
require_relative 'erd/extension'
block Asciidoctor::Diagram::ErdBlockProcessor, :erd
block_macro Asciidoctor::Diagram::ErdBlockMacroProcessor, :erd
end
42 changes: 42 additions & 0 deletions lib/asciidoctor-diagram/erd/extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative '../extensions'
require_relative '../util/cli_generator'
require_relative '../util/platform'
require_relative '../util/which'

module Asciidoctor
module Diagram
# @private
module Erd
include Which

def self.included(mod)
[:png, :svg].each do |f|
mod.register_format(f, :image) do |parent, source|
erd(parent, source, f)
end
end
end

def erd(parent, source, format)
erd_path = which(parent, 'erd')
dot_path = which(parent, 'dot', :alt_attrs => ['graphvizdot'])

dot_code = CliGenerator.generate_stdin(erd_path, format.to_s, source.to_s) do |tool_path, output_path|
[tool_path, '-o', Platform.native_path(output_path), '-f', 'dot']
end

CliGenerator.generate_stdin(dot_path, format.to_s, dot_code) do |tool_path, output_path|
[tool_path, "-o#{Platform.native_path(output_path)}", "-T#{format.to_s}"]
end
end
end

class ErdBlockProcessor < Extensions::DiagramBlockProcessor
include Erd
end

class ErdBlockMacroProcessor < Extensions::DiagramBlockMacroProcessor
include Erd
end
end
end
Loading

0 comments on commit a296714

Please sign in to comment.