elexis-wiki-interface 0.5.2 → 0.5.3

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
  SHA1:
3
- metadata.gz: 39023cc608821f4d521e4ecbc6bbced22b04bed5
4
- data.tar.gz: 53d24e645de05ca3ebbb95d7ead6095de2ec9501
3
+ metadata.gz: e9d72d912fd4a22ecaf2edbf49da976269fc25e8
4
+ data.tar.gz: fb88d025c7dfedd98f704a8cbf3fa3a3013dc457
5
5
  SHA512:
6
- metadata.gz: 0dca8f432c28684fff8170c702b2efbbbea0a4bdec271b36eeeaf42116569f203c72715eb212cebce13c8738495bd97d2d998f84ca8be12ffdc0924bbc940280
7
- data.tar.gz: 42a2159ea7d141b3b4e72c6bceb4a6c552a415f21ad2a7b3d24bced1c35c5423212ff40182ec11c5072e1275c86edb26ddc2033ed10537503c0087691ed4ffd2
6
+ metadata.gz: 805a7d07ade2e96a7500819ae6a83c0cb13db5fc0b48eff63da2b59e05385924e2fb634f7bdee8a76eb00c4a801c3af5ffeac1fd96c0dff97dc6519420a3bcb5
7
+ data.tar.gz: e4b562ca6ea1278aa1e9f4c313147d6843494e2ad97d571a476ce6c336e4a032fa64c7e958504c83e67e0b1191c9c512067eba913125493d86579bd3bec10cff
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elexis-wiki-interface (0.5.2)
4
+ elexis-wiki-interface (0.5.3)
5
5
  eclipse-plugin (>= 0.1)
6
6
  mediawiki-gateway
7
7
  mediawiki_api
@@ -1,3 +1,8 @@
1
+ h3. Version 0.5.3 (2015-10-29)
2
+
3
+ * Remove dummy UTF-8 characters
4
+ * Fix mediawiki files which reference images containing '/' and ':'
5
+
1
6
  h3. Version 0.5.2 (2015-10-29)
2
7
 
3
8
  * Correctly rename picture with ':' and '/'.
@@ -22,7 +22,8 @@ end
22
22
 
23
23
  module Elexis
24
24
  module Wiki
