asciidoctor-diagram 1.1.1-java → 1.1.3-java
Sign up to get free protection for your applications and to get access to all the features.
- 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 +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0f69b3d47bad0cef1b5b515d030c2bdd41ef13d
|
4
|
+
data.tar.gz: 84fab6e64ec3fc13e1638ab44c4104a20b369eb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c7f3dea8bb76b394345bec0354ad49b1fc0d94be25ac1ce38b02528076c96f14dc2b1eac7860916153dd41c269db57c7cd4c38ef52ff6479ef4ea3d0a583d8d
|
7
|
+
data.tar.gz: c1ecba019813053288283abf6f529c6f0ca6eca836536445983e18028d1ce9fb09d9b6317725d8fb4f3f3c8b27041142287162a2a96091505dd5851362b407a9
|
@@ -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
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciidoctor-diagram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.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
|