ydocx 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/ydocx/document.rb +9 -9
- data/lib/ydocx/parser.rb +8 -7
- data/lib/ydocx/templates/fachinfo.rb +3 -0
- data/lib/ydocx/templates/patinfo.rb +3 -0
- data/lib/ydocx.rb +1 -1
- metadata +5 -5
data/History.txt
CHANGED
data/lib/ydocx/document.rb
CHANGED
@@ -13,14 +13,14 @@ require 'ydocx/builder'
|
|
13
13
|
|
14
14
|
module YDocx
|
15
15
|
class Document
|
16
|
-
attr_reader :contents, :indecies, :
|
16
|
+
attr_reader :contents, :indecies, :images
|
17
17
|
def self.open(file, options={})
|
18
18
|
self.new(file, options)
|
19
19
|
end
|
20
20
|
def initialize(file, options={})
|
21
21
|
@contents = nil
|
22
22
|
@indecies = nil
|
23
|
-
@
|
23
|
+
@images = []
|
24
24
|
@options = options
|
25
25
|
@path = nil
|
26
26
|
@files = nil
|
@@ -44,7 +44,7 @@ module YDocx
|
|
44
44
|
html = builder.build_html
|
45
45
|
end
|
46
46
|
unless file.empty?
|
47
|
-
create_files if
|
47
|
+
create_files if has_image?
|
48
48
|
html_file = @path.sub_ext('.html')
|
49
49
|
File.open(html_file, 'w:utf-8') do |f|
|
50
50
|
f.puts html
|
@@ -73,9 +73,9 @@ module YDocx
|
|
73
73
|
def create_files
|
74
74
|
FileUtils.mkdir @files unless @files.exist?
|
75
75
|
@zip = Zip::ZipFile.open(@path.realpath)
|
76
|
-
@
|
77
|
-
origin_path = Pathname.new
|
78
|
-
source_path = Pathname.new
|
76
|
+
@images.each do |image|
|
77
|
+
origin_path = Pathname.new image[:origin] # media/filename.ext
|
78
|
+
source_path = Pathname.new image[:source] # images/filename.ext
|
79
79
|
dir = @files.join source_path.dirname
|
80
80
|
FileUtils.mkdir dir unless dir.exist?
|
81
81
|
organize_image(origin_path, source_path)
|
@@ -102,8 +102,8 @@ module YDocx
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
|
-
def
|
106
|
-
!@
|
105
|
+
def has_image?
|
106
|
+
!@images.empty?
|
107
107
|
end
|
108
108
|
def read(file)
|
109
109
|
@path = Pathname.new file
|
@@ -113,7 +113,7 @@ module YDocx
|
|
113
113
|
Parser.new(doc, ref) do |parser|
|
114
114
|
@contents = parser.parse
|
115
115
|
@indecies = parser.indecies
|
116
|
-
@
|
116
|
+
@images = parser.images
|
117
117
|
end
|
118
118
|
@zip.close
|
119
119
|
end
|
data/lib/ydocx/parser.rb
CHANGED
@@ -8,15 +8,16 @@ require 'ydocx/markup_method'
|
|
8
8
|
module YDocx
|
9
9
|
class Parser
|
10
10
|
include MarkupMethod
|
11
|
-
attr_accessor :indecies, :
|
11
|
+
attr_accessor :indecies, :images, :result, :space
|
12
12
|
def initialize(doc, rel)
|
13
13
|
@doc = Nokogiri::XML.parse(doc)
|
14
14
|
@rel = Nokogiri::XML.parse(rel)
|
15
15
|
@coder = HTMLEntities.new
|
16
16
|
@indecies = []
|
17
|
-
@
|
17
|
+
@images = []
|
18
18
|
@result = []
|
19
19
|
@space = ' '
|
20
|
+
@image_path = 'images'
|
20
21
|
init
|
21
22
|
if block_given?
|
22
23
|
yield self
|
@@ -152,11 +153,11 @@ module YDocx
|
|
152
153
|
}
|
153
154
|
ns = r.namespaces.merge additional_namespaces
|
154
155
|
paths = {
|
155
|
-
:id => '
|
156
|
-
:embed => '
|
156
|
+
:id => 'w:pict//v:shape//v:imagedata',
|
157
|
+
:embed => 'w:drawing//wp:anchor//a:graphic//a:graphicData//pic:pic//pic:blipFill//a:blip'
|
157
158
|
}.each do |attr, path|
|
158
159
|
if image = r.xpath(path, ns) and !image.empty?
|
159
|
-
id = image.first[attr.to_s]
|
160
|
+
(id = image.first[attr.to_s]) && break
|
160
161
|
end
|
161
162
|
end
|
162
163
|
if id
|
@@ -164,14 +165,14 @@ module YDocx
|
|
164
165
|
element.children.each do |rel|
|
165
166
|
if rel['Id'] == id and rel['Target']
|
166
167
|
target = rel['Target']
|
167
|
-
source =
|
168
|
+
source = @image_path + '/'
|
168
169
|
if defined? Magick::Image and
|
169
170
|
ext = File.extname(target).match(/\.wmf$/).to_a[0]
|
170
171
|
source << File.basename(target, ext) + '.png'
|
171
172
|
else
|
172
173
|
source << File.basename(target)
|
173
174
|
end
|
174
|
-
@
|
175
|
+
@images << {
|
175
176
|
:origin => target,
|
176
177
|
:source => source
|
177
178
|
}
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &17798620 !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: *17798620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &17798200 !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: *17798200
|
36
36
|
description: ''
|
37
37
|
email:
|
38
38
|
- yasaka@ywesee.com, zdavatz@ywesee.com
|