asciidoctor-diagram 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6929d068c82dc319a53dbcbc30da263e8356923fe2f92e6c4794f166c61b0252
4
- data.tar.gz: 15b20dbe24d572cf174114d3e7cfa6146aa8bb7d46403de6c08284f6819d6e15
3
+ metadata.gz: 682b06be01eb9a3aa29f735c134fe97e813db674f3e7d4a76ae86dcc8241e826
4
+ data.tar.gz: fdf1252fc4f30c1ec56a64bb1928306f1b73341b81442c233111e1fdf8bbc038
5
5
  SHA512:
6
- metadata.gz: 04bec237f4f0529bd12324a1794bb0cd863a82ec27b867572e0f14ff93dbbce4e1e553e48f43fe04fbf1c31cf9af6eaab4e5b7933fb6b820988eade9031653d4
7
- data.tar.gz: 392c0d5e97b6527bb21019f146732a8028681362c5dc19c8c572b2dc06a2c1f528a06d9d3236e292c8166f9acca3be1892bcb35eb0591a3e1c4a40ce10ff9e06
6
+ metadata.gz: b0b928e103aef0f5123cd3a3810c210d28c626493bf536ec7e0ed4363e761df0c2fa23ec8a2a5bbb6c4cc748c2a66d13a846e2d5c06a9b38405d8c7ec0148569
7
+ data.tar.gz: 1387ead776db0d3df332fb585e99be44eb49245f1b32d8be5275034d0de6e9fb89e1085ca485a6336be9e190119e193d6bdebefe44dcfa51eacb277739ee8a91
@@ -1,5 +1,19 @@
1
1
  = Asciidoctor-diagram Changelog
2
2
 
3
+ == 2.0.5
4
+
5
+ Enhancements::
6
+
7
+ * Improve internal target path resolution logic
8
+ * TikZ diagrams can now add content to the LaTeX preamble by setting the `preamble` block attribute to `true`.
9
+ The preamble and diagram should be separated by a line consisting of `\~~~~`. (@colbyn)
10
+ * The `scale` attribute is now passed on to Mermaid. (@gustav-b)
11
+ * Issue #271: Launch UMLet directly using `java` instead of using the UMLet wrapper scripts or executables
12
+
13
+ Bug Fixes::
14
+
15
+ * Issue #294: Treat the first positional parameter of diagram block macros as the desired output format rather than as the target.
16
+
3
17
  == 2.0.4
4
18
 
5
19
  Enhancements::
@@ -144,10 +144,9 @@ module Asciidoctor
144
144
 
145
145
  def create_image_block(parent, source, format, converter)
146
146
  image_name = "#{source.image_name}.#{format}"
147
- image_dir = image_output_dir(parent)
148
- cache_dir = cache_dir(source, parent)
149
- image_file = parent.normalize_system_path image_name, image_dir
150
- metadata_file = parent.normalize_system_path "#{image_name}.cache", cache_dir
147
+
148
+ image_file = parent.normalize_system_path(image_name, image_output_dir(parent))
149
+ metadata_file = parent.normalize_system_path("#{image_name}.cache", cache_dir(source, parent))
151
150
 
152
151
  if File.exist? metadata_file
153
152
  metadata = File.open(metadata_file, 'r') {|f| JSON.load(f, nil, :symbolize_names => true, :create_additions => false) }
@@ -185,7 +184,7 @@ module Asciidoctor
185
184
  end
186
185
 
187
186
  scale = image_attributes['scale']
188
- if !converter.native_scaling? && scalematch = /(\d+(?:\.\d+))/.match(scale)
187
+ if !converter.native_scaling? && scalematch = /([0-9]+(?:\.[0-9]+)?)/.match(scale)
189
188
  scale_factor = scalematch[1].to_f
190
189
  else
191
190
  scale_factor = 1.0
@@ -244,11 +243,11 @@ module Asciidoctor
244
243
  node.set_attr('target', image_name)
245
244
 
246
245
  if source.global_attr('autoimagesdir')
