ydocx 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 1.0.6 / 03.05.2012
2
+
3
+ * Removed RMagick dependency (as optional feature)
4
+ - use RMagick only for wmf conversion
5
+
1
6
  === 1.0.5 / 03.05.2012
2
7
 
3
8
  * Added img support
data/README.txt CHANGED
@@ -14,13 +14,15 @@
14
14
  == Usage
15
15
 
16
16
  * Usage: /usr/local/bin/docx2html file [options]
17
- -f, --format Format of style and chapter {(fi|fachinfo)|(pl|plain)}, default none.
17
+ -f, --format Format of style and chapter {(fi|fachinfo)|(pl|plain)}, default is FI.
18
18
  -h, --help Display this help message.
19
19
 
20
20
  == Using the great libraries
21
21
 
22
+ * rubyzip
22
23
  * nokogiri
23
24
  * htmlentities
25
+ * RMagick
24
26
 
25
27
  == License GPLv3.0
26
28
 
data/lib/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module Docx2html
5
- VERSION = "1.0.5"
5
+ VERSION = "1.0.6"
6
6
  end
@@ -3,6 +3,11 @@
3
3
 
4
4
  require 'pathname'
5
5
  require 'zip/zip'
6
+ begin
7
+ require 'RMagick'
8
+ rescue LoadError
9
+ warn "Couldn't load RMagick: .wmf conversion off"
10
+ end
6
11
  require 'ydocx/parser'
7
12
  require 'ydocx/builder'
8
13
 
@@ -65,12 +70,27 @@ module YDocx
65
70
  FileUtils.mkdir @files unless @files.exist?
66
71
  @zip = Zip::ZipFile.open(@path.realpath)
67
72
  @pictures.each do |pic|
68
- pic_path = Pathname.new pic # id/filename.ext
69
- pic_dir = @files.join pic_path.dirname
70
- FileUtils.mkdir pic_dir unless pic_dir.exist?
71
- binary = @zip.find_entry("word/media/#{pic_path.basename}").get_input_stream
72
- @files.join(pic_path).open('w') do |f|
73
- f.puts binary.read
73
+ origin_path = Pathname.new pic[:origin] # media/filename.ext
74
+ source_path = Pathname.new pic[:source] # id/filename.ext
75
+ dir = @files.join source_path.dirname
76
+ FileUtils.mkdir dir unless dir.exist?
77
+ binary = @zip.find_entry("word/#{origin_path}").get_input_stream
78
+ if source_path.extname != origin_path.extname # convert
79
+ if defined? Magick::Image
80
+ image = Magick::Image.from_blob(binary.read).first
81
+ image.format = source_path.extname[1..-1].upcase
82
+ @files.join(source_path).open('w') do |f|
83
+ f.puts image.to_blob
84
+ end
85
+ else # copy original image
86
+ @files.join(dir, origin_path.basename).open('w') do |f|
87
+ f.puts binary.read
88
+ end
89
+ end
90
+ else
91
+ @files.join(source_path).open('w') do |f|
92
+ f.puts binary.read
93
+ end
74
94
  end
75
95
  end
76
96
  @zip.close
data/lib/ydocx/parser.rb CHANGED
@@ -158,9 +158,19 @@ module YDocx
158
158
  @rel.xpath('/').children.each do |element|
159
159
  element.children.each do |rel|
160
160
  if rel['Id'] == id and rel['Target']
161
- src = id.downcase + '/' + File.basename(rel['Target'])
162
- @pictures << src
163
- return markup :img, [], {:src => src}
161
+ target = rel['Target']
162
+ source = id.downcase + '/'
163
+ if defined? Magick::Image and
164
+ ext = File.extname(target).match(/\.wmf$/).to_a[0]
165
+ source << File.basename(target, ext) + '.png'
166
+ else
167
+ source << File.basename(target)
168
+ end
169
+ @pictures << {
170
+ :origin => target,
171
+ :source => source
172
+ }
173
+ return markup :img, [], {:src => source}
164
174
  end
165
175
  end
166
176
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ydocx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &9555940 !ruby/object:Gem::Requirement
16
+ requirement: &16602400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *9555940
24
+ version_requirements: *16602400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &9555520 !ruby/object:Gem::Requirement
27
+ requirement: &16601980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *9555520
35
+ version_requirements: *16601980
36
36
  description: ''
37
37
  email:
38
38
  - yasaka@ywesee.com, zdavatz@ywesee.com