asciidoctor-diagram 1.1.6 → 1.2.0.preview.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +2 -39
- data/examples/README.adoc +15 -3
- data/lib/asciidoctor-diagram.rb +1 -3
- data/lib/asciidoctor-diagram/ditaa.rb +2 -2
- data/lib/asciidoctor-diagram/ditaa/extension.rb +23 -21
- data/lib/asciidoctor-diagram/ditaa/generator.rb +31 -0
- data/lib/asciidoctor-diagram/graphviz.rb +2 -2
- data/lib/asciidoctor-diagram/graphviz/extension.rb +32 -9
- data/lib/asciidoctor-diagram/plantuml.rb +3 -2
- data/lib/asciidoctor-diagram/plantuml/extension.rb +31 -15
- data/lib/asciidoctor-diagram/plantuml/generator.rb +25 -11
- data/lib/asciidoctor-diagram/util/diagram.rb +76 -96
- data/lib/asciidoctor-diagram/util/java_jruby.rb +0 -4
- data/lib/asciidoctor-diagram/util/java_rjb.rb +0 -8
- data/lib/asciidoctor-diagram/util/svg.rb +23 -19
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/lib/plantuml.jar +0 -0
- data/spec/ditaa_spec.rb +3 -3
- data/spec/graphviz_spec.rb +3 -28
- data/spec/plantuml_spec.rb +6 -147
- data/spec/test_helper.rb +3 -10
- metadata +19 -29
- data/examples/build_example.rb +0 -9
- data/lib/asciidoctor-diagram/blockdiag.rb +0 -8
- data/lib/asciidoctor-diagram/blockdiag/extension.rb +0 -18
- data/lib/asciidoctor-diagram/shaape.rb +0 -8
- data/lib/asciidoctor-diagram/shaape/extension.rb +0 -16
- data/lib/asciidoctor-diagram/util/cli_generator.rb +0 -40
- data/lib/asciidoctor-diagram/util/which.rb +0 -14
- data/spec/blockdiag_spec.rb +0 -183
- data/spec/shaape_spec.rb +0 -227
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9105f3a758a381ee41273031fcdabb5c6e6c7c7
|
4
|
+
data.tar.gz: 9b8a9602d6832d46bb9d8e6b483a390b1d491c34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d2ef13b181388d1737a021e163ba3376da41ac68bfde8974a3ff2e4ba4ad4ccc8ee142b12a0bf0ee9bc2317d59ebe043d8f49d3971d5a9a0b0e55ca78c62c6
|
7
|
+
data.tar.gz: 6fea7bf3a26ed2a07c5548ca90dc93fcbdaa175815bbf32f6bcb85eacb7d864ec692b25035f87c61d043692fe37647267af02b85eb1f566abf543c362dfc4b8b
|
data/CHANGELOG.adoc
CHANGED
@@ -1,47 +1,10 @@
|
|
1
1
|
= Asciidoctor-diagram Changelog
|
2
2
|
|
3
|
-
== 1.
|
3
|
+
== 1.2.0
|
4
4
|
|
5
5
|
Enhancements::
|
6
6
|
|
7
|
-
* Updated
|
8
|
-
* Add support for Shaape diagrams (requires Shaape to be installed separately)
|
9
|
-
* Add support for Blockdiag diagrams (requires Blockdiag to be installed separately)
|
10
|
-
* Add support for Actdiag diagrams (requires Actdiag to be installed separately)
|
11
|
-
* Add support for Seqdiag diagrams (requires Seqdiag to be installed separately)
|
12
|
-
* Add support for Nwdiag diagrams (requires Nwdiag to be installed separately)
|
13
|
-
|
14
|
-
Bug Fixes::
|
15
|
-
* Issue #38: Resolved Graphviz syntax errors with certain diagrams
|
16
|
-
|
17
|
-
== 1.1.5
|
18
|
-
|
19
|
-
Enhancements::
|
20
|
-
|
21
|
-
* Use the output directory (outdir attribute) as base directory if it's specified.
|
22
|
-
* Do not auto-generate width/height attributes when outputting to a non-HTML backend. This resolves issues with
|
23
|
-
oversized images in docbook output.
|
24
|
-
|
25
|
-
== 1.1.4
|
26
|
-
|
27
|
-
Bug Fixes::
|
28
|
-
|
29
|
-
* Under CRuby in combination with certain Java versions a FileNotFoundException could be triggered due to incorrect
|
30
|
-
method selection by RJB
|
31
|
-
|
32
|
-
== 1.1.3
|
33
|
-
|
34
|
-
Bug Fixes::
|
35
|
-
|
36
|
-
* Image regeneration logic did not always correctly detect cases where images did not need to be updated
|
37
|
-
|
38
|
-
== 1.1.2
|
39
|
-
|
40
|
-
Bug Fixes::
|
41
|
-
|
42
|
-
* Fix corrupt PNG images on Windows
|
43
|
-
* Fix NoSuchMethodError in block macro processing when target image file already existed
|
44
|
-
* Respect target attribute in block macros
|
7
|
+
* Updated to Asciidoctor 1.5.0
|
45
8
|
|
46
9
|
== 1.1.1
|
47
10
|
|
data/examples/README.adoc
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
= Asciidoctor-diagram Examples
|
2
2
|
|
3
3
|
This directory contains a number of example files that illustrate how to use the asciidoctor-diagram extension.
|
4
|
-
|
5
|
-
In order to
|
6
|
-
This
|
4
|
+
|
5
|
+
In order to build the examples correctly the asciidoctor-diagram extension should be loaded.
|
6
|
+
This can be done using bundler by running
|
7
|
+
|
8
|
+
----
|
9
|
+
bundle exec asciidoctor -r asciidoctor-diagram <asciidoc file>
|
10
|
+
----
|
11
|
+
|
12
|
+
If you do not want to use bundler you can alternatively run
|
13
|
+
|
14
|
+
----
|
15
|
+
asciidoctor -r asciidoctor-diagram -I ../lib <asciidoc file>
|
16
|
+
----
|
17
|
+
|
18
|
+
This variant requires you to explicitly specify the load path from which asciidoctor-diagram can be loaded.
|
data/lib/asciidoctor-diagram.rb
CHANGED
@@ -3,6 +3,6 @@ require_relative 'version'
|
|
3
3
|
|
4
4
|
Asciidoctor::Extensions.register do
|
5
5
|
require_relative 'ditaa/extension'
|
6
|
-
block
|
7
|
-
block_macro
|
6
|
+
block Asciidoctor::Diagram::DitaaBlock, :ditaa
|
7
|
+
block_macro Asciidoctor::Diagram::DitaaBlockMacro, :ditaa
|
8
8
|
end
|
@@ -1,35 +1,37 @@
|
|
1
1
|
require_relative '../util/diagram'
|
2
|
-
require_relative '
|
2
|
+
require_relative 'generator'
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
module
|
7
|
-
|
8
|
-
Java.classpath << DITAA_JAR_PATH
|
6
|
+
module DitaaBase
|
7
|
+
include DitaaGenerator
|
9
8
|
|
10
|
-
|
11
|
-
Java.load
|
9
|
+
private
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
bis.close
|
20
|
-
bos.close
|
21
|
-
|
22
|
-
result = Java.string_from_java_bytes(bos.toByteArray)
|
11
|
+
def register_formats
|
12
|
+
register_format(:png, :image) do |c|
|
13
|
+
ditaa(c)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
23
17
|
|
24
|
-
|
18
|
+
class DitaaBlock < Asciidoctor::Extensions::BlockProcessor
|
19
|
+
include DiagramProcessorBase
|
20
|
+
include DitaaBase
|
25
21
|
|
26
|
-
|
22
|
+
def initialize name = nil, config = {}
|
23
|
+
super
|
24
|
+
register_formats()
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
class DitaaBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
29
|
+
include DiagramProcessorBase
|
30
|
+
include DitaaBase
|
31
|
+
|
32
|
+
def initialize name = nil, config = {}
|
33
|
+
super
|
34
|
+
register_formats()
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../util/java'
|
2
|
+
|
3
|
+
module Asciidoctor
|
4
|
+
module Diagram
|
5
|
+
module DitaaGenerator
|
6
|
+
private
|
7
|
+
|
8
|
+
DITAA_JAR_PATH = File.expand_path File.join('../..', 'ditaamini0_9.jar'), File.dirname(__FILE__)
|
9
|
+
Java.classpath << DITAA_JAR_PATH
|
10
|
+
|
11
|
+
def ditaa(code)
|
12
|
+
Java.load
|
13
|
+
|
14
|
+
args = ['-e', 'UTF-8']
|
15
|
+
|
16
|
+
bytes = code.encode(Encoding::UTF_8).bytes.to_a
|
17
|
+
bis = Java.java.io.ByteArrayInputStream.new(Java.array_to_java_array(bytes, :byte))
|
18
|
+
bos = Java.java.io.ByteArrayOutputStream.new
|
19
|
+
result_code = Java.org.stathissideris.ascii2image.core.CommandLineConverter.convert(Java.array_to_java_array(args, :string), bis, bos)
|
20
|
+
bis.close
|
21
|
+
bos.close
|
22
|
+
|
23
|
+
result = Java.string_from_java_bytes(bos.toByteArray)
|
24
|
+
|
25
|
+
raise "Ditaa image generation failed: #{result}" unless result_code == 0
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,6 +3,6 @@ require_relative 'version'
|
|
3
3
|
|
4
4
|
Asciidoctor::Extensions.register do
|
5
5
|
require_relative 'graphviz/extension'
|
6
|
-
block
|
7
|
-
block_macro
|
6
|
+
block Asciidoctor::Diagram::GraphvizBlock, :graphviz
|
7
|
+
block_macro Asciidoctor::Diagram::GraphvizBlockMacro, :graphviz
|
8
8
|
end
|
@@ -1,18 +1,41 @@
|
|
1
|
-
require_relative '../util/cli_generator'
|
2
1
|
require_relative '../util/diagram'
|
2
|
+
require_relative '../plantuml/generator'
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
module
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
module GraphvizBase
|
7
|
+
include PlantUmlGenerator
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def register_formats
|
12
|
+
register_format(:png, :image) do |c, p|
|
13
|
+
plantuml(p, c, 'dot')
|
14
|
+
end
|
15
|
+
register_format(:svg, :image) do |c, p|
|
16
|
+
plantuml(p, c, 'dot', '-tsvg')
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
20
|
+
|
21
|
+
class GraphvizBlock < Asciidoctor::Extensions::BlockProcessor
|
22
|
+
include DiagramProcessorBase
|
23
|
+
include GraphvizBase
|
24
|
+
|
25
|
+
def initialize name = nil, config = {}
|
26
|
+
super
|
27
|
+
register_formats()
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class GraphvizBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
32
|
+
include DiagramProcessorBase
|
33
|
+
include GraphvizBase
|
34
|
+
|
35
|
+
def initialize name = nil, config = {}
|
36
|
+
super
|
37
|
+
register_formats()
|
38
|
+
end
|
39
|
+
end
|
17
40
|
end
|
18
41
|
end
|
@@ -3,6 +3,7 @@ require_relative 'version'
|
|
3
3
|
|
4
4
|
Asciidoctor::Extensions.register do
|
5
5
|
require_relative 'plantuml/extension'
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
block Asciidoctor::Diagram::PlantUmlBlock, :plantuml
|
8
|
+
block_macro Asciidoctor::Diagram::PlantUmlBlockMacro, :plantuml
|
8
9
|
end
|
@@ -3,25 +3,41 @@ require_relative 'generator'
|
|
3
3
|
|
4
4
|
module Asciidoctor
|
5
5
|
module Diagram
|
6
|
-
|
7
|
-
|
8
|
-
config_args = []
|
9
|
-
config = parent.document.attributes['plantumlconfig']
|
10
|
-
if config
|
11
|
-
config_args += ['-config', File.expand_path(config, parent.document.attributes['docdir'])]
|
12
|
-
end
|
6
|
+
module PlantUmlBase
|
7
|
+
include PlantUmlGenerator
|
13
8
|
|
14
|
-
|
15
|
-
end
|
9
|
+
private
|
16
10
|
|
17
|
-
|
18
|
-
|
11
|
+
def register_formats()
|
12
|
+
register_format(:png, :image) do |c, p|
|
13
|
+
plantuml(p, c, 'uml')
|
14
|
+
end
|
15
|
+
register_format(:svg, :image) do |c, p|
|
16
|
+
plantuml(p, c, 'uml', '-tsvg')
|
17
|
+
end
|
18
|
+
register_format(:txt, :literal) do |c, p|
|
19
|
+
plantuml(p, c, 'uml', '-tutxt')
|
20
|
+
end
|
19
21
|
end
|
20
|
-
|
21
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
class PlantUmlBlock < Asciidoctor::Extensions::BlockProcessor
|
25
|
+
include DiagramProcessorBase
|
26
|
+
include PlantUmlBase
|
27
|
+
|
28
|
+
def initialize name = nil, config = {}
|
29
|
+
super
|
30
|
+
register_formats()
|
22
31
|
end
|
23
|
-
|
24
|
-
|
32
|
+
end
|
33
|
+
|
34
|
+
class PlantUmlBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
|
35
|
+
include DiagramProcessorBase
|
36
|
+
include PlantUmlBase
|
37
|
+
|
38
|
+
def initialize name = nil, config = {}
|
39
|
+
super
|
40
|
+
register_formats()
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative '../util/java'
|
2
|
-
require_relative '../util/which'
|
3
2
|
|
4
3
|
module Asciidoctor
|
5
4
|
module Diagram
|
@@ -9,10 +8,10 @@ module Asciidoctor
|
|
9
8
|
PLANTUML_JAR_PATH = File.expand_path File.join('../..', 'plantuml.jar'), File.dirname(__FILE__)
|
10
9
|
Java.classpath << PLANTUML_JAR_PATH
|
11
10
|
|
12
|
-
def
|
11
|
+
def plantuml(parent, code, tag, *flags)
|
13
12
|
unless @graphvizdot
|
14
13
|
@graphvizdot = parent.document.attributes['graphvizdot']
|
15
|
-
@graphvizdot =
|
14
|
+
@graphvizdot = which('dot') unless @graphvizdot && File.executable?(@graphvizdot)
|
16
15
|
raise "Could not find the Graphviz 'dot' executable in PATH; add it to the PATH or specify its location using the 'graphvizdot' document attribute" unless @graphvizdot
|
17
16
|
end
|
18
17
|
|
@@ -22,20 +21,35 @@ module Asciidoctor
|
|
22
21
|
|
23
22
|
flags += ['-charset', 'UTF-8', '-failonerror', '-graphvizdot', @graphvizdot]
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
config_file = parent.document.attributes['plantumlconfig']
|
25
|
+
if config_file
|
26
|
+
flags += ['-config', File.expand_path(config_file, parent.document.attributes['docdir'])]
|
27
|
+
end
|
28
|
+
|
29
|
+
option = Java.net.sourceforge.plantuml.Option.new(Java.array_to_java_array(flags, :string))
|
30
|
+
source_reader = Java.net.sourceforge.plantuml.SourceStringReader.new(
|
31
|
+
Java.net.sourceforge.plantuml.preproc.Defines.new(),
|
32
|
+
code,
|
33
|
+
option.getConfig()
|
31
34
|
)
|
32
35
|
|
33
|
-
bos = Java.
|
34
|
-
ps = Java.
|
36
|
+
bos = Java.java.io.ByteArrayOutputStream.new
|
37
|
+
ps = Java.java.io.PrintStream.new(bos)
|
35
38
|
source_reader.generateImage(ps, 0, option.getFileFormatOption())
|
36
39
|
ps.close
|
37
40
|
Java.string_from_java_bytes(bos.toByteArray)
|
38
41
|
end
|
42
|
+
|
43
|
+
def which(cmd)
|
44
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
45
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
46
|
+
exts.each { |ext|
|
47
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
48
|
+
return exe if File.executable? exe
|
49
|
+
}
|
50
|
+
end
|
51
|
+
nil
|
52
|
+
end
|
39
53
|
end
|
40
54
|
end
|
41
55
|
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'asciidoctor/extensions'
|
2
2
|
require 'digest'
|
3
3
|
require 'json'
|
4
|
-
require 'fileutils'
|
5
4
|
require_relative 'java'
|
6
5
|
require_relative 'png'
|
7
6
|
require_relative 'svg'
|
8
7
|
|
9
8
|
module Asciidoctor
|
10
9
|
module Diagram
|
11
|
-
module
|
10
|
+
module DiagramProcessorBase
|
12
11
|
IMAGE_PARAMS = {
|
13
12
|
:svg => {
|
14
13
|
:encoding => Encoding::UTF_8,
|
@@ -20,81 +19,42 @@ module Asciidoctor
|
|
20
19
|
}
|
21
20
|
}
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
# Registers a supported format. The first registered format becomes the default format for the block processor.
|
26
|
-
#
|
27
|
-
# +format+ is a symbol with the format name
|
28
|
-
# +type+ is a symbol and should be either :image or :literal
|
29
|
-
# +block+ is a block that produces the diagrams from code. The block receives the parent asciidoc block and the diagram code as arguments
|
30
|
-
#
|
31
|
-
def register_format(format, type, &block)
|
32
|
-
unless @default_format
|
33
|
-
@default_format = format
|
34
|
-
end
|
22
|
+
def self.included(base)
|
23
|
+
base.option :pos_attrs, ['target', 'format']
|
35
24
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
end
|
25
|
+
if base.ancestors.include?(Asciidoctor::Extensions::BlockProcessor)
|
26
|
+
base.option :contexts, [:listing, :literal, :open]
|
27
|
+
base.option :content_model, :simple
|
41
28
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.included base
|
52
|
-
base.extend ClassMethods
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.define_processors(name, &init)
|
56
|
-
block = Class.new(Asciidoctor::Extensions::BlockProcessor) do
|
57
|
-
include DiagramProcessor
|
58
|
-
|
59
|
-
option :pos_attrs, ['target', 'format']
|
60
|
-
option :contexts, [:listing, :literal, :open]
|
61
|
-
option :content_model, :simple
|
62
|
-
|
63
|
-
def process(parent, reader, attributes)
|
64
|
-
generate_block(parent, ReaderSource.new(reader), attributes)
|
29
|
+
base.instance_eval do
|
30
|
+
alias_method :process, :process_block
|
31
|
+
end
|
32
|
+
else
|
33
|
+
base.instance_eval do
|
34
|
+
alias_method :process, :process_macro
|
65
35
|
end
|
66
|
-
|
67
|
-
self.instance_eval &init
|
68
36
|
end
|
69
37
|
|
70
|
-
|
71
|
-
include DiagramProcessor
|
72
|
-
|
73
|
-
option :pos_attrs, ['target', 'format']
|
74
|
-
|
75
|
-
def process(parent, target, attributes)
|
76
|
-
source = FileSource.new(File.expand_path(target, parent.document.attributes['docdir']))
|
77
|
-
attributes['target'] ||= File.basename(target, File.extname(target))
|
78
|
-
|
79
|
-
generate_block(parent, source, attributes)
|
80
|
-
end
|
38
|
+
end
|
81
39
|
|
82
|
-
|
83
|
-
|
40
|
+
def process_macro(parent, target, attributes)
|
41
|
+
source = FileSource.new(File.expand_path(target, parent.document.attributes['docdir']))
|
42
|
+
attributes['target'] = File.basename(target, File.extname(target))
|
84
43
|
|
85
|
-
|
86
|
-
Asciidoctor::Diagram.const_set("#{name}BlockMacro", block_macro)
|
44
|
+
generate_block(parent, source, attributes)
|
87
45
|
end
|
88
46
|
|
89
|
-
|
47
|
+
def process_block(parent, reader, attributes)
|
48
|
+
generate_block(parent, ReaderSource.new(reader), attributes)
|
49
|
+
end
|
90
50
|
|
91
51
|
def generate_block(parent, source, attributes)
|
92
|
-
format = attributes.delete('format') ||
|
52
|
+
format = attributes.delete('format') || @default_format
|
93
53
|
format = format.to_sym if format.respond_to?(:to_sym)
|
94
54
|
|
95
55
|
raise "Format undefined" unless format
|
96
56
|
|
97
|
-
generator_info =
|
57
|
+
generator_info = formats[format]
|
98
58
|
|
99
59
|
raise "#{self.class.name} does not support output format #{format}" unless generator_info
|
100
60
|
|
@@ -108,41 +68,65 @@ module Asciidoctor
|
|
108
68
|
end
|
109
69
|
end
|
110
70
|
|
71
|
+
private
|
72
|
+
|
73
|
+
#
|
74
|
+
# Registers a supported format. The first registered format becomes the default format for the block processor.
|
75
|
+
#
|
76
|
+
# +format+ is a symbol with the format name
|
77
|
+
# +type+ is a symbol and should be either :image or :literal
|
78
|
+
# +block+ is a block that produces the diagrams from code. The block receives the parent asciidoc block and the diagram code as arguments
|
79
|
+
#
|
80
|
+
def register_format(format, type, &block)
|
81
|
+
unless @default_format
|
82
|
+
@default_format = format
|
83
|
+
end
|
84
|
+
|
85
|
+
formats[format] = {
|
86
|
+
:type => type,
|
87
|
+
:generator => block
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def formats
|
92
|
+
@formats ||= {}
|
93
|
+
end
|
94
|
+
|
111
95
|
def create_image_block(parent, source, attributes, format, generator_info)
|
112
96
|
target = attributes.delete('target')
|
113
97
|
|
114
98
|
image_name = "#{target || ('diag-' + source.checksum)}.#{format}"
|
115
|
-
image_dir = File.expand_path(parent.document.attributes['imagesdir'] || '', parent.document.attributes['
|
99
|
+
image_dir = File.expand_path(parent.document.attributes['imagesdir'] || '', parent.document.attributes['docdir'])
|
116
100
|
image_file = File.expand_path(image_name, image_dir)
|
117
|
-
metadata_file = File.expand_path("#{image_name}.cache", image_dir)
|
118
101
|
|
119
|
-
if
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
102
|
+
if source.newer_than?(image_file)
|
103
|
+
cache_file = File.expand_path("#{image_name}.cache", image_dir)
|
104
|
+
|
105
|
+
if File.exists? cache_file
|
106
|
+
metadata = File.open(cache_file, 'r') { |f| JSON.load f }
|
107
|
+
else
|
108
|
+
metadata = nil
|
109
|
+
end
|
124
110
|
|
125
|
-
|
126
|
-
|
111
|
+
unless File.exists?(image_file) && metadata && metadata['checksum'] == source.checksum
|
112
|
+
params = IMAGE_PARAMS[format]
|
127
113
|
|
128
|
-
|
114
|
+
result = generator_info[:generator].call(source.code, parent)
|
129
115
|
|
130
|
-
|
116
|
+
result.force_encoding(params[:encoding])
|
131
117
|
|
132
|
-
|
133
|
-
|
118
|
+
metadata = {'checksum' => source.checksum}
|
119
|
+
metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
|
134
120
|
|
135
|
-
|
136
|
-
|
137
|
-
|
121
|
+
File.open(image_file, 'w') { |f| f.write result }
|
122
|
+
File.open(cache_file, 'w') { |f| JSON.dump(metadata, f) }
|
123
|
+
end
|
138
124
|
end
|
139
125
|
|
140
126
|
attributes['target'] = image_name
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
attributes['alt'] ||= if title_text = attributes['title']
|
127
|
+
attributes['width'] ||= metadata['width'] if metadata['width']
|
128
|
+
attributes['height'] ||= metadata['height'] if metadata['height']
|
129
|
+
attributes['alt'] ||= if (title_text = attributes['title'])
|
146
130
|
title_text
|
147
131
|
elsif target
|
148
132
|
(File.basename target, (File.extname target) || '').tr '_-', ' '
|
@@ -170,12 +154,12 @@ module Asciidoctor
|
|
170
154
|
end
|
171
155
|
|
172
156
|
class Source
|
173
|
-
def
|
174
|
-
|
157
|
+
def newer_than?(image)
|
158
|
+
true
|
175
159
|
end
|
176
160
|
|
177
|
-
def
|
178
|
-
|
161
|
+
def checksum
|
162
|
+
@checksum ||= compute_checksum(code)
|
179
163
|
end
|
180
164
|
|
181
165
|
private
|
@@ -192,12 +176,8 @@ module Asciidoctor
|
|
192
176
|
@reader = reader
|
193
177
|
end
|
194
178
|
|
195
|
-
def newer_than?(image_file)
|
196
|
-
true
|
197
|
-
end
|
198
|
-
|
199
179
|
def code
|
200
|
-
@code ||= @reader.lines.join
|
180
|
+
@code ||= @reader.lines.join("\n")
|
201
181
|
end
|
202
182
|
end
|
203
183
|
|
@@ -206,13 +186,13 @@ module Asciidoctor
|
|
206
186
|
@file_name = file_name
|
207
187
|
end
|
208
188
|
|
209
|
-
def newer_than?(image_file)
|
210
|
-
File.mtime(@file_name) > File.mtime(image_file)
|
211
|
-
end
|
212
|
-
|
213
189
|
def code
|
214
190
|
@code ||= File.read(@file_name)
|
215
191
|
end
|
192
|
+
|
193
|
+
def newer_than?(image)
|
194
|
+
!File.exists?(image) || File.mtime(@file_name) > File.mtime(image)
|
195
|
+
end
|
216
196
|
end
|
217
197
|
end
|
218
198
|
end
|