ydocx 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -1
- data/lib/ydocx.rb +1 -1
- data/lib/ydocx/builder.rb +6 -3
- data/lib/ydocx/document.rb +6 -8
- data/lib/ydocx/parser.rb +10 -7
- data/lib/ydocx/templates/fachinfo.rb +22 -7
- metadata +6 -6
data/History.txt
CHANGED
data/lib/ydocx.rb
CHANGED
data/lib/ydocx/builder.rb
CHANGED
@@ -16,6 +16,7 @@ module YDocx
|
|
16
16
|
@indecies = []
|
17
17
|
@references = []
|
18
18
|
@block = :div
|
19
|
+
@block_class = nil
|
19
20
|
@files = Pathname.new('.')
|
20
21
|
@style = false
|
21
22
|
@title = ''
|
@@ -63,18 +64,20 @@ module YDocx
|
|
63
64
|
def compile(contents, mode)
|
64
65
|
result = ''
|
65
66
|
headings = 0
|
67
|
+
block_start = (@block_class ? "<#{@block} class='#{@block_class}'>" : "<#{@block}>")
|
68
|
+
block_close = "</#{@block}>"
|
66
69
|
contents.each do |element|
|
67
70
|
if element[:tag].to_s =~ /^h[1-9]$/ # block
|
68
71
|
if headings == 0
|
69
|
-
result <<
|
72
|
+
result << block_start
|
70
73
|
else
|
71
|
-
result << "
|
74
|
+
result << "#{block_close}#{block_start}"
|
72
75
|
end
|
73
76
|
headings += 1
|
74
77
|
end
|
75
78
|
result << build_tag(element[:tag], element[:content], element[:attributes], mode)
|
76
79
|
end
|
77
|
-
result <<
|
80
|
+
result << block_close
|
78
81
|
end
|
79
82
|
def build_after_content
|
80
83
|
nil
|
data/lib/ydocx/document.rb
CHANGED
@@ -40,7 +40,7 @@ module YDocx
|
|
40
40
|
def output_file(ext)
|
41
41
|
@path.sub_ext(".#{ext.to_s}")
|
42
42
|
end
|
43
|
-
def to_html(
|
43
|
+
def to_html(output=false, options={})
|
44
44
|
html = ''
|
45
45
|
options = @options.merge(options)
|
46
46
|
files = output_directory
|
@@ -54,32 +54,30 @@ module YDocx
|
|
54
54
|
|
55
55
|
html = builder.build_html
|
56
56
|
end
|
57
|
-
|
57
|
+
if output
|
58
58
|
create_files if has_image?
|
59
59
|
html_file = output_file(:html)
|
60
60
|
File.open(html_file, 'w:utf-8') do |f|
|
61
61
|
f.puts html
|
62
62
|
end
|
63
|
-
else
|
64
|
-
html
|
65
63
|
end
|
64
|
+
html
|
66
65
|
end
|
67
|
-
def to_xml(
|
66
|
+
def to_xml(output=false, options={})
|
68
67
|
xml = ''
|
69
68
|
options = @options.merge(options)
|
70
69
|
Builder.new(@contents) do |builder|
|
71
70
|
builder.block = options.has_key?(:block) ? options[:block] : :chapter
|
72
71
|
xml = builder.build_xml
|
73
72
|
end
|
74
|
-
|
73
|
+
if output
|
75
74
|
xml_file = output_file(:xml)
|
76
75
|
mkdir xml_file.parent
|
77
76
|
File.open(xml_file, 'w:utf-8') do |f|
|
78
77
|
f.puts xml
|
79
78
|
end
|
80
|
-
else
|
81
|
-
xml
|
82
79
|
end
|
80
|
+
xml
|
83
81
|
end
|
84
82
|
private
|
85
83
|
def create_files
|
data/lib/ydocx/parser.rb
CHANGED
@@ -188,13 +188,7 @@ module YDocx
|
|
188
188
|
rel.children.each do |r|
|
189
189
|
if r['Id'] == id and r['Target']
|
190
190
|
target = r['Target']
|
191
|
-
source =
|
192
|
-
if defined? Magick::Image and
|
193
|
-
ext = File.extname(target).match(/\.wmf$/).to_a[0]
|
194
|
-
source << File.basename(target, ext) + '.png'
|
195
|
-
else
|
196
|
-
source << File.basename(target)
|
197
|
-
end
|
191
|
+
source = source_path(target)
|
198
192
|
@images << {
|
199
193
|
:origin => target,
|
200
194
|
:source => source
|
@@ -208,6 +202,15 @@ module YDocx
|
|
208
202
|
end
|
209
203
|
nil
|
210
204
|
end
|
205
|
+
def source_path(target)
|
206
|
+
source = @image_path + '/'
|
207
|
+
if defined? Magick::Image and
|
208
|
+
ext = File.extname(target).match(/\.wmf$/).to_a[0]
|
209
|
+
source << File.basename(target, ext) + '.png'
|
210
|
+
else
|
211
|
+
source << File.basename(target)
|
212
|
+
end
|
213
|
+
end
|
211
214
|
def parse_paragraph(node)
|
212
215
|
content = []
|
213
216
|
if block = parse_block(node)
|
@@ -5,10 +5,11 @@ require 'cgi'
|
|
5
5
|
|
6
6
|
module YDocx
|
7
7
|
class Parser
|
8
|
-
|
8
|
+
attr_accessor :code, :lang
|
9
9
|
def init
|
10
10
|
@image_path = 'image'
|
11
11
|
@code = nil
|
12
|
+
@lang = 'DE'
|
12
13
|
end
|
13
14
|
private
|
14
15
|
def chapters
|
@@ -31,7 +32,7 @@ module YDocx
|
|
31
32
|
'Pharm.kinetik' => /^Pharmakokinetik($|\s*\((Absorption,\s*Distribution,\s*Metabolisms,\s*Elimination\s|Kinetik\s+spezieller\s+Patientengruppen)*\)$)|^Pharmacocin.tique?/iu, # 14
|
32
33
|
'Präklin.' => /^Präklinische\s+Daten$/u, # 15
|
33
34
|
'Sonstige H.' => /^Sonstige\s*Hinweise($|\s*\(\s*(Inkompatibilitäten|Beeinflussung\s*diagnostischer\s*Methoden|Haltbarkeit|Besondere\s*Lagerungshinweise|Hinweise\s+für\s+die\s+Handhabung)\s*\)$)|^Remarques/u, # 16
|
34
|
-
'Swissmedic-Nr.' => /^Zulassungsnummer(
|
35
|
+
'Swissmedic-Nr.' => /^Zulassungsnummer(n|:|$|\s*\(\s*Swissmedic\s*\)$)/u, # 17
|
35
36
|
'Packungen' => /^Packungen($|\s*\(\s*mit\s+Angabe\s+der\s+Abgabekategorie\s*\)$)/u, # 18
|
36
37
|
'Reg.Inhaber' => /^Zulassungsinhaberin($|\s*\(\s*Firma\s+und\s+Sitz\s+gemäss\s*Handelsregisterauszug\s*\))/u, # 19
|
37
38
|
'Stand d. Info.' => /^Stand\s+der\s+Information$|^Mise\s+.\s+jour$/iu, # 20
|
@@ -49,6 +50,19 @@ module YDocx
|
|
49
50
|
nil
|
50
51
|
end
|
51
52
|
end
|
53
|
+
def parse_heading(text, id)
|
54
|
+
return markup(:h2, text, {:id => id})
|
55
|
+
end
|
56
|
+
def parse_title(node, text)
|
57
|
+
if @indecies.empty? and !text.empty? and
|
58
|
+
(node.previous.inner_text.strip.empty? or node.parent.previous.nil?)
|
59
|
+
# The first line as package name
|
60
|
+
@indecies << {:text => 'Titel', :id => 'titel'}
|
61
|
+
return markup(:h1, text, {:id => 'titel'})
|
62
|
+
else
|
63
|
+
return nil
|
64
|
+
end
|
65
|
+
end
|
52
66
|
def parse_block(node)
|
53
67
|
text = node.inner_text.strip
|
54
68
|
text = optional_escape text
|
@@ -58,15 +72,13 @@ module YDocx
|
|
58
72
|
# next if !node.previous.inner_text.empty? and !node.next.inner_text.empty?
|
59
73
|
id = escape_id(chapter)
|
60
74
|
@indecies << {:text => chapter, :id => id}
|
61
|
-
return
|
75
|
+
return parse_heading(text, id)
|
62
76
|
elsif parse_code(text)
|
63
77
|
return nil
|
64
78
|
end
|
65
79
|
end
|
66
|
-
if
|
67
|
-
|
68
|
-
@indecies << {:text => 'Titel', :id => 'titel'}
|
69
|
-
return markup(:h2, text, {:id => 'titel'})
|
80
|
+
if title = parse_title(node, text)
|
81
|
+
return title
|
70
82
|
end
|
71
83
|
return nil
|
72
84
|
end
|
@@ -205,6 +217,8 @@ div#container {
|
|
205
217
|
# now returns just true
|
206
218
|
true
|
207
219
|
end
|
220
|
+
def optional_copy(source_path)
|
221
|
+
end
|
208
222
|
# NOTE
|
209
223
|
# Image reference option
|
210
224
|
# Currently, this supports only all images or first one reference.
|
@@ -220,6 +234,7 @@ div#container {
|
|
220
234
|
else
|
221
235
|
copy_or_convert(origin_path, source_path)
|
222
236
|
end
|
237
|
+
optional_copy(source_path)
|
223
238
|
end
|
224
239
|
def prepare_reference
|
225
240
|
ARGV.reverse.each do |arg|
|
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.2.
|
4
|
+
version: 1.2.1
|
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-07-
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &6667440 !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: *6667440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &6667000 !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: *6667000
|
36
36
|
description: ''
|
37
37
|
email:
|
38
38
|
- yasaka@ywesee.com, zdavatz@ywesee.com
|