247
- output_base_dir = output_base_dir(parent)
248
- if output_base_dir
249
- imagesdir = Pathname.new(image_file).relative_path_from(output_base_dir).dirname.to_s
250
- node.set_attr('imagesdir', imagesdir)
251
- end
246
+ image_path = Pathname.new(image_file)
247
+ output_path = Pathname.new(parent.normalize_system_path(output_dir(parent)))
248
+
249
+ imagesdir = image_path.relative_path_from(output_path).dirname.to_s
250
+ node.set_attr('imagesdir', imagesdir)
252
251
  end
253
252
  end
254
253
 
@@ -265,25 +264,43 @@ module Asciidoctor
265
264
  end
266
265
  end
267
266
 
267
+ # Returns the image output directory as an absolute path
268
268
  def image_output_dir(parent)
269
- images_dir = parent.attr('imagesoutdir', nil, true)
269
+ images_out_dir = parent.attr('imagesoutdir', nil, true)
270
270
 
271
- if images_dir
272
- base_dir = nil
271
+ if images_out_dir
272
+ resolve_path(parent, images_out_dir)
273
273
  else
274
- base_dir = output_base_dir(parent)
275
274
  images_dir = parent.attr('imagesdir', nil, true)
275
+ output_dir = output_dir(parent)
276
+ resolve_path(parent, images_dir, output_dir)
276
277
  end
278
+ end
277
279
 
278
- parent.normalize_system_path(images_dir, base_dir)
280
+ # Returns the cache directory as an absolute path
281
+ def cache_dir(source, parent)
282
+ cache_dir = source.global_attr('cachedir')
283
+ if cache_dir
284
+ resolve_path(parent, cache_dir)
285
+ else
286
+ output_dir = output_dir(parent)
287
+ resolve_path(parent, '.asciidoctor/diagram', output_dir)
288
+ end
279
289
  end
280
290
 
281
- def output_base_dir(parent)
282
- parent.normalize_system_path(parent.attr('outdir', nil, true) || doc_option(parent.document, :to_dir))
291
+ # Returns the general output directory for Asciidoctor as an absolute path
292
+ def output_dir(parent)
293
+ resolve_path(parent, parent.attr('outdir', nil, true) || doc_option(parent.document, :to_dir))
283
294
  end
284
295
 
285
- def cache_dir(source, parent)
286
- source.global_attr('cachedir') || parent.normalize_system_path('.asciidoctor/diagram', output_base_dir(parent))
296
+ def resolve_path(parent, path, base_dir = nil)
297
+ if path.nil?
298
+ # Resolve the base dir itself
299
+ parent.document.path_resolver.system_path(base_dir)
300
+ else
301
+ # Resolve the path with respect to the base dir
302
+ parent.document.path_resolver.system_path(path, base_dir)
303
+ end
287
304
  end
288
305
 
289
306
  def create_literal_block(parent, source, format, converter)
@@ -335,7 +352,7 @@ module Asciidoctor
335
352
  include DiagramProcessor
336
353
 
337
354
  def self.inherited(subclass)
338
- subclass.name_positional_attributes ['target', 'format']
355
+ subclass.name_positional_attributes ['format']
339
356
  end
340
357
 
341
358
  def apply_target_subs(parent, target)
@@ -15,6 +15,10 @@ module Asciidoctor
15
15
  [:png, :svg]
16
16
  end
17
17
 
18
+ def native_scaling?
19
+ true
20
+ end
21
+
18
22
  def collect_options(source)
19
23
  options = {}
20
24
 
@@ -23,6 +27,10 @@ module Asciidoctor
23
27
  options[:seq_config] = source.attr(['sequenceconfig', 'sequence-config'])
24
28
  options[:width] = source.attr('width')
25
29
  options[:height] = source.attr('height')
30
+ options[:scale] = source.attr('scale')
31
+ if options[:scale]
32
+ raise "Mermaid only supports integer scale factors: #{options[:scale]}" unless options[:scale] =~ /^[0-9]+$/
33
+ end
26
34
  options[:theme] = source.attr('theme')
