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
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ # Hoe.plugin :compiler
7
+ # Hoe.plugin :cucumberfeatures
8
+ # Hoe.plugin :gem_prelude_sucks
9
+ # Hoe.plugin :inline
10
+ # Hoe.plugin :inline
11
+ # Hoe.plugin :manifest
12
+ # Hoe.plugin :newgem
13
+ # Hoe.plugin :racc
14
+ # Hoe.plugin :rubyforge
15
+ # Hoe.plugin :rubyforge
16
+ # Hoe.plugin :website
17
+
18
+ Hoe.spec 'ebps' do
19
+ # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
20
+ # you'll never have to touch them again!
21
+ # (delete this comment too, of course)
22
+
23
+ developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
24
+
25
+ # self.rubyforge_name = 'ebpsx' # if different than 'ebps'
26
+ end
27
+
28
+ # vim: syntax=ruby
data/SetupConfig ADDED
@@ -0,0 +1,30 @@
1
+ ---
2
+ install_prefix:
3
+ localstatedir: /var/lib
4
+ prefix: /usr
5
+ rubyprog: /usr/bin/ruby18
6
+ rubypath: /usr/bin/ruby18
7
+ siterubyverarch: /usr/lib/ruby/site_ruby/1.8/i686-linux
8
+ no_ext: false
9
+ no_ri: true
10
+ extconfopt: ""
11
+ type: site
12
+ no_doc: false
13
+ librubyverarch: /usr/lib/ruby/1.8/i686-linux
14
+ installdirs: site
15
+ no_test: true
16
+ siteruby: /usr/lib/ruby/site_ruby
17
+ root:
18
+ siterubyver: /usr/lib/ruby/site_ruby/1.8
19
+ sysconfdir: /etc
20
+ rbdir: /usr/lib/ruby/site_ruby/1.8
21
+ datadir: /usr/share
22
+ shebang: ruby
23
+ makeprog: make
24
+ librubyver: /usr/lib/ruby/1.8
25
+ mandir: /usr/share/man
26
+ libdir: /usr/lib
27
+ libruby: /usr/lib/ruby
28
+ sodir: /usr/lib/ruby/site_ruby/1.8/i686-linux
29
+ docdir: /usr/share/doc
30
+ bindir: /usr/bin
data/bin/ebps ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ log = []
4
+
5
+ if RUBY_VERSION < '1.9'
6
+ warning = <<-EOS
7
+ #$0 is designed to run on Ruby 1.9 and higher.
8
+ Running on Ruby #{RUBY_VERSION} may result in unexpected results or errors,
9
+ particularly in the handling of multibyte characters.
10
+ EOS
11
+ log.push "Warning: " << warning
12
+ warn warning
13
+ end
14
+
15
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
16
+
17
+ require 'ebps'
18
+ require 'ebps/util/mail'
19
+
20
+ def identify_module namespace, name
21
+ module_name = name.gsub /(^|_)./ do |match| match.upcase.delete '_' end
22
+ namespace.const_get module_name
23
+ end
24
+
25
+ begin
26
+
27
+ import_from = EBPS.config.import_from
28
+ export_to = EBPS.config.export_to
29
+ require "ebps/conversion/#{import_from}"
30
+ require "ebps/conversion/#{export_to}"
31
+
32
+ EBPS.config.preprocess.each do |name, data|
33
+ require "ebps/preprocess/#{name}"
34
+ result = identify_module(EBPS::Preprocess, name).preprocess(data)
35
+ log.push sprintf('Preprocess: %s', result)
36
+ end
37
+
38
+ importer = identify_module EBPS::Conversion, import_from
39
+ exporter = identify_module EBPS::Conversion, export_to
40
+
41
+ model = []
42
+ source_path = EBPS.config.source
43
+ inputs = ""
44
+ if File.ftype(source_path) == 'directory'
45
+ inputs << "Input files for conversion:"
46
+ Dir.foreach(source_path) do |name|
47
+ path = File.join source_path, name
48
+ if File.ftype(path) == 'file'
49
+ inputs << "\n" << path
50
+ File.open(path) do |fh|
51
+ model.concat importer.import(fh, path)
52
+ end
53
+ end
54
+ end
55
+ else
56
+ inputs << "Input file for conversion: " << source_path
57
+ source = File.open(source_path)
58
+ model = importer.import source, source_path
59
+ end
60
+ log.push inputs
61
+
62
+ EBPS.config.decorate.each do |path, name|
63
+ require path
64
+ decorator = identify_module(EBPS::Decorator, name)
65
+ model.each do |doc|
66
+ decorator.decorate(doc)
67
+ end
68
+ log.push sprintf('Decorate: %s.decorate', name)
69
+ end
70
+
71
+ target = EBPS.config.target
72
+ exporter.export model, target
73
+
74
+ log.push sprintf("The Ebook %s was generated and stored in %s",
75
+ File.basename(target), File.dirname(target))
76
+
77
+ EBPS.config.postprocess.each do |name, data|
78
+ require "ebps/postprocess/#{name}"
79
+ result = identify_module(EBPS::Postprocess, name).postprocess(data)
80
+ log.push sprintf('Postprocess: %s', result)
81
+ end
82
+ rescue StandardError => err
83
+ log.push err
84
+ ensure
85
+ EBPS::Util::Mail.notify log
86
+ end
@@ -0,0 +1,12 @@
1
+ ---
2
+ smtp_server: smtp_server
3
+ smtp_user: username@domain
4
+ smtp_pass: 'password'
5
+ report_to:
6
+ - email_address
7
+ source: ./data.yml
8
+ target: ./sample.epub
9
+ import_from: import_module_sample
10
+ export_to: epub
11
+ language: de
12
+ title: Firmenliste Schweiz
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby19
2
+
3
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
4
+
5
+ require 'ebps'
6
+ require 'ebps/util/mail'
7
+
8
+ def identify_module namespace, name
9
+ module_name = name.gsub /(^|_)./ do |match| match.upcase.delete '_' end
10
+ namespace.const_get module_name
11
+ end
12
+
13
+ begin
14
+
15
+ log = []
16
+
17
+ # Read modules
18
+ import_from = EBPS.config.import_from
19
+ export_to = EBPS.config.export_to
20
+ require "ebps/conversion/#{import_from}"
21
+ require "ebps/conversion/#{export_to}"
22
+
23
+ importer = identify_module EBPS::Conversion, import_from
24
+ exporter = identify_module EBPS::Conversion, export_to
25
+
26
+ # Import process
27
+ model = []
28
+ source_path = EBPS.config.source
29
+ inputs = ""
30
+ if File.ftype(source_path) == 'directory'
31
+ inputs << "Input files for conversion:"
32
+ Dir.foreach(source_path) do |name|
33
+ path = File.join source_path, name
34
+ if File.ftype(path) == 'file'
35
+ inputs << "\n" << path
36
+ File.open(path) do |fh|
37
+ model.concat importer.import(fh, path)
38
+ end
39
+ end
40
+ end
41
+ else
42
+ inputs << "Input file for conversion: " << source_path
43
+ source = File.open(source_path)
44
+ model = importer.import source, source_path
45
+ end
46
+ log.push inputs
47
+
48
+ # Export process
49
+ target = EBPS.config.target
50
+ exporter.export model, target
51
+
52
+ log.push sprintf("The Ebook %s was generated and stored in %s",
53
+ File.basename(target), File.dirname(target))
54
+
55
+ rescue StandardError => err
56
+ log.push err
57
+ ensure
58
+ EBPS::Util::Mail.notify log
59
+ end
data/example/data.yml ADDED
@@ -0,0 +1,60 @@
1
+ --- !ywesee,2010/CompanyInfo
2
+ oid: 123456789
3
+ descriptions: !ywesee,2010/SimpleLanguage::Descriptions
4
+ de: !ywesee,2010/CompanyInfo2010
5
+ name: ywesee GmbH
6
+ short_description: !ywesee,2010/Text::Chapter
7
+ heading: ywesee - intellectual capital connected
8
+ sections: []
9
+
10
+ general_information: !ywesee,2010/Text::Chapter
11
+ heading: About ywesee GmbH
12
+ sections:
13
+ - !ywesee,2010/Text::Section
14
+ subheading: ""
15
+ paragraphs:
16
+ - !ywesee,2010/Text::Paragraph
17
+ formats:
18
+ - !ywesee,2010/Text::Format
19
+ values:
20
+ - :italic
21
+ start: 0
22
+ end: 9
23
+ - !ywesee,2010/Text::Format
24
+ values: []
25
+
26
+ start: 10
27
+ end: -1
28
+ text: "ywesee GmbH is an OpenSource Software company with a bias for OpenStandards and a dedicated focus on the HealthCare industry."
29
+ preformatted: false
30
+ - !ywesee,2010/Text::Paragraph
31
+ formats:
32
+ - !ywesee,2010/Text::Format
33
+ values:
34
+ - :italic
35
+ start: 0
36
+ end: 11
37
+ - !ywesee,2010/Text::Format
38
+ values: []
39
+
40
+ start: 12
41
+ end: -1
42
+ text: "Web site: http://www.ywesee.com"
43
+ preformatted: false
44
+ address_form: !ywesee,2010/Text::Chapter
45
+ heading: Kontakt zu ywesee
46
+ sections:
47
+ - !ywesee,2010/Text::Section
48
+ subheading: "Address"
49
+ paragraphs:
50
+ - !ywesee,2010/Text::Paragraph
51
+ formats:
52
+ - !ywesee,2010/Text::Format
53
+ values: []
54
+
55
+ start: 0
56
+ end: -1
57
+ text: "Winterthurerstrasse 52, 8006 Zürich, Schweiz."
58
+ preformatted: false
59
+
60
+
@@ -0,0 +1,3 @@
1
+ #! /bin/sh
2
+
3
+ ruby1.9 ./converter_for_firefox.rb config="./config.yml"
Binary file
data/lib/ebps.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'ebps/config'
2
+
3
+ class Ebps
4
+ VERSION = '1.0.2'
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'rclconf'
2
+
3
+ module EBPS
4
+ run_as = File.basename $0
5
+ default_config_files = [
6
+ "/etc/ebps/#{run_as}.yml",
7
+ '/etc/ebps/ebps.yml',
8
+ ]
9
+ defaults = {
10
+ 'config' => default_config_files,
11
+ 'log_level' => 'INFO',
12
+ ## interesting configuration values start here
13
+ 'appendix' => nil,
14
+ 'author' => nil,
15
+ 'content_title' => nil,
16
+ 'cover' => File.expand_path('data/default_cover.jpg', File.dirname(__FILE__)),
17
+ 'decorate' => [],
18
+ 'export_to' => nil,
19
+ 'guide_index' => 'Index',
20
+ 'html_index' => true,
21
+ 'image_prefix' => '',
22
+ 'image_suffix' => '',
23
+ 'image_format' => 'gif',
24
+ 'import_from' => nil,
25
+ 'index_name' => 'Index',
26
+ 'keep_tmpfiles' => false,
27
+ 'kindlegen_args' => '-c2 -nomin -unicode',
28
+ 'kindlegen_path' => 'kindlegen',
29
+ 'kindle_quirks' => false,
30
+ 'language' => nil,
31
+ 'link_drug_brand_name' => false,
32
+ 'max_depth' => 3,
33
+ 'name' => 'ebps',
34
+ 'preprocess' => {},
35
+ 'postprocess' => {},
36
+ 'report_from' => 'EBPS <ebps@ywesee.com>',
37
+ 'report_subject' => 'Ebook %s finished at %s',
38
+ 'report_subject_err'=> 'Ebook %s could not be completed (%s)',
39
+ 'report_time_format'=> '%d.%m.%Y %H:%M:%S',
40
+ 'report_to' => [],
41
+ 'smtp_authtype' => :plain,
42
+ 'smtp_domain' => 'ywesee.com',
43
+ 'smtp_pass' => nil,
44
+ 'smtp_port' => 587,
45
+ 'smtp_server' => 'mail.ywesee.com',
46
+ 'smtp_user' => nil,
47
+ 'sort' => true,
48
+ 'source' => nil,
49
+ 'stylesheet' => File.expand_path('data/stylesheet.css', File.dirname(__FILE__)),
50
+ 'target' => nil,
51
+ 'title' => nil,
52
+ 'xml_indent' => nil,
53
+ }
54
+
55
+ config = RCLConf::RCLConf.new(ARGV, defaults)
56
+ config.load(config.config)
57
+ @config = config
58
+ def self.config
59
+ @config
60
+ end
61
+ end
@@ -0,0 +1,81 @@
1
+ require 'ebps/text/document'
2
+ require 'yaml'
3
+
4
+ module EBPS
5
+ YAML.add_domain_type 'de.oddb.org,2007',
6
+ 'ODDB::Util::M10lDocument' do |type, val|
7
+ if descr = val['canonical']
8
+ descr[EBPS.config.language.to_sym]
9
+ end
10
+ end
11
+ YAML.add_domain_type 'de.oddb.org,2007', 'ODDB::Text::Document' do |type, val|
12
+ doc = Text::Document.new
13
+ doc.title << val['title'].to_s.strip
14
+ val['chapters'].each do |chapter|
15
+ doc.add_chapter chapter
16
+ end
17
+ doc
18
+ end
19
+ YAML.add_domain_type 'de.oddb.org,2007', 'ODDB::Text::Chapter' do |type, val|
20
+ pars = val['paragraphs']
21
+ chp = Text::Chapter.new
22
+ if (heading = pars.first) && heading.respond_to?(:text)
23
+ pars.shift
24
+ chp.heading << heading.text
25
+ end
26
+ chp.paragraphs.concat pars
27
+ chp
28
+ end
29
+ YAML.add_domain_type 'de.oddb.org,2007', 'ODDB::Text::Paragraph' do |type, val|
30
+ fmts = val['formats']
31
+ par = if fmts.size == 1 && fmts.first.values.include?('i')
32
+ Text::Subheading.new
33
+ else
34
+ Text::Paragraph.new
35
+ end
36
+ par << val['text']
37
+ par.formats.replace fmts
38
+ par
39
+ end
40
+ YAML.add_domain_type 'de.oddb.org,2007', 'ODDB::Text::Format' do |type, val|
41
+ fmt = Text::Format.new
42
+ fmt.values = val['values']
43
+ fmt.start = val['start']
44
+ fmt.end = val['end']
45
+ fmt
46
+ end
47
+ YAML.add_domain_type 'de.oddb.org,2007', 'ODDB::Text::Table' do |type, val|
48
+ table = Text::Table.new
49
+ table.rows.replace val['rows']
50
+ table
51
+ end
52
+ YAML.add_domain_type 'de.oddb.org,2007', 'ODDB::Text::Picture' do |type, val|
53
+ path = File.join EBPS.config.image_prefix, val['path']
54
+ file = File.basename path
55
+ handle = nil
56
+ begin
57
+ handle = open path
58
+ picture = Text::Picture.new
59
+ picture << handle.read
60
+ picture
61
+ rescue StandardError => e
62
+ par = Text::Paragraph.new
63
+ par << e.message
64
+ par
65
+ end
66
+ end
67
+ module Conversion
68
+ module DeFachinfoYaml
69
+ def self.import string_or_io, path=nil
70
+ collection = {}
71
+ YAML.each_document string_or_io do |doc|
72
+ if doc
73
+ collection.store Digest::MD5.hexdigest(doc.to_s), doc
74
+ end
75
+ end
76
+ ## apparently we have some nil-values here (?)
77
+ collection.values.compact
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,38 @@
1
+ # - encoding: utf-8
2
+ require 'builder'
3
+ require 'ebps/conversion/oebps'
4
+ require 'zip/zip'
5
+
6
+ module EBPS
7
+ module Conversion
8
+ module Epub
9
+ def self.compile_epub target, tmpdir, name
10
+ Zip::ZipOutputStream.open(target) do |zh|
11
+ zh.put_next_entry('mimetype', nil, nil, Zip::ZipEntry::STORED)
12
+ zh << 'application/epub+zip'
13
+ zh.put_next_entry('META-INF/container.xml')
14
+ zh << <<-EOS
15
+ <?xml version="1.0" encoding="UTF-8" ?>
16
+ <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
17
+ <rootfiles>
18
+ <rootfile full-path="OPS/#{name}" media-type="application/oebps-package+xml"/>
19
+ </rootfiles>
20
+ </container>
21
+ EOS
22
+ Dir.foreach(tmpdir) do |entry|
23
+ path = File.join tmpdir, entry
24
+ if File.ftype(path) == 'file'
25
+ zh.put_next_entry("OPS/#{entry}")
26
+ zh << File.read(path)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ def self.export docs, target, override_tmpdir=nil
32
+ Oebps.export docs, target, override_tmpdir do |tmpdir, name|
33
+ compile_epub target, tmpdir, name
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end