ydocx 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/ydocx/document.rb +5 -5
- data/lib/ydocx/parser.rb +30 -11
- data/lib/ydocx.rb +1 -1
- metadata +6 -6
data/History.txt
CHANGED
data/lib/ydocx/document.rb
CHANGED
@@ -88,16 +88,16 @@ module YDocx
|
|
88
88
|
if defined? Magick::Image
|
89
89
|
image = Magick::Image.from_blob(binary.read).first
|
90
90
|
image.format = source_path.extname[1..-1].upcase
|
91
|
-
@files.join(source_path).open('
|
91
|
+
@files.join(source_path).open('wb') do |f|
|
92
92
|
f.puts image.to_blob
|
93
93
|
end
|
94
94
|
else # copy original image
|
95
|
-
@files.join(dir, origin_path.basename).open('
|
95
|
+
@files.join(dir, origin_path.basename).open('wb') do |f|
|
96
96
|
f.puts binary.read
|
97
97
|
end
|
98
98
|
end
|
99
99
|
else
|
100
|
-
@files.join(source_path).open('
|
100
|
+
@files.join(source_path).open('wb') do |f|
|
101
101
|
f.puts binary.read
|
102
102
|
end
|
103
103
|
end
|
@@ -109,8 +109,8 @@ module YDocx
|
|
109
109
|
@path = Pathname.new file
|
110
110
|
@zip = Zip::ZipFile.open(@path.realpath)
|
111
111
|
doc = @zip.find_entry('word/document.xml').get_input_stream
|
112
|
-
|
113
|
-
Parser.new(doc,
|
112
|
+
rel = @zip.find_entry('word/_rels/document.xml.rels').get_input_stream
|
113
|
+
Parser.new(doc, rel) do |parser|
|
114
114
|
@contents = parser.parse
|
115
115
|
@indecies = parser.indecies
|
116
116
|
@images = parser.images
|
data/lib/ydocx/parser.rb
CHANGED
@@ -18,6 +18,7 @@ module YDocx
|
|
18
18
|
@result = []
|
19
19
|
@space = ' '
|
20
20
|
@image_path = 'images'
|
21
|
+
@image_style = ''
|
21
22
|
init
|
22
23
|
if block_given?
|
23
24
|
yield self
|
@@ -152,19 +153,35 @@ module YDocx
|
|
152
153
|
'xmlns:pic' => 'http://schemas.openxmlformats.org/drawingml/2006/picture'
|
153
154
|
}
|
154
155
|
ns = r.namespaces.merge additional_namespaces
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
156
|
+
[
|
157
|
+
{
|
158
|
+
:attr => 'id',
|
159
|
+
:path => 'w:pict//v:shape//v:imagedata',
|
160
|
+
:wrap => 'w:pict//v:shape//w10:wrap',
|
161
|
+
:type => 'type',
|
162
|
+
},
|
163
|
+
{
|
164
|
+
:attr => 'embed',
|
165
|
+
:path => 'w:drawing//wp:anchor//a:graphic//a:graphicData//pic:pic//pic:blipFill//a:blip',
|
166
|
+
:wrap => 'w:drawing//wp:anchor//wp:wrapTight',
|
167
|
+
:type => 'wrapText',
|
168
|
+
},
|
169
|
+
].each do |element|
|
170
|
+
if image = r.xpath(element[:path], ns) and !image.empty?
|
171
|
+
if wrap = r.xpath("#{element[:wrap]}", ns).first
|
172
|
+
# TODO
|
173
|
+
# wrap handling (currently all wrap off)
|
174
|
+
# wrap[element[:type]] has "bothSides", "topAndBottom"
|
175
|
+
@image_style = 'display:block;'
|
176
|
+
end
|
177
|
+
(id = image.first[element[:attr].to_s]) && break
|
161
178
|
end
|
162
179
|
end
|
163
180
|
if id
|
164
|
-
@rel.xpath('/').children.each do |
|
165
|
-
|
166
|
-
if
|
167
|
-
target =
|
181
|
+
@rel.xpath('/').children.each do |rel|
|
182
|
+
rel.children.each do |r|
|
183
|
+
if r['Id'] == id and r['Target']
|
184
|
+
target = r['Target']
|
168
185
|
source = @image_path + '/'
|
169
186
|
if defined? Magick::Image and
|
170
187
|
ext = File.extname(target).match(/\.wmf$/).to_a[0]
|
@@ -176,7 +193,9 @@ module YDocx
|
|
176
193
|
:origin => target,
|
177
194
|
:source => source
|
178
195
|
}
|
179
|
-
|
196
|
+
attributes = {:src => source}
|
197
|
+
attributes.merge!({:style => @image_style}) unless @image_style.empty?
|
198
|
+
return markup :img, [], attributes
|
180
199
|
end
|
181
200
|
end
|
182
201
|
end
|
data/lib/ydocx.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &24016920 !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: *24016920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &24016500 !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: *24016500
|
36
36
|
description: ''
|
37
37
|
email:
|
38
38
|
- yasaka@ywesee.com, zdavatz@ywesee.com
|