asciidoctor-diagram 1.1.1-java → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39492da724ad540e40f7ab2f94c2ddddb360d1dc
4
- data.tar.gz: 71c56837a403619e4d2af14860bdfd5f3f269914
3
+ metadata.gz: f0f69b3d47bad0cef1b5b515d030c2bdd41ef13d
4
+ data.tar.gz: 84fab6e64ec3fc13e1638ab44c4104a20b369eb9
5
5
  SHA512:
6
- metadata.gz: d4db4cf84706e5f043432d2915218563c590fa8d42cf4dceed49614e3c74d3e37169c1588d2d4a7338a604af5458bae178e229ddfff7cf2413b89b1f110fe371
7
- data.tar.gz: 93428cb3c6066462496719501dc06d1d844d9f6ba3175fbd5a93c7d02c0cfebb9a5ba0d04b567e14556fcfb9392b98c4c05a30dea6c33e62a709b4c4844d03c3
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'] = File.basename(target, File.extname(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 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
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
- unless File.exists?(image_file) && metadata && metadata['checksum'] == source.checksum
112
- params = IMAGE_PARAMS[format]
109
+ if source.should_process?(image_file, metadata['checksum'])
110
+ params = IMAGE_PARAMS[format]
113
111
 
114
- result = generator_info[:generator].call(source.code, parent)
112
+ result = generator_info[:generator].call(source.code, parent)
115
113
 
116
- result.force_encoding(params[:encoding])
114
+ result.force_encoding(params[:encoding])
117
115
 
118
- metadata = {'checksum' => source.checksum}
119
- metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
116
+ metadata = {'checksum' => source.checksum}
117
+ metadata['width'], metadata['height'] = params[:decoder].get_image_size(result)
120
118
 
121
- File.open(image_file, 'w') { |f| f.write result }
122
- File.open(cache_file, 'w') { |f| JSON.dump(metadata, f) }
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 code
190
- @code ||= File.read(@file_name)
190
+ def newer_than?(image_file)
191
+ File.mtime(@file_name) > File.mtime(image_file)
191
192
  end
192
193
 
193
- def newer_than?(image)
194
- !File.exists?(image) || File.mtime(@file_name) > File.mtime(image)
194
+ def code
195
+ @code ||= File.read(@file_name)
195
196
  end
196
197
  end
197
198
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module Diagram
3
- VERSION = "1.1.1"
3
+ VERSION = "1.1.3"
4
4
  end
5
5
  end
@@ -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(:all) do
34
- #FileUtils.rm_r TEST_DIR if Dir.exists? TEST_DIR
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
- test_dir = Dir.mktmpdir 'test', File.expand_path(TEST_DIR)
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.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-21 00:00:00.000000000 Z
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler