ydocx 1.1.2 → 1.1.3

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.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.1.3 / 08.05.2012
2
+
3
+ * Updated image copy as binary mode
4
+
1
5
  === 1.1.2 / 07.05.2012
2
6
 
3
7
  * Fixed bug in xpath for multi images
@@ -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('w') do |f|
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('w') do |f|
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('w') do |f|
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
- ref = @zip.find_entry('word/_rels/document.xml.rels').get_input_stream
113
- Parser.new(doc, ref) do |parser|
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
- paths = {
156
- :id => 'w:pict//v:shape//v:imagedata',
157
- :embed => 'w:drawing//wp:anchor//a:graphic//a:graphicData//pic:pic//pic:blipFill//a:blip'
158
- }.each do |attr, path|
159
- if image = r.xpath(path, ns) and !image.empty?
160
- (id = image.first[attr.to_s]) && break
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 |element|
165
- element.children.each do |rel|
166
- if rel['Id'] == id and rel['Target']
167
- target = rel['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
- return markup :img, [], {:src => source}
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
@@ -4,5 +4,5 @@
4
4
  require 'ydocx/document'
5
5
 
6
6
  module YDocx
7
- VERSION = '1.1.2'
7
+ VERSION = '1.1.3'
8
8
  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.1.2
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-07 00:00:00.000000000 Z
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: &17798620 !ruby/object:Gem::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: *17798620
24
+ version_requirements: *24016920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &17798200 !ruby/object:Gem::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: *17798200
35
+ version_requirements: *24016500
36
36
  description: ''
37
37
  email:
38
38
  - yasaka@ywesee.com, zdavatz@ywesee.com