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 +5 -0
- data/README.txt +3 -1
- data/lib/version.rb +1 -1
- data/lib/ydocx/document.rb +26 -6
- data/lib/ydocx/parser.rb +13 -3
- metadata +5 -5
data/History.txt
CHANGED
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
|
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
data/lib/ydocx/document.rb
CHANGED
@@ -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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@
|
73
|
-
|
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
|
-
|
162
|
-
|
163
|
-
|
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.
|
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: &
|
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: *
|
24
|
+
version_requirements: *16602400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
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: *
|
35
|
+
version_requirements: *16601980
|
36
36
|
description: ''
|
37
37
|
email:
|
38
38
|
- yasaka@ywesee.com, zdavatz@ywesee.com
|