ebps 1.0.2

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.
Files changed (57) hide show
  1. data/History.txt +3 -0
  2. data/InstalledFiles +36 -0
  3. data/LICENSE.txt +339 -0
  4. data/Manifest.txt +56 -0
  5. data/README.txt +28 -0
  6. data/Rakefile +28 -0
  7. data/SetupConfig +30 -0
  8. data/bin/ebps +86 -0
  9. data/example/config.yml +12 -0
  10. data/example/converter_for_firefox.rb +59 -0
  11. data/example/data.yml +60 -0
  12. data/example/example.sh +3 -0
  13. data/example/sample.epub +0 -0
  14. data/lib/ebps.rb +5 -0
  15. data/lib/ebps/config.rb +61 -0
  16. data/lib/ebps/conversion/de_fachinfo_yaml.rb +81 -0
  17. data/lib/ebps/conversion/epub.rb +38 -0
  18. data/lib/ebps/conversion/fachinfo_xml.rb +170 -0
  19. data/lib/ebps/conversion/fachinfo_yaml.rb +113 -0
  20. data/lib/ebps/conversion/import_module_sample.rb +86 -0
  21. data/lib/ebps/conversion/mobi_pocket.rb +30 -0
  22. data/lib/ebps/conversion/oebps.rb +537 -0
  23. data/lib/ebps/conversion/patinfo_yaml.rb +107 -0
  24. data/lib/ebps/data/default_cover.jpg +0 -0
  25. data/lib/ebps/data/stylesheet.css +16 -0
  26. data/lib/ebps/postprocess/bookworm.rb +16 -0
  27. data/lib/ebps/postprocess/copy.rb +28 -0
  28. data/lib/ebps/postprocess/system_call.rb +18 -0
  29. data/lib/ebps/preprocess/copy.rb +28 -0
  30. data/lib/ebps/preprocess/system_call.rb +18 -0
  31. data/lib/ebps/text/chapter.rb +36 -0
  32. data/lib/ebps/text/document.rb +36 -0
  33. data/lib/ebps/text/format.rb +34 -0
  34. data/lib/ebps/text/paragraph.rb +63 -0
  35. data/lib/ebps/text/picture.rb +41 -0
  36. data/lib/ebps/text/table.rb +65 -0
  37. data/lib/ebps/util/mail.rb +47 -0
  38. data/lib/ebps/util/smtp_tls.rb +62 -0
  39. data/spec/conversion/data/DF_15164_1_3.gif +0 -0
  40. data/spec/conversion/data/DF_15164_2_3.gif +0 -0
  41. data/spec/conversion/data/appendix.png +0 -0
  42. data/spec/conversion/data/fachinfo.xml +1151 -0
  43. data/spec/conversion/data/fachinfo.yaml +1214 -0
  44. data/spec/conversion/data/fachinfo_with_image.xml +334 -0
  45. data/spec/conversion/data/fachinfo_with_table.xml +1101 -0
  46. data/spec/conversion/data/fachinfos.de.oddb.yaml +5789 -0
  47. data/spec/conversion/data/images/5c/5c54d52c8132230e8c40c37a428fe761.png +0 -0
  48. data/spec/conversion/de_fachinfo_yaml_spec.rb +86 -0
  49. data/spec/conversion/epub_spec.rb +59 -0
  50. data/spec/conversion/fachinfo_xml_spec.rb +245 -0
  51. data/spec/conversion/fachinfo_yaml_spec.rb +52 -0
  52. data/spec/conversion/mobi_pocket_spec.rb +55 -0
  53. data/spec/conversion/oebps_spec.rb +555 -0
  54. data/spec/text/chapter_spec.rb +65 -0
  55. data/spec/text/document_spec.rb +78 -0
  56. data/spec/text/paragraph_spec.rb +77 -0
  57. metadata +145 -0
@@ -0,0 +1,107 @@
1
+ require 'ebps/text/document'
2
+ require 'yaml'
3
+
4
+ module EBPS
5
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Patinfo' do |type, val|
6
+ if descr = val.delete('descriptions')
7
+ doc = descr[EBPS.config.language]
8
+ doc.metadata.update val
9
+ doc
10
+ end
11
+ end
12
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::PatinfoDocument' do |type, val|
13
+ chapters = %w{galenic_form composition effects kinetic indications usage
14
+ restrictions unwanted_effects interactions overdose
15
+ other_advice delivery distribution fabrication iksnrs
16
+ packages date}
17
+ Conversion::PatinfoYaml.assemble_document chapters, val
18
+ end
19
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::PatinfoDocument2001' do |type, val|
20
+ chapters = %w{amzv composition galenic_form indications usage
21
+ contra_indications restrictions interactions pregnancy
22
+ driving_ability unwanted_effects overdose effects kinetic
23
+ preclinic other_advice iksnrs packages registration_owner
24
+ date}
25
+ Conversion::PatinfoYaml.assemble_document chapters, val
26
+ end
27
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Chapter' do |type, val|
28
+ chp = Text::Chapter.new
29
+ chp.heading << val['heading']
30
+ Conversion::PatinfoYaml.encode chp.heading
31
+ chp.paragraphs.concat val['sections'].flatten.compact
32
+ chp
33
+ end
34
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Section' do |type, val|
35
+ paragraphs = []
36
+ if (txt = val['subheading']) && !txt.empty?
37
+ sh = Text::Subheading.new
38
+ sh << txt
39
+ Conversion::PatinfoYaml.encode sh.text
40
+ paragraphs << sh
41
+ end
42
+ paragraphs.concat val['paragraphs']
43
+ paragraphs
44
+ end
45
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Paragraph' do |type, val|
46
+ par = Text::Paragraph.new
47
+ par << val['text']
48
+ Conversion::PatinfoYaml.encode par.text
49
+ par.formats.replace val['formats']
50
+ if val['preformatted']
51
+ par.formats.each do |fmt|
52
+ fmt.values << 'pre'
53
+ end
54
+ end
55
+ par
56
+ end
57
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::ImageLink' do |type, val|
58
+ src = File.join EBPS.config.image_prefix, val['src']
59
+ file = File.basename src
60
+ handle = nil
61
+ begin
62
+ handle = open src
63
+ picture = Text::Picture.new
64
+ picture << handle.read
65
+ picture
66
+ rescue
67
+ end
68
+ end
69
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Format' do |type, val|
70
+ fmt = Text::Format.new
71
+ fmt.values = val['values']
72
+ fmt.start = val['start']
73
+ fmt.end = val['end']
74
+ fmt
75
+ end
76
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::SimpleLanguage::Descriptions' do |type, val|
77
+ val
78
+ end
79
+ module Conversion
80
+ module PatinfoYaml
81
+ def self.import string_or_io, path=nil
82
+ collection = {}
83
+ YAML.each_document string_or_io do |doc|
84
+ if doc
85
+ collection.store Digest::MD5.hexdigest(doc.to_s), doc
86
+ end
87
+ end
88
+ ## apparently we have some nil-values here (?)
89
+ collection.values.compact
90
+ end
91
+ def self.assemble_document chapters, yaml_value
92
+ doc = Text::Document.new
93
+ doc.title = Conversion::PatinfoYaml.encode(yaml_value['name'])
94
+ chapters.each do |name|
95
+ if chapter = yaml_value[name]
96
+ doc.add_chapter chapter
97
+ end
98
+ end
99
+ doc
100
+ end
101
+ def self.encode txt
102
+ txt.force_encoding 'UTF-8'
103
+ txt
104
+ end
105
+ end
106
+ end
107
+ end
Binary file
@@ -0,0 +1,16 @@
1
+ .ebps {
2
+ display: block;
3
+ text-indent: 0;
4
+ }
5
+ h3 {
6
+ margin-top: 1em;
7
+ }
8
+ h4 {
9
+ margin-top: 0.5em;
10
+ }
11
+ table.ebps {
12
+ border-collapse: collapse;
13
+ }
14
+ table.ebps td {
15
+ border: 1px solid #999;
16
+ }
@@ -0,0 +1,16 @@
1
+ module EBPS
2
+ module Postprocess
3
+ module Bookworm
4
+ def self.postprocess data={}
5
+ target = EBPS.config.target
6
+ command = "curl -F epub_data=@#{target}"
7
+ data['params'].each do |name, value|
8
+ command << " -F #{name}=#{value}"
9
+ end
10
+ command << " #{data['url']}"
11
+ system command
12
+ "the generated Ebook %s was published on Bookworm" % File.basename(target)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ require 'net/ftp'
2
+ require 'uri'
3
+
4
+ module EBPS
5
+ module Postprocess
6
+ module Copy
7
+ def self.postprocess data={}
8
+ target = EBPS.config.target
9
+ report = ["the generated Ebook %s was copied to the following locations" % File.basename(target)]
10
+ data['targets'].each do |path|
11
+ uri = ::URI.parse path
12
+ case uri.scheme
13
+ when 'ftp'
14
+ Net::FTP.open uri.host do |ftp|
15
+ ftp.login uri.user, uri.password
16
+ ftp.chdir File.dirname(uri.path)
17
+ ftp.putbinaryfile target, File.basename(uri.path)
18
+ end
19
+ else
20
+ FileUtils.cp target, path
21
+ end
22
+ report.push sprintf(" - %s", path)
23
+ end
24
+ report.join "\n"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ module EBPS
2
+ module Postprocess
3
+ module SystemCall
4
+ def self.postprocess data={}
5
+ report = ["the following commands were executed"]
6
+ pwd = Dir.pwd
7
+ data['command_lines'].each do |dir, command|
8
+ Dir.chdir dir
9
+ system(command)
10
+ report.push sprintf(" - %s in directory %s", command, dir)
11
+ end
12
+ report.join "\n"
13
+ ensure
14
+ Dir.chdir pwd
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require 'net/ftp'
2
+ require 'uri'
3
+
4
+ module EBPS
5
+ module Preprocess
6
+ module Copy
7
+ def self.preprocess data={}
8
+ report = ["The following files were copied"]
9
+ data['transfers'].each do |path, destination|
10
+ FileUtils.mkdir_p File.dirname(destination)
11
+ uri = ::URI.parse path
12
+ case uri.scheme
13
+ when 'ftp'
14
+ Net::FTP.open uri.host do |ftp|
15
+ ftp.login uri.user, uri.password
16
+ ftp.chdir File.dirname(uri.path)
17
+ ftp.getbinaryfile File.basename(uri.path), destination
18
+ end
19
+ else
20
+ FileUtils.cp path, destination
21
+ end
22
+ report.push sprintf(" - from %s to %s")
23
+ end
24
+ report.join "\n"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ module EBPS
2
+ module Preprocess
3
+ module SystemCall
4
+ def self.preprocess data={}
5
+ report = ["the following commands were executed"]
6
+ pwd = Dir.pwd
7
+ data['command_lines'].each do |dir, command|
8
+ Dir.chdir dir
9
+ system(command)
10
+ report.push sprintf(" - %s in directory %s", command, dir)
11
+ end
12
+ report.join "\n"
13
+ ensure
14
+ Dir.chdir pwd
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ require 'ebps/text/paragraph'
2
+ require 'ebps/text/picture'
3
+ require 'ebps/text/table'
4
+
5
+ module EBPS
6
+ module Text
7
+ class Chapter
8
+ attr_reader :paragraphs, :heading
9
+ def initialize
10
+ @heading = ''
11
+ @paragraphs = []
12
+ end
13
+ def add_paragraph(paragraph)
14
+ case paragraph
15
+ when Paragraph, Picture, Table
16
+ else
17
+ raise TypeError
18
+ end
19
+ unless @paragraphs.include?(paragraph)
20
+ @paragraphs.push paragraph
21
+ paragraph
22
+ end
23
+ end
24
+ def append chapter
25
+ @paragraphs.concat chapter.paragraphs
26
+ end
27
+ def partial?
28
+ @heading.empty? || @paragraphs.empty?
29
+ end
30
+ def to_s
31
+ head = @heading.empty? ? [] : [@heading]
32
+ head.concat(@paragraphs).join("\n")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'ebps/text/chapter'
2
+
3
+ module EBPS
4
+ module Text
5
+ class Document
6
+ attr_reader :chapters, :metadata
7
+ attr_accessor :title
8
+ def initialize
9
+ @chapters = []
10
+ @metadata = {}
11
+ @title = ''
12
+ end
13
+ def add_chapter(chapter)
14
+ raise TypeError unless chapter.is_a?(Chapter)
15
+ unless @chapters.include?(chapter)
16
+ @chapters.push chapter
17
+ chapter
18
+ end
19
+ end
20
+ def chapter(idx_or_name)
21
+ case idx_or_name
22
+ when Integer
23
+ @chapters[idx_or_name]
24
+ else
25
+ @chapters.find { |ch| ch.name == idx_or_name }
26
+ end
27
+ end
28
+ def remove_chapter(chapter)
29
+ @chapters.delete(chapter)
30
+ end
31
+ def to_s
32
+ @chapters.join("\n")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ module EBPS
2
+ module Text
3
+ class Format
4
+ attr_accessor :start, :end, :values
5
+ VALID_FORMATS = %w{b i pre sub sup u}
6
+ def initialize(*args)
7
+ @values = []
8
+ augment *args
9
+ @start = 0
10
+ @end = -1
11
+ end
12
+ def augment(*args)
13
+ @values.concat(args & VALID_FORMATS)
14
+ @values.sort!
15
+ @values.uniq!
16
+ @values
17
+ end
18
+ def range
19
+ @start..@end
20
+ end
21
+ def ==(other)
22
+ case other
23
+ when Format
24
+ @values == other.values
25
+ when Array
26
+ @values == (other & VALID_FORMATS).sort
27
+ else
28
+ false
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,63 @@
1
+ require 'ebps/text/format'
2
+
3
+ module EBPS
4
+ module Text
5
+ class Paragraph
6
+ attr_reader :text, :formats
7
+ attr_accessor :align
8
+ def initialize(str='')
9
+ @formats = []
10
+ @text = ''
11
+ set_format()
12
+ self << str
13
+ end
14
+ def method_missing *args, &block
15
+ @text.send *args, &block
16
+ end
17
+ def set_format(*args)
18
+ if(fmt = @formats.last)
19
+ return if(fmt == args)
20
+ if(fmt.start == @text.length)
21
+ @formats.pop
22
+ fmt = @formats.last
23
+ if(fmt == args)
24
+ fmt.end = -1
25
+ return
26
+ end
27
+ else
28
+ fmt.end = (@text.length - 1)
29
+ end
30
+ end
31
+ fmt = Text::Format.new(*args)
32
+ fmt.start = (@text.length)
33
+ @formats.push(fmt)
34
+ fmt
35
+ end
36
+ def to_s
37
+ @text.dup
38
+ end
39
+ def <<(str)
40
+ if(str.is_a? Paragraph)
41
+ @align = str.align
42
+ txt = str.text
43
+ str.formats.each { |fmt|
44
+ set_format(*fmt.values)
45
+ @text << txt[fmt.range]
46
+ }
47
+ else
48
+ @text << str
49
+ end
50
+ self
51
+ end
52
+ end
53
+ class Subheading < Paragraph
54
+ end
55
+ class LinkedParagraph < Paragraph
56
+ attr_reader :url
57
+ def initialize(url, str='')
58
+ @url = url
59
+ super str
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,41 @@
1
+ require 'ebps/config'
2
+ require 'delegate'
3
+ require 'digest/md5'
4
+ require 'RMagick'
5
+
6
+ module EBPS
7
+ module Text
8
+ class Picture < DelegateClass(String)
9
+ attr_accessor :height, :width, :xscale, :yscale, :height_goal, :width_goal
10
+ def initialize
11
+ super('')
12
+ end
13
+ def digest
14
+ @digest ||= Digest::MD5.hexdigest(self)
15
+ end
16
+ def empty?
17
+ super
18
+ rescue StandardError => err
19
+ EBPS.logger.error("Text::Picture") {
20
+ sprintf "%s: %s", err.class, err.message
21
+ }
22
+ true
23
+ end
24
+ def filename
25
+ @filename ||= "%s.%s" % [digest, EBPS.config.image_format]
26
+ end
27
+ def formats
28
+ []
29
+ end
30
+ def image
31
+ Magick::Image.from_blob(self).first
32
+ end
33
+ def set_format(*ignore)
34
+ # ignore
35
+ end
36
+ def to_s
37
+ image.inspect
38
+ end
39
+ end
40
+ end
41
+ end