ydocx 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/README.txt +3 -2
- data/lib/ydocx.rb +1 -1
- data/lib/ydocx/command.rb +50 -36
- data/lib/ydocx/document.rb +1 -0
- data/lib/ydocx/templates/fachinfo.rb +86 -33
- metadata +6 -6
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
== ydocx
|
1
|
+
== ydocx by ywesee GmbH
|
2
2
|
|
3
3
|
* https://github.com/zdavatz/ydocx
|
4
4
|
* Parsing docx files with Ruby and output them as HTML and XML.
|
@@ -18,9 +18,10 @@
|
|
18
18
|
|
19
19
|
== Usage
|
20
20
|
|
21
|
-
* Usage:
|
21
|
+
* Usage: docx2html file [options]
|
22
22
|
-f, --format Format of style and chapter {(fi|fachinfo)|(pi|patinfo)|(pl|plain)|none}, default fachinfo.
|
23
23
|
-h, --help Display this help message.
|
24
|
+
-l, --lang Language option for templates {de|fr}
|
24
25
|
-v, --version Show version.
|
25
26
|
|
26
27
|
== Using the great libraries
|
data/lib/ydocx.rb
CHANGED
data/lib/ydocx/command.rb
CHANGED
@@ -6,8 +6,9 @@ require 'ydocx'
|
|
6
6
|
module YDocx
|
7
7
|
class Command
|
8
8
|
class << self
|
9
|
-
@@help = /^\-(h|\-help)$/u
|
10
9
|
@@format = /^\-(f|\-format)$/u
|
10
|
+
@@help = /^\-(h|\-help)$/u
|
11
|
+
@@lang = /^\-(l|\-lang)$/u
|
11
12
|
@@version = /^\-(v|\-version)$/u
|
12
13
|
def error(message='')
|
13
14
|
puts message
|
@@ -25,11 +26,57 @@ module YDocx
|
|
25
26
|
Usage: #{self.command} file [options]
|
26
27
|
-f, --format Format of style and chapter {(fi|fachinfo)|(pi|patinfo)|(pl|plain)|none}, default fachinfo.
|
27
28
|
-h, --help Display this help message.
|
29
|
+
-l, --lang Language option for templates {de|fr}
|
28
30
|
-v, --version Show version.
|
29
31
|
BANNER
|
30
32
|
puts banner
|
31
33
|
exit
|
32
34
|
end
|
35
|
+
def parse(action, argv)
|
36
|
+
if argv.length.odd?
|
37
|
+
self.error "#{self.command}: exit with: Invalid option"
|
38
|
+
else
|
39
|
+
args = Hash[*argv]
|
40
|
+
end
|
41
|
+
options = {}
|
42
|
+
args.each_pair do |option, value|
|
43
|
+
if option =~ @@format
|
44
|
+
case value
|
45
|
+
when 'fi', 'fachinfo'
|
46
|
+
require 'ydocx/templates/fachinfo'
|
47
|
+
options.merge!({:style => :frame}) if action == :to_html
|
48
|
+
when 'pi', 'patinfo'
|
49
|
+
require 'ydocx/templates/patinfo'
|
50
|
+
options.merge!({:style => :frame}) if action == :to_html
|
51
|
+
when 'pl', 'plain'
|
52
|
+
options.merge!({:style => true}) if action == :to_html
|
53
|
+
when 'none'
|
54
|
+
# pass
|
55
|
+
else
|
56
|
+
self.error "#{self.command}: exit with #{option}: Invalid argument"
|
57
|
+
end
|
58
|
+
elsif option =~ @@help
|
59
|
+
self.help
|
60
|
+
elsif option =~ @@lang
|
61
|
+
options.merge!({:lang => value})
|
62
|
+
elsif option.downcase =~ /\.(jpeg|jpg|png|gif)$/u and action == :to_html
|
63
|
+
# allow as default
|
64
|
+
# TODO
|
65
|
+
# refactor as normal option
|
66
|
+
# currently, support fachinfo/patinfo format only
|
67
|
+
require 'ydocx/templates/fachinfo'
|
68
|
+
options.merge!({:style => :frame})
|
69
|
+
else
|
70
|
+
self.error "#{self.command}: exit with #{option}: Unknown option"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
if !args.include?('-f') and !args.include?('--format')
|
74
|
+
# default fachinfo
|
75
|
+
require 'ydocx/templates/fachinfo'
|
76
|
+
options.merge!({:style => :frame}) if action == :to_html
|
77
|
+
end
|
78
|
+
options
|
79
|
+
end
|
33
80
|
def report(action, path)
|
34
81
|
puts "#{self.command}: generated #{File.expand_path(path)}"
|
35
82
|
exit
|
@@ -48,41 +95,8 @@ Usage: #{self.command} file [options]
|
|
48
95
|
elsif !File.extname(path).match(/^\.docx$/)
|
49
96
|
self.error "#{self.command}: cannot open #{file}: Not a docx file"
|
50
97
|
else
|
51
|
-
options =
|
52
|
-
|
53
|
-
if option =~ @@format
|
54
|
-
case argv[0]
|
55
|
-
when 'fi', 'fachinfo'
|
56
|
-
require 'ydocx/templates/fachinfo'
|
57
|
-
options.merge!({:style => :frame}) if action == :to_html
|
58
|
-
when 'pi', 'patinfo'
|
59
|
-
require 'ydocx/templates/patinfo'
|
60
|
-
options.merge!({:style => :frame}) if action == :to_html
|
61
|
-
when 'pl', 'plain'
|
62
|
-
options.merge!({:style => true}) if action == :to_html
|
63
|
-
when 'none'
|
64
|
-
# pass
|
65
|
-
else
|
66
|
-
self.error "#{self.command}: exit with #{option}: Invalid argument"
|
67
|
-
end
|
68
|
-
elsif option =~ @@help
|
69
|
-
self.help
|
70
|
-
elsif option.downcase =~ /\.(jpeg|jpg|png|gif)$/u and action == :to_html
|
71
|
-
# allow as default
|
72
|
-
# TODO
|
73
|
-
# refactor as normal option
|
74
|
-
# currently, support fachinfo/patinfo format only
|
75
|
-
require 'ydocx/templates/fachinfo'
|
76
|
-
options.merge!({:style => :frame})
|
77
|
-
else
|
78
|
-
self.error "#{self.command}: exit with #{option}: Unknown option"
|
79
|
-
end
|
80
|
-
else
|
81
|
-
# default fachinfo
|
82
|
-
require 'ydocx/templates/fachinfo'
|
83
|
-
options.merge!({:style => :frame}) if action == :to_html
|
84
|
-
end
|
85
|
-
doc = YDocx::Document.open(path)
|
98
|
+
options = self.parse(action, argv)
|
99
|
+
doc = YDocx::Document.open(path, options)
|
86
100
|
doc.send(action, path, options)
|
87
101
|
ext = self.extname(action)
|
88
102
|
self.report action, doc.output_file(ext[1..-1])
|
data/lib/ydocx/document.rb
CHANGED
@@ -122,6 +122,7 @@ module YDocx
|
|
122
122
|
doc = @zip.find_entry('word/document.xml').get_input_stream
|
123
123
|
rel = @zip.find_entry('word/_rels/document.xml.rels').get_input_stream
|
124
124
|
@parser = Parser.new(doc, rel) do |parser|
|
125
|
+
parser.lang = @options[:lang] if @options[:lang]
|
125
126
|
@contents = parser.parse
|
126
127
|
@indecies = parser.indecies
|
127
128
|
@images = parser.images
|
@@ -9,42 +9,92 @@ module YDocx
|
|
9
9
|
def init
|
10
10
|
@image_path = 'image'
|
11
11
|
@code = nil
|
12
|
-
@lang
|
12
|
+
@lang ||= 'de'
|
13
13
|
end
|
14
14
|
private
|
15
|
+
###
|
16
|
+
# Fachinfo Chapters
|
17
|
+
# 1. name
|
18
|
+
# 2. composition
|
19
|
+
# 3. galenic form
|
20
|
+
# 4. indications
|
21
|
+
# 5. usage
|
22
|
+
# 6. contra_indications
|
23
|
+
# 7. restrictions
|
24
|
+
# 8. interactions
|
25
|
+
# 9. pregnancy
|
26
|
+
# 10. driving_ability
|
27
|
+
# 11. unwanted_effects
|
28
|
+
# 12. overdose
|
29
|
+
# 13. effects
|
30
|
+
# 14. kinetic
|
31
|
+
# 15. preclinic
|
32
|
+
# 16. other_advice
|
33
|
+
# 17. iksnr
|
34
|
+
# 19. packages
|
35
|
+
# 19. registration_owner
|
36
|
+
# 20. date
|
15
37
|
def chapters
|
16
|
-
# TODO
|
17
|
-
# Franzoesisch
|
18
38
|
chapters = {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
:de => {
|
40
|
+
"Name" => /^Name\s+des\s+Präparates$/u, # 1
|
41
|
+
"Zusammens." => /^Zusammensetzung($|\s*\/\s*(Wirkstoffe|Hilsstoffe)$)/u, # 2
|
42
|
+
"Galen.Form" => /^Galenische\s+Form\s*(und|\/)\s*Wirkstoffmenge\s+pro\s+Einheit$/iu, # 3
|
43
|
+
"Ind./Anw.mögl." => /^Indikationen(\s+|\s*(\/|und)\s*)Anwendungsmöglichkeiten$/u, # 4
|
44
|
+
"Dos./Anw." => /^Dosierung\s*(\/|und)\s*Anwendung/u, # 5
|
45
|
+
"Kontraind." => /^Kontraindikationen($|\s*\(\s*absolute\s+Kontraindikationen\s*\)$)/u, # 6
|
46
|
+
"Warn.hinw." => /^Warnhinweise\s+und\s+Vorsichtsmassnahmen($|\s*\/\s*(relative\s+Kontraindikationen|Warnhinweise\s*und\s*Vorsichtsmassnahmen)$)/u, # 7
|
47
|
+
"Interakt." => /^Interaktionen$/u, # 8
|
48
|
+
"Schwangerschaft" => /^Schwangerschaft(,\s*|\s*\/\s*|\s+und\s+)Stillzeit$/u, # 9
|
49
|
+
"Fahrtücht." => /^Wirkung\s+auf\s+die\s+Fahrtüchtigkeit\s+und\s+auf\s+das\s+Bedienen\s+von\s+Maschinen$/u, # 10
|
50
|
+
"Unerw.Wirkungen" => /^Unerwünschte\s+Wirkungen$/u, # 11
|
51
|
+
"Überdos." => /^Überdosierung$/u, # 12
|
52
|
+
"Eigensch." => /^Eigenschaften\s*\/\s*Wirkungen($|\s*\(\s*(ATC\-Code|Wirkungsmechanismus|Pharmakodyamik|Klinische\s+Wirksamkeit)\s*\)\s*$)/iu, # 13
|
53
|
+
"Pharm.kinetik" => /^Pharmakokinetik($|\s*\((Absorption,\s*Distribution,\s*Metabolisms,\s*Elimination\s|Kinetik\s+spezieller\s+Patientengruppen)*\)$)/iu, # 14
|
54
|
+
"Präklin." => /^Präklinische\s+Daten$/u, # 15
|
55
|
+
"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
|
56
|
+
"Swissmedic-Nr." => /^Zulassungsnummer(n|:|$|\s*\(\s*Swissmedic\s*\)$)/u, # 17
|
57
|
+
"Packungen" => /^Packungen($|\s*\(\s*mit\s+Angabe\s+der\s+Abgabekategorie\s*\)$)/u, # 18
|
58
|
+
"Reg.Inhaber" => /^Zulassungsinhaberin($|\s*\(\s*Firma\s+und\s+Sitz\s+gemäss\s*Handelsregisterauszug\s*\))/u, # 19
|
59
|
+
"Stand d. Info." => /^Stand\s+der\s+Information$/iu, # 20
|
60
|
+
},
|
61
|
+
:fr => {
|
62
|
+
"Nom" => /^Nom$/u, # 1
|
63
|
+
"Composit." => /^Composition$/u, # 2
|
64
|
+
"Forme gal." => /^Forme\s+galénique\s+et\s+quantité\s+de\s+principe\s+actif\s+par\s+unité|^Forme\s*gal.nique/iu, # 3
|
65
|
+
"Indic./emploi" => /^Indications\s*\/\s*Possibilités\s+d'emploi/u, # 4
|
66
|
+
"Posolog./mode d'empl." => /^Posologie\s*\/\s*Mode\s+d'emploi/u, # 5
|
67
|
+
"Contre-Ind." => /^Contre\-indications$/iu, # 6
|
68
|
+
"Précautions" => /^Mises\s+en\s+garde\s+et\s+précautions/u, # 7
|
69
|
+
"Interact." => /^Interactions$/u, # 8
|
70
|
+
"Grossesse" => /^Grossesse\s*\/\s*Allaitement/u, # 9
|
71
|
+
"Apt.conduite" => /^Effet\s+sur\s+l'aptitude\s+à\s+la\s+conduite\s+et\s+l'utilisation\s+de\s+machines/u, # 10
|
72
|
+
"Effets indésir." => /^Effets\s+indésirables$/u, # 11
|
73
|
+
"Surdosage" => /^Surdosage$/u, # 12
|
74
|
+
"Propriétés" => /^Propriétés\s*\/\s*Effets$/iu, # 13
|
75
|
+
"Pharm.cinét." => /^Pharmacocinétique$/iu, # 14
|
76
|
+
"Donn.précl." => /^Données\s+précliniques$/u, # 15
|
77
|
+
"Remarques" => /^Remarques\s+particulières$/u, # 16
|
78
|
+
"Estampille" => /^Numéro\s+d'autorisation$/u, # 17
|
79
|
+
"Présentations" => /^Présentation$/u, # 18
|
80
|
+
"Titulaire" => /^Titulaire\s+de\s+l'autorisation$/u, # 19
|
81
|
+
"Mise à jour" => /^Mise\s+.\s+jour$|^Etat\s+de\s+l'information/iu, # 20
|
82
|
+
}
|
39
83
|
}
|
84
|
+
if @lang == 'fr'
|
85
|
+
chapters[:fr]
|
86
|
+
else
|
87
|
+
chapters[:de]
|
88
|
+
end
|
40
89
|
end
|
41
90
|
def escape_id(text)
|
42
|
-
CGI.escape(text.
|
91
|
+
CGI.escape(text.
|
92
|
+
gsub(/&(.)uml;/, '\1e').gsub(/'/, '').gsub(/&(eacute|agrave);/, 'e').
|
93
|
+
gsub(/\s*\/\s*|\s+|\/|\-/, '_').gsub(/\./, '').downcase)
|
43
94
|
end
|
44
|
-
def parse_code(text) # swissmedic
|
45
|
-
if text
|
46
|
-
|
47
|
-
elsif text =~ /^\s*(\d{5})(.*|\s*)\s*\(\s*Swiss\s*medic\s*\)(\s*|.)$/iu
|
95
|
+
def parse_code(text) # swissmedic number
|
96
|
+
if text.gsub(/‘|’|'|´/, '') =~
|
97
|
+
/^\s*(\d{5})(.*|\s*)\s*\(\s*Swiss\s*medic\s*\)(\s*|.)$/iu
|
48
98
|
@code = "%5d" % $1
|
49
99
|
else
|
50
100
|
nil
|
@@ -57,8 +107,9 @@ module YDocx
|
|
57
107
|
if @indecies.empty? and !text.empty? and
|
58
108
|
(node.previous.inner_text.strip.empty? or node.parent.previous.nil?)
|
59
109
|
# The first line as package name
|
60
|
-
@
|
61
|
-
|
110
|
+
title = (@lang == 'fr' ? 'Titre' : 'Titel')
|
111
|
+
@indecies << {:text => title, :id => title.downcase}
|
112
|
+
return markup(:h1, text, {:id => title.downcase})
|
62
113
|
else
|
63
114
|
return nil
|
64
115
|
end
|
@@ -177,11 +228,13 @@ div#container {
|
|
177
228
|
end
|
178
229
|
style.gsub(/\s\s+|\n/, ' ')
|
179
230
|
end
|
180
|
-
def resolve_path(path)
|
231
|
+
def resolve_path(path) # image src
|
181
232
|
if reference = @references.shift
|
182
233
|
File.dirname(path) + '/' + reference.basename.to_s
|
183
|
-
|
234
|
+
elsif @files.to_s =~ /\d{5}/
|
184
235
|
path
|
236
|
+
else
|
237
|
+
@files.join path
|
185
238
|
end
|
186
239
|
end
|
187
240
|
end
|
@@ -202,7 +255,7 @@ div#container {
|
|
202
255
|
end
|
203
256
|
@files
|
204
257
|
end
|
205
|
-
def output_file(ext)
|
258
|
+
def output_file(ext) # html
|
206
259
|
if @parser.code
|
207
260
|
filename = @parser.code
|
208
261
|
output_directory.join "#{filename}.#{ext.to_s}"
|
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.2
|
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-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &14401180 !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: *14401180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &14400740 !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: *14400740
|
36
36
|
description: ''
|
37
37
|
email:
|
38
38
|
- yasaka@ywesee.com, zdavatz@ywesee.com
|