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 CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.2.2 / 12.07.2012
2
+
3
+ * Fixed typo in french
4
+ * Updated help output
5
+ * Updated help message about --lang option
6
+
1
7
  === 1.2.1 / 11.07.2012
2
8
 
3
9
  * Updated template, option handling for extension
data/README.txt CHANGED
@@ -1,4 +1,4 @@
1
- == ydocx - © ywesee GmbH
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: bin/docx2html file [options]
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
@@ -4,5 +4,5 @@
4
4
  require 'ydocx/document'
5
5
 
6
6
  module YDocx
7
- VERSION = '1.2.1'
7
+ VERSION = '1.2.2'
8
8
  end
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
- if option = argv.shift
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])
@@ -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 = 'DE'
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
- 'Name' => /^Name\s+des\s+Pr&auml;parates$/u, # 1
20
- 'Zusammens.' => /^Zusammensetzung($|\s*\/\s*(Wirkstoffe|Hilsstoffe)$)/u, # 2
21
- 'Galen.Form' => /^Galenische\s+Form\s*(und|\/)\s*Wirkstoffmenge\s+pro\s+Einheit$|^Forme\s*gal.nique/iu, # 3
22
- 'Ind./Anw.m&ouml;gl.' => /^Indikationen(\s+|\s*(\/|und)\s*)Anwendungsm&ouml;glichkeiten$|^Indications/u, # 4
23
- 'Dos./Anw.' => /^Dosierung\s*(\/|und)\s*Anwendung/u, # 5
24
- 'Kontraind.' => /^Kontraindikationen($|\s*\(\s*absolute\s+Kontraindikationen\s*\)$)/u, # 6
25
- 'Warn.hinw.' => /^Warnhinweise\s+und\s+Vorsichtsmassnahmen($|\s*\/\s*(relative\s+Kontraindikationen|Warnhinweise\s*und\s*Vorsichtsmassnahmen)$)/u, # 7
26
- 'Interakt.' => /^Interaktionen$|^Interactions/u, # 8
27
- 'Schwangerschaft' => /^Schwangerschaft(,\s*|\s*\/\s*|\s+und\s+)Stillzeit$/u, # 9
28
- 'Fahrt&uuml;cht.' => /^Wirkung\s+auf\s+die\s+Fahrt&uuml;chtigkeit\s+und\s+auf\s+das\s+Bedienen\s+von\s+Maschinen$/u, # 10
29
- 'Unerw.Wirkungen' => /^Unerw&uuml;nschte\s+Wirkungen$/u, # 11
30
- '&Uuml;berdos.' => /^&Uuml;berdosierung$|^Surdosage$/u, # 12
31
- 'Eigensch.' => /^Eigenschaften\s*\/\s*Wirkungen($|\s*\(\s*(ATC\-Code|Wirkungsmechanismus|Pharmakodyamik|Klinische\s+Wirksamkeit)\s*\)\s*$)|^Propri.t.s/iu, # 13
32
- 'Pharm.kinetik' => /^Pharmakokinetik($|\s*\((Absorption,\s*Distribution,\s*Metabolisms,\s*Elimination\s|Kinetik\s+spezieller\s+Patientengruppen)*\)$)|^Pharmacocin.tique?/iu, # 14
33
- 'Pr&auml;klin.' => /^Pr&auml;klinische\s+Daten$/u, # 15
34
- 'Sonstige H.' => /^Sonstige\s*Hinweise($|\s*\(\s*(Inkompatibilit&auml;ten|Beeinflussung\s*diagnostischer\s*Methoden|Haltbarkeit|Besondere\s*Lagerungshinweise|Hinweise\s+f&uuml;r\s+die\s+Handhabung)\s*\)$)|^Remarques/u, # 16
35
- 'Swissmedic-Nr.' => /^Zulassungsnummer(n|:|$|\s*\(\s*Swissmedic\s*\)$)/u, # 17
36
- 'Packungen' => /^Packungen($|\s*\(\s*mit\s+Angabe\s+der\s+Abgabekategorie\s*\)$)/u, # 18
37
- 'Reg.Inhaber' => /^Zulassungsinhaberin($|\s*\(\s*Firma\s+und\s+Sitz\s+gem&auml;ss\s*Handelsregisterauszug\s*\))/u, # 19
38
- 'Stand d. Info.' => /^Stand\s+der\s+Information$|^Mise\s+.\s+jour$/iu, # 20
39
+ :de => {
40
+ "Name" => /^Name\s+des\s+Pr&auml;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&ouml;gl." => /^Indikationen(\s+|\s*(\/|und)\s*)Anwendungsm&ouml;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&uuml;cht." => /^Wirkung\s+auf\s+die\s+Fahrt&uuml;chtigkeit\s+und\s+auf\s+das\s+Bedienen\s+von\s+Maschinen$/u, # 10
50
+ "Unerw.Wirkungen" => /^Unerw&uuml;nschte\s+Wirkungen$/u, # 11
51
+ "&Uuml;berdos." => /^&Uuml;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&auml;klin." => /^Pr&auml;klinische\s+Daten$/u, # 15
55
+ "Sonstige H." => /^Sonstige\s*Hinweise($|\s*\(\s*(Inkompatibilit&auml;ten|Beeinflussung\s*diagnostischer\s*Methoden|Haltbarkeit|Besondere\s*Lagerungshinweise|Hinweise\s+f&uuml;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&auml;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&eacute;nique\s+et\s+quantit&eacute;\s+de\s+principe\s+actif\s+par\s+unit&eacute;|^Forme\s*gal.nique/iu, # 3
65
+ "Indic./emploi" => /^Indications\s*\/\s*Possibilit&eacute;s\s+d&apos;emploi/u, # 4
66
+ "Posolog./mode d&apos;empl." => /^Posologie\s*\/\s*Mode\s+d&apos;emploi/u, # 5
67
+ "Contre-Ind." => /^Contre\-indications$/iu, # 6
68
+ "Pr&eacute;cautions" => /^Mises\s+en\s+garde\s+et\s+pr&eacute;cautions/u, # 7
69
+ "Interact." => /^Interactions$/u, # 8
70
+ "Grossesse" => /^Grossesse\s*\/\s*Allaitement/u, # 9
71
+ "Apt.conduite" => /^Effet\s+sur\s+l&apos;aptitude\s+&agrave;\s+la\s+conduite\s+et\s+l&apos;utilisation\s+de\s+machines/u, # 10
72
+ "Effets ind&eacute;sir." => /^Effets\s+ind&eacute;sirables$/u, # 11
73
+ "Surdosage" => /^Surdosage$/u, # 12
74
+ "Propri&eacute;t&eacute;s" => /^Propri&eacute;t&eacute;s\s*\/\s*Effets$/iu, # 13
75
+ "Pharm.cin&eacute;t." => /^Pharmacocin&eacute;tique$/iu, # 14
76
+ "Donn.pr&eacute;cl." => /^Donn&eacute;es\s+pr&eacute;cliniques$/u, # 15
77
+ "Remarques" => /^Remarques\s+particuli&egrave;res$/u, # 16
78
+ "Estampille" => /^Num&eacute;ro\s+d&apos;autorisation$/u, # 17
79
+ "Pr&eacute;sentations" => /^Pr&eacute;sentation$/u, # 18
80
+ "Titulaire" => /^Titulaire\s+de\s+l&apos;autorisation$/u, # 19
81
+ "Mise &agrave; jour" => /^Mise\s+.\s+jour$|^Etat\s+de\s+l&apos;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.gsub(/&(.)uml;/, '\1e').gsub(/\s*\/\s*|\s+|\/|\-/, '_').gsub(/\./, '').downcase)
91
+ CGI.escape(text.
92
+ gsub(/&(.)uml;/, '\1e').gsub(/&apos;/, '').gsub(/&(eacute|agrave);/, 'e').
93
+ gsub(/\s*\/\s*|\s+|\/|\-/, '_').gsub(/\./, '').downcase)
43
94
  end
44
- def parse_code(text) # swissmedic nummer
45
- if text =~ /^\s*(\d{2})(&lsquo;|&rsquo;|&apos;|.|\s*)(\d{3})\s*\(\s*Swiss\s*medic\s*\)(\s*|.)$/iu
46
- @code = "%5d" % ($1 + $3)
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(/&lsquo;|&rsquo;|&apos;|&acute;/, '') =~
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
- @indecies << {:text => 'Titel', :id => 'titel'}
61
- return markup(:h1, text, {:id => 'titel'})
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
- else
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.1
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-11 00:00:00.000000000 Z
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: &6667440 !ruby/object:Gem::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: *6667440
24
+ version_requirements: *14401180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &6667000 !ruby/object:Gem::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: *6667000
35
+ version_requirements: *14400740
36
36
  description: ''
37
37
  email:
38
38
  - yasaka@ywesee.com, zdavatz@ywesee.com