25
- ImagePattern = /(\[File:|Datei:|\[Image:)(?:[^\/:]*\/)?([ \w\.:\/-]*)([^\]\|]*)/
25
+ ImageWithSlashPattern = /(\[File:|Datei:|\[Image:)([^\/:\]]*[:\/])([\w.-]+)/
26
+ ImagePattern = /(\[File:|\[Datei:|\[Image:)((?:.+:|)[^\/:|]*)/
26
27
 
27
28
  #
28
29
  # This helper class collect information about all images used in
@@ -190,8 +191,9 @@ module Elexis
190
191
 
191
192
  def get_name_with_project(path)
192
193
  prefix =Images.get_project_abbreviation(path)
193
- result = (prefix + '-' + File.basename(path)).downcase.gsub(':', '-')
194
- result
194
+ basename = File.basename(path)
195
+ result = /^#{prefix}/i.match(basename) ? basename : (prefix + '-' + basename).gsub(':', '-')
196
+ result.downcase
195
197
  end
196
198
 
197
199
  def Images.get_small_name(path)
@@ -307,6 +309,7 @@ module Elexis
307
309
  run_git_cmd("git rm -f --ignore-unmatch #{picture[:path]}", true) if picture[:path] != new_path
308
310
  }
309
311
  @actions.uniq!
312
+ cleanup_mediawikis
310
313
  puts @actions.join("\n")
311
314
  ensure
312
315
  Dir.chdir(savedDir)
@@ -332,32 +335,90 @@ module Elexis
332
335
  lines = IO.readlines(mediawiki_file)
333
336
  lines.each{
334
337
  |line|
335
- unless m = ImagePattern.match(line)
336
- newLines << line
337
- else
338
- unless old_image_name.downcase.eql?(m[2].downcase) or /\/#{old_image_name}/i.match(m[2])
339
- puts "change_image_name_in_mediawiki #{__LINE__} skip #{m}" if $VERBOSE
340
- newLines << line
341
- else
338
+ image_name = nil
339
+ if m = ImageWithSlashPattern.match(line)
340
+ image_name = m[2] + m[3]
341
+ elsif m = ImagePattern.match(line)
342
+ image_name = m[2]
343
+ end
344
+ unless image_name
345
+ newLines << fix_line(line)
346
+ next;
347
+ end
348
+ if old_image_name.downcase.eql?(image_name.downcase) or/\/#{old_image_name}/i.match(image_name)
342
349
  dirName = File.dirname(mediawiki_file)
343
350
  simpleName = File.join(dirName, File.basename(new_image_name))
351
+ raise "Could not find image" unless File.exists?(new_image_name)
344
352
  if files = Dir.glob(simpleName, File::FNM_CASEFOLD) and files.size >= 1
345
- # if files = (Dir.glob(simpleName, File::FNM_CASEFOLD) +Dir.glob(old_image_name, File::FNM_CASEFOLD)) and files.size >= 1
346
- new_line = line.sub(m[2], new_image_name)
347
- new_line = new_line.sub(m[3], '') if m[3]
348
- puts "change_image_name_in_mediawiki #{__LINE__} #{line} aus #{m[2]} mit #{new_image_name}" if $VERBOSE
349
- newLines << new_line
353
+ newLines << fix_line(line, old_image_name, new_image_name)
350
354
  else
351
- msg = "#{__LINE__} Could not find image for #{m[0]} searched for #{simpleName} in #{Dir.pwd}. files are #{files}"
352
- raise msg
355
+ newLines << fix_line(line)
353
356
  end
354
- end
357
+ else
358
+ newLines << fix_line(line)
355
359
  end
356
360
  }
357
361
  File.open(mediawiki_file, "w") {|f| f.write newLines.join.gsub(/\[\[Datei:|\[\[Image:/i, '[[File:')}
358
362
  run_git_cmd("git add #{mediawiki_file}")
359
363
  ensure Dir.chdir(savedDir)
360
364
  end
365
+ def fix_line(line, old_file=nil, new_file=nil)
366
+ line.gsub!(/(<U\+\h\h\h\h>)/,'') # remove pseudo UTF-8
367
+ old_ref = 'unknown'
368
+ unless old_file
369
+ image_name = nil
370
+ if m = ImageWithSlashPattern.match(line)
371
+ old_file = m[2] + m[3]
372
+ old_ref = m[3].downcase
373
+ elsif m = ImagePattern.match(line)
374
+ old_file = m[2]
375
+ old_ref = m[2].downcase
376
+ end
377
+ return line unless m
378
+ end
379
+ new_file ||= Images.get_small_name(old_file)
380
+ proj = Images.get_project_abbreviation(Dir.pwd)
381
+ change_to = nil
382
+ if File.exists?(new_file)
383
+ change_to ||= new_file
384
+ else
385
+ [ old_ref,
386
+ old_file.sub(/^#{proj}[_]/i, proj+'-'),
387
+ new_file.sub(/^#{proj}/i, ''),
388
+ proj + '-' + new_file.sub(/^#{proj}/i, ''),
389
+ new_file.sub(/^#{proj}-#{proj}/i, proj + '-'),
390
+ new_file.sub(/^#{proj}-(.*)/i, proj + '\1'),
391
+ (proj + '-' + new_file).downcase,
392
+ ].each{
393
+ |try_this|
394
+ if File.exists?(try_this.downcase)
395
+ change_to ||= try_this.downcase
396
+ break
397
+ end
398
+ }
399
+ end
400
+ return line unless change_to
401
+ line.sub(old_file, change_to)
402
+ end
403
+
404
+ def cleanup_mediawikis
405
+ savedDir = Dir.pwd
406
+ @docs.each do
407
+ |docDir|
408
+ Dir.chdir(File.join(@rootDir, docDir))
409
+ wikis = Dir.glob('*.mediawiki')
410
+ wikis.each{
411
+ |file|
412
+ output = ''
413
+ lines = IO.readlines(file)
414
+ lines.each{|line| output << fix_line(line) }
415
+ File.open(file, 'w+') { |f| f.write(output) }
416
+ }
417
+ end
418
+ ensure
419
+ Dir.chdir(savedDir)
420
+ end
421
+
361
422
  end
362
423
  end
363
424
  end
@@ -1,5 +1,5 @@
1
1
  module Elexis
2
2
  module Wiki
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  end
5
5
  end
@@ -4,8 +4,9 @@ require 'spec_helper'
4
4
  require "elexis/wiki/images"
5
5
 
6
6
  describe 'Images' do
7
- NR_PICTURES = 23
8
- NR_ELEMS_IN_IMAGE_PATTERN = 4
7
+ NR_PICTURES = 24
8
+ NR_ELEMS_IN_IMAGE_PATTERN = 3
9
+ NR_ELEMS_IN_IMAGE_WITH_SLASH_PATTERN = 4
9
10
 
10
11
  before :all do
11
12
  @subdir = 'images'
@@ -21,6 +22,14 @@ describe 'Images' do
21
22
  # FileUtils.rm_rf(@dataDir)
22
23
  end
23
24
 
25
+ it "should refuse to change the image name in a mediawiki file when we find no corresponding image file" do
26
+ wiki_file = File.join(@dataDir, @subdir, 'ch.elexis.icpc', 'doc', 'test2.mediawiki')
27
+ old_picture_name = 'ch.elexis.icpc:icpc4.png'
28
+ expect(IO.read(wiki_file)).to include old_picture_name
29
+ expect(File.exist?(wiki_file)).to eq true
30
+ expect { @images.change_image_name_in_mediawiki(wiki_file, old_picture_name, 'icpc_should_not_exist.png')}.to raise_error(RuntimeError, /Could not find image/)
31
+ end
32
+
24
33
  it "should create the pictures.yml and .csv file" do
25
34
  expect(@images.yml).to eq File.join(@images.rootDir, 'pictures.yml')
26
35
  expect(@images.csv).to eq File.join(@images.rootDir, 'pictures.csv')
@@ -42,15 +51,17 @@ describe 'Images' do
42
51
  end
43
52
 
44
53
  it "should match picture names with a /" do
45
- res = Elexis::Wiki::ImagePattern.match('[[File:At.medevit.elexis.dbcheck/dbcleaningui.png|frame|none]]')
46
- expect(res.size).to eq NR_ELEMS_IN_IMAGE_PATTERN
47
- expect(res[2]).to eq 'dbcleaningui.png'
54
+ res = Elexis::Wiki::ImageWithSlashPattern.match('[[File:At.medevit.elexis.dbcheck/dbcleaningui.png|frame|none]]')
55
+ expect(res.size).to eq NR_ELEMS_IN_IMAGE_WITH_SLASH_PATTERN
56
+ expect(res[2]).to eq 'At.medevit.elexis.dbcheck/'
57
+ expect(res[3]).to eq 'dbcleaningui.png'
48
58
  end
49
59
 
50
60
  it "should match picture doc_de/settings_agenda-druck1.png" do
51
- res = Elexis::Wiki::ImagePattern.match('[[File:doc_de/settings_agenda-druck1.png|image]]<br />')
52
- expect(res.size).to eq NR_ELEMS_IN_IMAGE_PATTERN
53
- expect(res[2]).to eq 'settings_agenda-druck1.png'
61
+ res = Elexis::Wiki::ImageWithSlashPattern.match('[[File:doc_de/settings_agenda-druck1.png|image]]<br />')
62
+ expect(res.size).to eq NR_ELEMS_IN_IMAGE_WITH_SLASH_PATTERN
63
+ expect(res[2]).to eq 'doc_de/'
64
+ expect(res[3]).to eq 'settings_agenda-druck1.png'
54
65
  end
55
66
 
56
67
  it "should match picture File:dbcleaningui.png" do
@@ -61,6 +72,7 @@ describe 'Images' do
61
72
 
62
73
  examples = { 'doc_de/settings_agenda-druck1.png' => 'settings_agenda-druck1.png',
63
74
  'doc_de/settingsAgendaDruck1.png' => 'settings_agenda_druck1.png',
75
+ 'Ch.elexis.privatrechnung/doc/privatrechnung-3.png' => 'privatrechnung-3.png',
64
76
  'CurabillWarning1.png' => 'curabill_warning1.png',
65
77
  'ch.elexis.icpc/Icpc1.png' => 'icpc-1.png',
66
78
  }
@@ -79,7 +91,6 @@ describe 'Images' do
79
91
  end
80
92
 
81
93
  def check_rename(wiki_file, old_picture_name, new_picture_name, expected_new_line)
82
- expect(IO.read(wiki_file)).to include old_picture_name
83
94
  @images.change_image_name_in_mediawiki(wiki_file, old_picture_name, new_picture_name)
84
95
  changed = IO.read(wiki_file)
85
96
  expect(changed).to include "tag_one"
@@ -100,6 +111,7 @@ describe 'Images' do
100
111
  'org.iatrix.tests/doc/test.png' => 'iatrix-test.png',
101
112
  'org.iatrix.tests/doc/test.jpg' => 'iatrix-test.jpg',
102
113
  'org.iatrix_tests/doc/test.gif' => 'iatrix-test.gif',
114
+ 'ch.elexis.connect.abxmicros/doc/abxmicros-kabel.png' => 'abxmicros-kabel.png',
103
115
  }
104
116
  tests.each {
105
117
  |path, expected|
@@ -113,9 +125,10 @@ describe 'Images' do
113
125
  rename_tests = {
114
126
  # 'Ch.elexis.icpc:Icpc2.png' => [ 'icpc2.png', 'tag_two [[File:icpc-2.png|image]]'],
115
127
  'Ch.elexis.icpc:icpc5.png' => [ 'icpc5.png', 'tag_frame_none [[File:icpc5.png|frame|none]]'],
116
- 'Ch.elexis.icpc:icpc5.png' => [ 'icpc5.png', 'tag_png [[File:icpc5.png|image]]'],
117
- 'Ch.elexis.icpc:icpc6.png' => [ 'elexis_logo.jpg', 'tag_jpg [[File:elexis_logo.jpg|image]]'],
118
- 'Ch.elexis.icpc:icpc7.png' => [ 'disposan.gif', 'tag_gif [[File:disposan.gif|image]]'],
128
+ 'ch.elexis.icpc:icpc5.png' => [ 'icpc5.png', 'tag_png [[File:icpc5.png|image]]<br />'],
129
+ 'Ch.elexis.icpc:icpc6.png' => [ 'elexis_logo.jpg', 'tag_jpg [[File:icpc6.png|image]]'],
130
+ 'Ch.elexis.icpc:icpc7.png' => [ 'disposan.gif', 'tag_gif [[File:icpc7.png|image]]'],
131
+ 'Ch.elexis.icpc/favicon_green.png' => [ 'favicon_green.png', 'tag_slash [[File:favicon_green.png|image]]<br />'],
119
132
  }
120
133
  rename_tests.each {
121
134
  |old_picture_name, params|
@@ -136,14 +149,6 @@ describe 'Images' do
136
149
  expect(content).to include 'kabel.png]'
137
150
  end
138
151
 
139
- it "should refuse to change the image name in a mediawiki file when we find no corresponding image file" do
140
- wiki_file = File.join(@dataDir, @subdir, 'ch.elexis.icpc', 'doc', 'test2.mediawiki')
141
- expect(File.exist?(wiki_file)).to eq true
142
- old_picture_name = 'ch.elexis.icpc:icpc4.png'
143
- expect(IO.read(wiki_file)).to include old_picture_name
144
- expect { @images.change_image_name_in_mediawiki(wiki_file, old_picture_name, 'icpc_should_not_exist.png')}.to raise_error(RuntimeError, /Could not find image/)
145
- end
146
-
147
152
  checks = {
148
153
  'at.medevit.elexis.swissmedic/fixmedikationaufruf.png' => 'swissmedic',
149
154
  'at.medevit.elexis.swissmedic/doc/fixmedikationaufruf.png' => 'swissmedic',
@@ -220,6 +225,23 @@ describe 'ImagesCleanup' do
220
225
  @images.execute_cleanup(true)
221
226
  end
222
227
 
228
+ it "should fix old names in" do
229
+ wiki_file = File.join(@dataDir, @subdir, 'ch.elexis.agenda', 'doc', 'agenda.mediawiki')
230
+ expect(File.exist?(wiki_file)).to eq true
231
+ @images.cleanup_mediawikis
232
+ content = IO.read(wiki_file)
233
+ expect(content).to include 'tag_one [[File:agenda-2.png|image]]<br />'
234
+ expect(content).to include 'tag_three [[File:agenda-2.png|image]]<br />'
235
+ expect(content).to include 'tag_two [[File:agenda-2.png|frame|none]]<br />'
236
+ end
237
+
238
+ it "should remove pseudo UTF-8 chars like <U+200E>" do
239
+ wiki_file = File.join(@dataDir, @subdir, 'ch.elexis.icpc', 'doc', 'test2.mediawiki')
240
+ content = IO.read(wiki_file)
241
+ expect(File.exist?(wiki_file)).to eq true
242
+ expect(/(<U\+\h\h\h\h>)/.match(content)).to be nil
243
+ end
244
+
223
245
  it "should add icpc-8.png and icpc-1.png" do
224
246
  expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc-1.png")).not_to eq nil
225
247
  expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc1.png")).to eq nil
@@ -243,6 +265,7 @@ describe 'ImagesCleanup' do
243
265
  it 'should add a "-" if the image name starts with the abbrev' do
244
266
  expect(@images.actions.index("git add -f images/ch.elexis.icpc/doc/icpc-1.png")).not_to eq nil
245
267
  end
268
+
246
269
  end
247
270
 
248
271
  describe "execute_cleanup" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elexis-wiki-interface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklaus Giger
@@ -166,6 +166,8 @@ files:
166
166
  - spec/data/doc/doc_de/.project
167
167
  - spec/data/images/ch.elexis.agenda/.project
168
168
  - spec/data/images/ch.elexis.agenda/META-INF/MANIFEST.MF
169
+ - spec/data/images/ch.elexis.agenda/doc/agenda.mediawiki
170
+ - spec/data/images/ch.elexis.agenda/doc/agenda2.png
169
171
  - spec/data/images/ch.elexis.agenda/doc/fixmedikationaufruf.png
170
172
  - spec/data/images/ch.elexis.agenda/plugin.properties
171
173
  - spec/data/images/ch.elexis.agenda/plugin.xml
@@ -283,6 +285,8 @@ test_files:
283
285
  - spec/data/doc/doc_de/.project
284
286
  - spec/data/images/ch.elexis.agenda/.project
285
287
  - spec/data/images/ch.elexis.agenda/META-INF/MANIFEST.MF
288
+ - spec/data/images/ch.elexis.agenda/doc/agenda.mediawiki
289
+ - spec/data/images/ch.elexis.agenda/doc/agenda2.png
286
290
  - spec/data/images/ch.elexis.agenda/doc/fixmedikationaufruf.png
287
291
  - spec/data/images/ch.elexis.agenda/plugin.properties
288
292
  - spec/data/images/ch.elexis.agenda/plugin.xml