27
35
  options[:background] = source.attr('background')
28
36
  options[:config] = source.attr('config')
@@ -60,6 +68,7 @@ module Asciidoctor
60
68
  node = source.find_command('node', :raise_on_error => false)
61
69
  if mmdc && node
62
70
  opts[:height] = options[:height]
71
+ opts[:scale] = options[:scale]
63
72
  opts[:theme] = options[:theme]
64
73
  opts[:background] = options[:background]
65
74
  config = options[:config]
@@ -94,6 +103,10 @@ module Asciidoctor
94
103
  args << '--height' << options[:height]
95
104
  end
96
105
 
106
+ if options[:scale]
107
+ args << '--scale' << options[:scale]
108
+ end
109
+
97
110
  if options[:background]
98
111
  bg = options[:background]
99
112
  bg = "##{bg}" unless bg[0] == '#'
@@ -13,6 +13,11 @@ module Asciidoctor
13
13
  [:pdf, :svg]
14
14
  end
15
15
 
16
+ def collect_options(source)
17
+ {
18
+ :preamble => source.attr('preamble') == 'true'
19
+ }
20
+ end
16
21
 
17
22
  def convert(source, format, options)
18
23
  latexpath = source.find_command('pdflatex')
@@ -23,14 +28,28 @@ module Asciidoctor
23
28
  svgpath = nil
24
29
  end
25
30
 
31
+ if options[:preamble]
32
+ preamble, body = source.to_s.split(/^~~~~$/, 2)
33
+ unless body
34
+ body = preamble
35
+ preamble = ''
36
+ end
37
+ else
38
+ preamble = ''
39
+ body = source.to_s
40
+ end
41
+
26
42
  latex = <<'END'
27
43
  \documentclass[border=2bp, tikz]{standalone}
28
44
  \usepackage{tikz}
45
+ END
46
+ latex << preamble
47
+ latex << <<'END'
29
48
  \begin{document}
30
49
  \begingroup
31
50
  \tikzset{every picture/.style={scale=1}}
32
51
  END
33
- latex << source.to_s
52
+ latex << body
34
53
  latex << <<'END'
35
54
  \endgroup
36
55
  \end{document}
@@ -1,6 +1,7 @@
1
1
  require_relative '../diagram_converter'
2
2
  require_relative '../util/cli_generator'
3
3
  require_relative '../util/platform'
4
+ require_relative '../util/java'
4
5
 
5
6
  module Asciidoctor
6
7
  module Diagram
@@ -15,8 +16,16 @@ module Asciidoctor
15
16
  end
16
17
 
17
18
  def convert(source, format, options)
18
- generate_file(source.find_command('umlet'), 'uxf', format.to_s, source.to_s) do |tool_path, input_path, output_path|
19
- [tool_path, '-action=convert', "-format=#{format.to_s}", "-filename=#{Platform.native_path(input_path)}", "-output=#{Platform.native_path(output_path)}"]
19
+ java = ::Asciidoctor::Diagram::Java.java
20
+
21
+ umlet = source.find_command('umlet')
22
+ ext = File.extname(umlet)
23
+ if ext == '' || ext != '.jar'
24
+ umlet = File.expand_path(File.basename(umlet, '.*') + '.jar', File.dirname(umlet))
25
+ end
26
+
27
+ generate_file(java, 'uxf', format.to_s, source.to_s) do |tool_path, input_path, output_path|
28
+ [tool_path, '-jar', Platform.native_path(umlet), '-action=convert', "-format=#{format.to_s}", "-filename=#{Platform.native_path(input_path)}", "-output=#{Platform.native_path(output_path)}"]
20
29
  end
21
30
  end
22
31
  end
@@ -88,6 +88,119 @@ module Asciidoctor
88
88
  raise "#{prefix_msg}: #{response[:reason]}"
89
89
  end
90
90
  end
