asciidoctor-diagram 1.2.0.preview.1-java → 1.2.0.preview.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/asciidoctor-diagram/util/diagram.rb +27 -26
- data/lib/asciidoctor-diagram/version.rb +1 -1
- data/spec/plantuml_spec.rb +90 -0
- data/spec/test_helper.rb +8 -3
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 952619d93cde27f68bf1739980da524a726ffdc5
|
4
|
+
data.tar.gz: 3410e9e1a782f07fd8e9143118f08b6f3b7a9739
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81352018260910259419b91d3d4858206b4b5cc762f4b3504bd12eb325233d191469fd697a3257c9c6c8420414d9136e0d6090c34c122e29d442bc8b6e6fb7f0
|
7
|
+
data.tar.gz: 37fbe270d7885a05cf16e6301be67ba0a7c5c51e79c74013bef0e13c95978197b575bb0f516d8cd2e006f839a1b422384ee3f0c666af7f5205a56e4361e3737c
|
@@ -39,7 +39,7 @@ module Asciidoctor
|
|
39
39
|
|
40
40
|
def process_macro(parent, target, attributes)
|
41
41
|
source = FileSource.new(File.expand_path(target, parent.document.attributes['docdir']))
|
42
|
-
attributes['target']
|
42
|
+
attributes['target'] ||= File.basename(target, File.extname(target))
|
43
43
|
|
44
44
|
generate_block(parent, source, attributes)
|
45
45
|
end
|
@@ -98,29 +98,26 @@ module Asciidoctor
|
|
98
98
|
image_name = "#{target || ('diag-' + source.checksum)}.#{format}"
|
99
99
|
image_dir = File.expand_path(parent.document.attributes['imagesdir'] || '', parent.document.attributes['docdir'])
|
100
100
|
image_file = File.expand_path(image_name, image_dir)
|
101
|
+
metadata_file = File.expand_path("#{image_name}.cache", image_dir)
|
101
102
|
|
102
|
-
if
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
else
|
108
|
-
metadata = nil
|
109
|
-
end
|
103
|
+
if File.exists? metadata_file
|
104
|
+
metadata = File.open(metadata_file, 'r') { |f| JSON.load f }
|
105
|
+
else
|
106
|
+
metadata = {}
|
107
|
+
end
|
110
108
|
|
111
|
-
|
112
|
-
|
109
|
+
if source.should_process?(image_file, metadata['checksum'])
|
110
|
+
params = IMAGE_PARAMS[format]
|
113
111
|
|
114
|
-
|
112
|
+
result = generator_info[:generator].call(source.code, parent)
|
115
113
|
|
116
|
-
|
114
|
+
result.force_encoding(params[:encoding])
|
117
115
|
|
118
|
-
|
119
|
-
|
116
|
+
metadata = {'checksum' => source.checksum}
|
117
|
+
metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
end
|
119
|
+
File.open(image_file, 'wb') { |f| f.write result }
|
120
|
+
File.open(metadata_file, 'w') { |f| JSON.dump(metadata, f) }
|
124
121
|
end
|
125
122
|
|
126
123
|
attributes['target'] = image_name
|
@@ -154,14 +151,14 @@ module Asciidoctor
|
|
154
151
|
end
|
155
152
|
|
156
153
|
class Source
|
157
|
-
def newer_than?(image)
|
158
|
-
true
|
159
|
-
end
|
160
|
-
|
161
154
|
def checksum
|
162
155
|
@checksum ||= compute_checksum(code)
|
163
156
|
end
|
164
157
|
|
158
|
+
def should_process?(image_file, old_checksum)
|
159
|
+
!File.exists?(image_file) || (newer_than?(image_file) && old_checksum != checksum)
|
160
|
+
end
|
161
|
+
|
165
162
|
private
|
166
163
|
|
167
164
|
def compute_checksum(code)
|
@@ -176,6 +173,10 @@ module Asciidoctor
|
|
176
173
|
@reader = reader
|
177
174
|
end
|
178
175
|
|
176
|
+
def newer_than?(image_file)
|
177
|
+
true
|
178
|
+
end
|
179
|
+
|
179
180
|
def code
|
180
181
|
@code ||= @reader.lines.join("\n")
|
181
182
|
end
|
@@ -186,12 +187,12 @@ module Asciidoctor
|
|
186
187
|
@file_name = file_name
|
187
188
|
end
|
188
189
|
|
189
|
-
def
|
190
|
-
@
|
190
|
+
def newer_than?(image_file)
|
191
|
+
File.mtime(@file_name) > File.mtime(image_file)
|
191
192
|
end
|
192
193
|
|
193
|
-
def
|
194
|
-
|
194
|
+
def code
|
195
|
+
@code ||= File.read(@file_name)
|
195
196
|
end
|
196
197
|
end
|
197
198
|
end
|
data/spec/plantuml_spec.rb
CHANGED
@@ -181,4 +181,94 @@ ArrowColor #DEADBE
|
|
181
181
|
svg = File.read(target)
|
182
182
|
expect(svg).to match /<path.*fill="#DEADBE"/
|
183
183
|
end
|
184
|
+
|
185
|
+
it "should not regenerate images when source has not changed" do
|
186
|
+
code = <<-eos
|
187
|
+
User -> (Start)
|
188
|
+
User --> (Use the application) : Label
|
189
|
+
|
190
|
+
:Main Admin: ---> (Use the application) : Another label
|
191
|
+
eos
|
192
|
+
|
193
|
+
File.write('plantuml.txt', code)
|
194
|
+
|
195
|
+
doc = <<-eos
|
196
|
+
= Hello, PlantUML!
|
197
|
+
Doc Writer <doc@example.com>
|
198
|
+
|
199
|
+
== First Section
|
200
|
+
|
201
|
+
plantuml::plantuml.txt
|
202
|
+
|
203
|
+
[plantuml, format="png"]
|
204
|
+
----
|
205
|
+
actor Foo1
|
206
|
+
boundary Foo2
|
207
|
+
Foo1 -> Foo2 : To boundary
|
208
|
+
----
|
209
|
+
eos
|
210
|
+
|
211
|
+
d = Asciidoctor.load StringIO.new(doc)
|
212
|
+
b = d.find { |b| b.context == :image }
|
213
|
+
target = b.attributes['target']
|
214
|
+
mtime1 = File.mtime(target)
|
215
|
+
|
216
|
+
sleep 1
|
217
|
+
|
218
|
+
d = Asciidoctor.load StringIO.new(doc)
|
219
|
+
|
220
|
+
mtime2 = File.mtime(target)
|
221
|
+
|
222
|
+
expect(mtime2).to eq mtime1
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should handle two block macros with the same source" do
|
226
|
+
code = <<-eos
|
227
|
+
User -> (Start)
|
228
|
+
User --> (Use the application) : Label
|
229
|
+
|
230
|
+
:Main Admin: ---> (Use the application) : Another label
|
231
|
+
eos
|
232
|
+
|
233
|
+
File.write('plantuml.txt', code)
|
234
|
+
|
235
|
+
doc = <<-eos
|
236
|
+
= Hello, PlantUML!
|
237
|
+
Doc Writer <doc@example.com>
|
238
|
+
|
239
|
+
== First Section
|
240
|
+
|
241
|
+
plantuml::plantuml.txt[]
|
242
|
+
plantuml::plantuml.txt[]
|
243
|
+
eos
|
244
|
+
|
245
|
+
Asciidoctor.load StringIO.new(doc)
|
246
|
+
expect(File.exists?('plantuml.png')).to be_true
|
247
|
+
end
|
248
|
+
|
249
|
+
it "should respect target attribute in block macros" do
|
250
|
+
code = <<-eos
|
251
|
+
User -> (Start)
|
252
|
+
User --> (Use the application) : Label
|
253
|
+
|
254
|
+
:Main Admin: ---> (Use the application) : Another label
|
255
|
+
eos
|
256
|
+
|
257
|
+
File.write('plantuml.txt', code)
|
258
|
+
|
259
|
+
doc = <<-eos
|
260
|
+
= Hello, PlantUML!
|
261
|
+
Doc Writer <doc@example.com>
|
262
|
+
|
263
|
+
== First Section
|
264
|
+
|
265
|
+
plantuml::plantuml.txt["foobar"]
|
266
|
+
plantuml::plantuml.txt["foobaz"]
|
267
|
+
eos
|
268
|
+
|
269
|
+
Asciidoctor.load StringIO.new(doc)
|
270
|
+
expect(File.exists?('foobar.png')).to be_true
|
271
|
+
expect(File.exists?('foobaz.png')).to be_true
|
272
|
+
expect(File.exists?('plantuml.png')).to be_false
|
273
|
+
end
|
184
274
|
end
|
data/spec/test_helper.rb
CHANGED
@@ -30,13 +30,18 @@ end
|
|
30
30
|
RSpec.configure do |c|
|
31
31
|
TEST_DIR = 'testing'
|
32
32
|
|
33
|
-
c.before(:
|
34
|
-
|
33
|
+
c.before(:suite) do
|
34
|
+
FileUtils.rm_r TEST_DIR if Dir.exists? TEST_DIR
|
35
35
|
FileUtils.mkdir_p TEST_DIR
|
36
36
|
end
|
37
37
|
|
38
38
|
c.around(:each) do |example|
|
39
|
-
|
39
|
+
metadata = example.metadata
|
40
|
+
group_dir = File.expand_path(metadata[:example_group][:full_description].gsub(/[^\w]+/, '_'), TEST_DIR)
|
41
|
+
Dir.mkdir(group_dir) unless Dir.exists?(group_dir)
|
42
|
+
|
43
|
+
test_dir = File.expand_path(metadata[:description].gsub(/[^\w]+/, '_'), group_dir)
|
44
|
+
Dir.mkdir(test_dir)
|
40
45
|
|
41
46
|
old_wd = Dir.pwd
|
42
47
|
Dir.chdir test_dir
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-diagram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.preview.
|
4
|
+
version: 1.2.0.preview.3
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: asciidoctor
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.5.0.preview.2
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.5.0.preview.2
|
69
69
|
description: Asciidoctor diagramming extension
|
@@ -114,17 +114,17 @@ require_paths:
|
|
114
114
|
- lib
|
115
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
|
-
- -
|
117
|
+
- - '>='
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0'
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>'
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.3.1
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.0.3
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: An extension for asciidoctor that adds support for UML diagram generation
|