91
+
92
+ def self.java
93
+ @java_exe ||= find_java
94
+ raise "Could not find Java executable" unless @java_exe
95
+ @java_exe
96
+ end
97
+
98
+ private
99
+ def self.find_java
100
+ case ::Asciidoctor::Diagram::Platform.os
101
+ when :windows
102
+ path_to(ENV['JAVA_HOME'], 'bin/java.exe') || registry_lookup || ::Asciidoctor::Diagram::Which.which('java')
103
+ when :macosx
104
+ path_to(ENV['JAVA_HOME'], 'bin/java') || path_to(::Asciidoctor::Diagram::Cli.run('/usr/libexec/java_home')[:out].strip, 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
105
+ else
106
+ path_to(ENV['JAVA_HOME'], 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
107
+ end
108
+ end
109
+
110
+ def self.path_to(java_home, java_binary)
111
+ exe_path = File.expand_path(java_binary, java_home)
112
+ if File.executable?(exe_path)
113
+ exe_path
114
+ else
115
+ nil
116
+ end
117
+ end
118
+
119
+ JDK_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit'
120
+ JRE_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment'
121
+
122
+ def self.registry_lookup
123
+ registry_current(JRE_KEY) || registry_current(JDK_KEY) || registry_any()
124
+ end
125
+
126
+ def self.registry_current(key)
127
+ current_version = registry_query(key, 'CurrentVersion')
128
+ if current_version
129
+ java_home = registry_query("#{key}\\#{current_version}", 'JavaHome')
130
+ java_exe(java_home)
131
+ else
132
+ nil
133
+ end
134
+ end
135
+
136
+ def self.registry_any()
137
+ java_homes = registry_query('HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft', 'JavaHome', :recursive => true).values
138
+ java_homes.map { |path| java_exe(path) }.find { |exe| !exe.nil? }
139
+ end
140
+
141
+ def self.java_exe(java_home)
142
+ java = File.expand_path('bin/java.exe', java_home)
143
+
144
+ if File.executable?(java)
145
+ java
146
+ else
147
+ nil
148
+ end
149
+ end
150
+
151
+ def self.registry_query(key, value = nil, opts = {})
152
+ args = ['reg', 'query']
153
+ args << key
154
+ args << '/v' << value unless value.nil?
155
+ args << '/s' if opts[:recursive]
156
+
157
+ begin
158
+ lines = ::Asciidoctor::Diagram::Cli.run(*args)[:out].lines.reject { |l| l.strip.empty? }.each
159
+ rescue
160
+ lines = [].each
161
+ end
162
+
163
+ result = {}
164
+
165
+ while true
166
+ begin
167
+ begin
168
+ k = lines.next
169
+ rescue StopIteration
170
+ break
171
+ end
172
+
173
+ unless k.start_with? key
174
+ next
175
+ end
176
+
177
+ v = nil
178
+ begin
179
+ v = lines.next.strip if lines.peek.start_with?(' ')
180
+ rescue StopIteration
181
+ break
182
+ end
183
+
184
+ if !k.valid_encoding? || (v && !v.valid_encoding?)
185
+ next
186
+ end
187
+
188
+ if v && (md = /([^\s]+)\s+(REG_[^\s]+)\s+(.+)/.match(v))
189
+ v_name = md[1]
190
+ v_value = md[3]
191
+ result["#{k}\\#{v_name}"] = v_value
192
+ else
193
+ result[k] = v
194
+ end
195
+ end
196
+ end
197
+
198
+ if value && !opts[:recursive]
199
+ result.values[0]
200
+ else
201
+ result
202
+ end
203
+ end
91
204
  end
92
205
  end
93
206
  end
@@ -41,11 +41,8 @@ module Asciidoctor
41
41
  end
42
42
 
43
43
  def self.instance
44
- @java_exe ||= find_java
45
- raise "Could not find Java executable" unless @java_exe
46
-
47
44
  unless defined?(@command_server) && @command_server
48
- server = CommandServer.new(@java_exe, classpath)
45
+ server = CommandServer.new(java, classpath)
49
46
  @command_server = server
50
47
  at_exit do
51
48
  server.shutdown
@@ -63,113 +60,6 @@ module Asciidoctor
63
60
  format_request(req, svr.io)
64
61
  parse_response(svr.io)
65
62
  end
66
-
67
- private
68
- def self.find_java
69
- case ::Asciidoctor::Diagram::Platform.os
70
- when :windows
71
- path_to(ENV['JAVA_HOME'], 'bin/java.exe') || registry_lookup || ::Asciidoctor::Diagram::Which.which('java')
72
- when :macosx
73
- path_to(ENV['JAVA_HOME'], 'bin/java') || path_to(::Asciidoctor::Diagram::Cli.run('/usr/libexec/java_home')[:out].strip, 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
74
- else
75
- path_to(ENV['JAVA_HOME'], 'bin/java') || ::Asciidoctor::Diagram::Which.which('java')
76
- end
77
- end
78
-
79
- def self.path_to(java_home, java_binary)
80
- exe_path = File.expand_path(java_binary, java_home)
81
- if File.executable?(exe_path)
82
- exe_path
83
- else
84
- nil
85
- end
86
- end
87
-
88
- JDK_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit'
89
- JRE_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment'
90
-
91
- def self.registry_lookup
92
- registry_current(JRE_KEY) || registry_current(JDK_KEY) || registry_any()
93
- end
94
-
95
- def self.registry_current(key)
96
- current_version = registry_query(key, 'CurrentVersion')
97
- if current_version
98
- java_home = registry_query("#{key}\\#{current_version}", 'JavaHome')
99
- java_exe(java_home)
100
- else
101
- nil
102
- end
103
- end
104
-
105
- def self.registry_any()
106
- java_homes = registry_query('HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft', 'JavaHome', :recursive => true).values
107
- java_homes.map { |path| java_exe(path) }.find { |exe| !exe.nil? }
108
- end
109
-
110
- def self.java_exe(java_home)
111
- java = File.expand_path('bin/java.exe', java_home)
112
-
113
- if File.executable?(java)
114
- java
115
- else
116
- nil
117
- end
118
- end
119
-
120
- def self.registry_query(key, value = nil, opts = {})
121
- args = ['reg', 'query']
122
- args << key
123
- args << '/v' << value unless value.nil?
124
- args << '/s' if opts[:recursive]
125
-
126
- begin
127
- lines = ::Asciidoctor::Diagram::Cli.run(*args)[:out].lines.reject { |l| l.strip.empty? }.each
128
- rescue
129
- lines = [].each
130
- end
131
-
132
- result = {}
133
-
134
- while true
135
- begin
136
- begin
137
- k = lines.next
138
- rescue StopIteration
139
- break
140
- end
141
-
142
- unless k.start_with? key
143
- next
144
- end
145
-
146
- v = nil
147
- begin
148
- v = lines.next.strip if lines.peek.start_with?(' ')
149
- rescue StopIteration
150
- break
151
- end
152
-
153
- if !k.valid_encoding? || (v && !v.valid_encoding?)
154
- next
155
- end
156
-
157
- if v && (md = /([^\s]+)\s+(REG_[^\s]+)\s+(.+)/.match(v))
158
- v_name = md[1]
159
- v_value = md[3]
160
- result["#{k}\\#{v_name}"] = v_value
161
- else
162
- result[k] = v
163
- end
164
- end
165
- end
166
-
167
- if value && !opts[:recursive]
168
- result.values[0]
169
- else
170
- result
171
- end
172
- end
173
63
  end
174
64
  end
175
65
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "2.0.4"
3
+ VERSION = "2.0.5"
4
4
  end
5
5
  end
@@ -10,10 +10,6 @@ eos
10
10
 
11
11
  describe Asciidoctor::Diagram::MermaidBlockMacroProcessor do
12
12
  include_examples "block_macro", :mermaid, code, [:png, :svg]
13
- end
14
-
15
- describe Asciidoctor::Diagram::MermaidBlockProcessor do
16
- include_examples "block", :mermaid, code, [:png, :svg]
17
13
 
18
14
  it "should respect the sequenceConfig attribute" do
19
15
  seq_diag = <<-eos
@@ -43,8 +39,8 @@ Doc Writer <doc@example.com>
43
39
 
44
40
  == First Section
45
41
 
46
- mermaid::mermaid.txt["with_config", sequenceConfig="seqconfig.txt"]
47
- mermaid::mermaid.txt["without_config"]
42
+ mermaid::mermaid.txt[target="with_config", sequenceConfig="seqconfig.txt"]
43
+ mermaid::mermaid.txt[target="without_config"]
48
44
  eos
49
45
 
50
46
  load_asciidoc doc
@@ -69,8 +65,8 @@ Doc Writer <doc@example.com>
69
65
 
70
66
  == First Section
71
67
 
72
- mermaid::mermaid.txt["with_width", width="700"]
73
- mermaid::mermaid.txt["without_width"]
68
+ mermaid::mermaid.txt[target="with_width", width="700"]
69
+ mermaid::mermaid.txt[target="without_width"]
74
70
  eos
75
71
 
76
72
  load_asciidoc doc
@@ -95,8 +91,8 @@ Doc Writer <doc@example.com>
95
91
 
96
92
  == First Section
97
93
 
98
- mermaid::mermaid.txt["default", format="svg"]
99
- mermaid::mermaid.txt["dark", format="svg", theme="dark"]
94
+ mermaid::mermaid.txt[target="default", format="svg"]
95
+ mermaid::mermaid.txt[target="dark", format="svg", theme="dark"]
100
96
  eos
101
97
 
102
98
  load_asciidoc doc
@@ -127,8 +123,8 @@ Doc Writer <doc@example.com>
127
123
 
128
124
  == First Section
129
125
 
130
- mermaid::mermaid.txt["with_config", puppeteerConfig="pptrconfig.txt"]
131
- mermaid::mermaid.txt["without_config"]
126
+ mermaid::mermaid.txt[target="with_config", puppeteerConfig="pptrconfig.txt"]
127
+ mermaid::mermaid.txt[target="without_config"]
132
128
  eos
133
129
 
134
130
  load_asciidoc doc
@@ -137,3 +133,25 @@ mermaid::mermaid.txt["without_config"]
137
133
  expect(File.size('with_config.png')).to be File.size('without_config.png')
138
134
  end
139
135
  end
136
+
137
+ describe Asciidoctor::Diagram::MermaidBlockProcessor do
138
+ include_examples "block", :mermaid, code, [:png, :svg]
139
+
140
+ it "should report unsupported scaling factors" do
141
+ doc = <<-eos
142
+ = Hello, Mermaid!
143
+ Doc Writer <doc@example.com>
144
+
145
+ == First Section
146
+
147
+ [mermaid, scale=1.5]
148
+ ----
149
+ sequenceDiagram
150
+ Alice->>John: Hello John, how are you?
151
+ John-->>Alice: Great!
152
+ ----
153
+ eos
154
+
155
+ expect { load_asciidoc doc }.to raise_error(/support.*scale/i)
156
+ end
157
+ end
@@ -12,7 +12,7 @@ Doc Writer <doc@example.com>
12
12
 
13
13
  == First Section
14
14
 
15
- #{name}::#{name}.txt[format="#{format}"]
15
+ #{name}::#{name}.txt[#{format}]
16
16
  eos
17
17
 
18
18
  d = load_asciidoc doc
@@ -35,7 +35,7 @@ Doc Writer <doc@example.com>
35
35
 
36
36
  == First Section
37
37
 
38
- #{name}::#{name}.txt[format="#{format}"]
38
+ #{name}::#{name}.txt[#{format}]
39
39
  eos
40
40
 
41
41
  d = load_asciidoc doc
@@ -165,8 +165,8 @@ Doc Writer <doc@example.com>
165
165
 
166
166
  == First Section
167
167
 
168
- #{name}::#{name}.txt["foobar"]
169
- #{name}::#{name}.txt["foobaz"]
168
+ #{name}::#{name}.txt[target="foobar"]
169
+ #{name}::#{name}.txt[target="foobaz"]
170
170
  eos
171
171
 
172
172
  load_asciidoc doc
@@ -184,8 +184,8 @@ Doc Writer <doc@example.com>
184
184
 
185
185
  == First Section
186
186
 
187
- #{name}::#{name}.txt["test/foobar"]
188
- #{name}::#{name}.txt["test2/foobaz"]
187
+ #{name}::#{name}.txt[target="test/foobar"]
188
+ #{name}::#{name}.txt[target="test2/foobaz"]
189
189
  eos
190
190
 
191
191
  load_asciidoc doc
@@ -415,6 +415,29 @@ Doc Writer <doc@example.com>
415
415
  expect(File.exist?(File.expand_path(target, 'foo'))).to be true
416
416
  end
417
417
 
418
+ it 'should write files to to_dir if set in safe mode' do
419
+ doc = <<-eos
420
+ = Hello, #{name}!
421
+ Doc Writer <doc@example.com>
422
+
423
+ == First Section
424
+
425
+ [#{name}]
426
+ ----
427
+ #{code}
428
+ ----
429
+ eos
430
+
431
+ to_dir = File.expand_path('foo')
432
+ d = load_asciidoc doc, {:to_dir => to_dir, :safe => :safe}
433
+ b = d.find { |bl| bl.context == :image }
434
+
435
+ target = b.attributes['target']
436
+ expect(target).to_not be_nil
437
+ expect(File.exist?(target)).to be false
438
+ expect(File.exist?(File.expand_path(target, to_dir))).to be true
439
+ end
440
+
418
441
  it 'should write files to to_dir if set when embedded in table' do
419
442
  doc = <<-eos
420
443
  = Hello, #{name}!
@@ -466,6 +489,32 @@ Doc Writer <doc@example.com>
466
489
  expect(File.exist?(File.expand_path(target, 'foo'))).to be false
467
490
  end
468
491
 
492
+ it 'should write files to imagesoutdir if set in safe mode' do
493
+ doc = <<-eos
494
+ = Hello, #{name}!
495
+ Doc Writer <doc@example.com>
496
+
497
+ == First Section
498
+
499
+ [#{name}]
500
+ ----
501
+ #{code}
502
+ ----
503
+ eos
504
+
505
+ out_dir = File.expand_path('foo')
506
+ images_out_dir = File.expand_path('bar')
507
+
508
+ d = load_asciidoc doc, {:attributes => {'imagesoutdir' => images_out_dir, 'outdir' => out_dir}, :safe => :safe}
509
+ b = d.find { |bl| bl.context == :image }
510
+
511
+ target = b.attributes['target']
512
+ expect(target).to_not be_nil
513
+ expect(File.exist?(target)).to be false
514
+ expect(File.exist?(File.expand_path(target, images_out_dir))).to be true
515
+ expect(File.exist?(File.expand_path(target, out_dir))).to be false
516
+ end
517
+
469
518
  it 'should omit width/height attributes when generating docbook' do
470
519
  doc = <<-eos
471
520
  = Hello, #{name}!
@@ -522,7 +571,7 @@ Doc Writer <doc@example.com>
522
571
 
523
572
  == First Section
524
573
 
525
- [#{name}]
574
+ [#{name}, target="unscaled"]
526
575
  ----
527
576
  #{code}
528
577
  ----
@@ -534,7 +583,7 @@ Doc Writer <doc@example.com>
534
583
 
535
584
  == First Section
536
585
 
537
- [#{name}, scale="1.5"]
586
+ [#{name}, scale="2", target="scaled"]
538
587
  ----
539
588
  #{code}
540
589
  ----
@@ -546,7 +595,9 @@ Doc Writer <doc@example.com>
546
595
  d = load_asciidoc scaled_doc, :attributes => {'backend' => 'html5'}
547
596
  scaled_image = d.find { |bl| bl.context == :image }
548
597
 
549
- expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 1.5)
550
- expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 1.5)
598
+ unless formats[0] == :pdf
599
+ expect(scaled_image.attributes['width']).to be_within(1).of(unscaled_image.attributes['width'] * 2)
600
+ expect(scaled_image.attributes['height']).to be_within(1).of(unscaled_image.attributes['height'] * 2)
601
+ end
551
602
  end
552
603
  end
@@ -104,4 +104,74 @@ end
104
104
 
105
105
  describe Asciidoctor::Diagram::TikZBlockProcessor, :broken_on_travis, :broken_on_windows do
106
106
  include_examples "block", :tikz, code, [:pdf]
107
+
108
+ it "should support the preamble attribute" do
109
+ File.write("tikz.txt", code)
110
+
111
+ doc = <<'eos'
112
+ = Hello, tikz!
113
+ Doc Writer <doc@example.com>
114
+
115
+ == First Section
116
+
117
+ [tikz, preamble="true"]
118
+ ----
119
+ \usepackage{tkz-euclide}
120
+ \usepackage{etoolbox}
121
+ \usepackage{MnSymbol}
122
+ \usetikzlibrary{angles,patterns,calc}
123
+ \usepackage[most]{tcolorbox}
124
+ \usepackage{pgfplots}
125
+ \pgfplotsset{compat=1.7}
126
+ ~~~~
127
+ \begin{tikzpicture}
128
+ \tikzset{>=stealth}
129
+ % draw axises and labels. We store a single coordinate to have the
130
+ % direction of the x axis
131
+ \draw[->] (-4,0) -- ++(8,0) coordinate (X) node[below] {$x$};
132
+ \draw[->] (0,-4) -- ++(0,8) node[left] {$y$};
133
+
134
+ \newcommand\CircleRadius{3cm}
135
+ \draw (0,0) circle (\CircleRadius);
136
+ % special method of noting the position of a point
137
+ \coordinate (P) at (-495:\CircleRadius);
138
+
139
+ \draw[thick]
140
+ (0,0)
141
+ coordinate (O) % store origin
142
+ node[] {} % label
143
+ --
144
+ node[below left, pos=1] {$P(-\frac{\sqrt{2}}{2}, -\frac{\sqrt{2}}{2})$} % some labels
145
+ node[below right, midway] {$r$}
146
+ (P)
147
+ --
148
+ node[midway,left] {$y$}
149
+ (P |- O) coordinate (Px) % projection onto horizontal line through
150
+ % O, saved for later
151
+ --
152
+ node[midway, below] {$x$}
153
+ cycle % closed path
154
+
155
+ % pic trick is from the angles library, requires the three points of
156
+ % the marked angle to be named
157
+
158
+ pic [] {angle=X--O--P};
159
+ \draw[->,red] (5mm, 0mm) arc (0:-495:5mm) node[midway,xshift=-4mm,yshift=3.5mm] {$-495^\circ$};
160
+ % right angle marker
161
+ \draw ($(Px)+(0.3, 0)$) -- ++(0, -0.3) -- ++(-0.3,0);
162
+ \end{tikzpicture}
163
+ ----
164
+ eos
165
+
166
+ d = load_asciidoc doc
167
+ expect(d).to_not be_nil
168
+
169
+ b = d.find { |bl| bl.context == :image }
170
+ expect(b).to_not be_nil
171
+
172
+ expect(b.content_model).to eq :empty
173
+
174
+ target = b.attributes['target']
175
+ expect(target).to_not be_nil
176
+ end
107
177
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-diagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pepijn Van Eeckhoudt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-26 00:00:00.000000000 Z
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  - !ruby/object:Gem::Version
240
240
  version: '0'
241
241
  requirements: []
242
- rubygems_version: 3.0.1
242
+ rubygems_version: 3.1.4
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: An extension for asciidoctor that adds support for UML diagram generation