docbook_xsl_wrapper 0.1.2 → 0.5.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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/CHANGELOG +41 -0
- data/README.md +9 -17
- data/bin/docbook_xsl_wrapper +9 -14
- data/docbook_xsl_wrapper.gemspec +8 -7
- data/lib/docbook_xsl_wrapper.rb +24 -1
- data/lib/docbook_xsl_wrapper/epub.rb +124 -122
- data/lib/docbook_xsl_wrapper/options.rb +1 -1
- data/lib/docbook_xsl_wrapper/validate.rb +22 -0
- data/lib/docbook_xsl_wrapper/version.rb +1 -1
- data/schema/docbookxi.rng +18654 -0
- data/spec/docbook_xsl_wrapper/validate_spec.rb +64 -0
- data/xsl/AUTHORS +4 -0
- data/xsl/COPYING +48 -0
- data/xsl/REVISION +1 -0
- data/xsl/VERSION.xsl +115 -0
- data/xsl/common/addns.xsl +124 -0
- data/xsl/common/af.xml +1272 -0
- data/xsl/common/am.xml +1272 -0
- data/xsl/common/ar.xml +1272 -0
- data/xsl/common/as.xml +703 -0
- data/xsl/common/ast.xml +703 -0
- data/xsl/common/autoidx-kimber.xsl +45 -0
- data/xsl/common/autoidx-kosek.xsl +155 -0
- data/xsl/common/az.xml +715 -0
- data/xsl/common/bg.xml +767 -0
- data/xsl/common/bn.xml +1272 -0
- data/xsl/common/bn_in.xml +703 -0
- data/xsl/common/bs.xml +705 -0
- data/xsl/common/ca.xml +703 -0
- data/xsl/common/charmap.xsl +222 -0
- data/xsl/common/common.xsl +2129 -0
- data/xsl/common/cs.xml +743 -0
- data/xsl/common/cy.xml +1288 -0
- data/xsl/common/da.xml +707 -0
- data/xsl/common/de.xml +709 -0
- data/xsl/common/el.xml +772 -0
- data/xsl/common/en.xml +1272 -0
- data/xsl/common/entities.ent +67 -0
- data/xsl/common/eo.xml +1272 -0
- data/xsl/common/es.xml +719 -0
- data/xsl/common/et.xml +1272 -0
- data/xsl/common/eu.xml +1272 -0
- data/xsl/common/fa.xml +703 -0
- data/xsl/common/fi.xml +713 -0
- data/xsl/common/fr.xml +733 -0
- data/xsl/common/ga.xml +1272 -0
- data/xsl/common/gentext.xsl +855 -0
- data/xsl/common/gl.xml +1272 -0
- data/xsl/common/gu.xml +703 -0
- data/xsl/common/he.xml +1272 -0
- data/xsl/common/hi.xml +703 -0
- data/xsl/common/hr.xml +705 -0
- data/xsl/common/hu.xml +721 -0
- data/xsl/common/id.xml +1272 -0
- data/xsl/common/insertfile.xsl +113 -0
- data/xsl/common/is.xml +715 -0
- data/xsl/common/it.xml +1272 -0
- data/xsl/common/ja.xml +703 -0
- data/xsl/common/ka.xml +743 -0
- data/xsl/common/kn.xml +1272 -0
- data/xsl/common/ko.xml +1272 -0
- data/xsl/common/ky.xml +775 -0
- data/xsl/common/l10n.dtd +64 -0
- data/xsl/common/l10n.xml +78 -0
- data/xsl/common/l10n.xsl +598 -0
- data/xsl/common/la.xml +1272 -0
- data/xsl/common/labels.xsl +933 -0
- data/xsl/common/lt.xml +721 -0
- data/xsl/common/lv.xml +1272 -0
- data/xsl/common/ml.xml +703 -0
- data/xsl/common/mn.xml +773 -0
- data/xsl/common/mr.xml +703 -0
- data/xsl/common/nb.xml +1272 -0
- data/xsl/common/nds.xml +709 -0
- data/xsl/common/nl.xml +703 -0
- data/xsl/common/nn.xml +1272 -0
- data/xsl/common/olink.xsl +1284 -0
- data/xsl/common/or.xml +1272 -0
- data/xsl/common/pa.xml +703 -0
- data/xsl/common/pi.xml +168 -0
- data/xsl/common/pi.xsl +347 -0
- data/xsl/common/pl.xml +721 -0
- data/xsl/common/pt.xml +1272 -0
- data/xsl/common/pt_br.xml +1272 -0
- data/xsl/common/refentry.xsl +1353 -0
- data/xsl/common/ro.xml +1272 -0
- data/xsl/common/ru.xml +769 -0
- data/xsl/common/sk.xml +1272 -0
- data/xsl/common/sl.xml +1272 -0
- data/xsl/common/sq.xml +1272 -0
- data/xsl/common/sr.xml +763 -0
- data/xsl/common/sr_Latn.xml +722 -0
- data/xsl/common/subtitles.xsl +181 -0
- data/xsl/common/sv.xml +707 -0
- data/xsl/common/ta.xml +703 -0
- data/xsl/common/table.xsl +515 -0
- data/xsl/common/targetdatabase.dtd +49 -0
- data/xsl/common/targets.xsl +338 -0
- data/xsl/common/te.xml +703 -0
- data/xsl/common/th.xml +1272 -0
- data/xsl/common/titles.xsl +850 -0
- data/xsl/common/tl.xml +1272 -0
- data/xsl/common/tr.xml +709 -0
- data/xsl/common/uk.xml +769 -0
- data/xsl/common/ur.xml +705 -0
- data/xsl/common/utility.xsl +291 -0
- data/xsl/common/vi.xml +1272 -0
- data/xsl/common/xh.xml +1272 -0
- data/xsl/common/zh.xml +703 -0
- data/xsl/common/zh_cn.xml +703 -0
- data/xsl/common/zh_tw.xml +703 -0
- data/xsl/epub/docbook.xsl +1769 -0
- data/xsl/epub3/chunk.xsl +30 -0
- data/xsl/epub3/docbook-epub.css.xml +142 -0
- data/xsl/epub3/docbook.xsl +20 -0
- data/xsl/epub3/epub3-chunk-mods.xsl +52 -0
- data/xsl/epub3/epub3-element-mods.xsl +2533 -0
- data/xsl/epub3/titlepage.templates.xml +712 -0
- data/xsl/epub3/titlepage.templates.xsl +3842 -0
- data/xsl/lib/lib.xsl +533 -0
- data/xsl/xhtml/admon.xsl +142 -0
- data/xsl/xhtml/annotations.xsl +160 -0
- data/xsl/xhtml/autoidx.xsl +831 -0
- data/xsl/xhtml/autotoc.xsl +706 -0
- data/xsl/xhtml/biblio-iso690.xsl +1302 -0
- data/xsl/xhtml/biblio.xsl +1371 -0
- data/xsl/xhtml/block.xsl +584 -0
- data/xsl/xhtml/callout.xsl +210 -0
- data/xsl/xhtml/chunk-code.xsl +675 -0
- data/xsl/xhtml/chunk-common.xsl +1627 -0
- data/xsl/xhtml/chunker.xsl +317 -0
- data/xsl/xhtml/component.xsl +440 -0
- data/xsl/xhtml/division.xsl +214 -0
- data/xsl/xhtml/ebnf.xsl +331 -0
- data/xsl/xhtml/footnote.xsl +346 -0
- data/xsl/xhtml/formal.xsl +496 -0
- data/xsl/xhtml/glossary.xsl +602 -0
- data/xsl/xhtml/graphics.xsl +1537 -0
- data/xsl/xhtml/html-rtf.xsl +321 -0
- data/xsl/xhtml/html.xsl +690 -0
- data/xsl/xhtml/htmltbl.xsl +102 -0
- data/xsl/xhtml/index.xsl +264 -0
- data/xsl/xhtml/info.xsl +48 -0
- data/xsl/xhtml/inline.xsl +1508 -0
- data/xsl/xhtml/its.xsl +109 -0
- data/xsl/xhtml/keywords.xsl +38 -0
- data/xsl/xhtml/lists.xsl +1227 -0
- data/xsl/xhtml/math.xsl +286 -0
- data/xsl/xhtml/param.xsl +449 -0
- data/xsl/xhtml/pi.xsl +1237 -0
- data/xsl/xhtml/qandaset.xsl +440 -0
- data/xsl/xhtml/refentry.xsl +307 -0
- data/xsl/xhtml/sections.xsl +564 -0
- data/xsl/xhtml/synop.xsl +1623 -0
- data/xsl/xhtml/table.xsl +1179 -0
- data/xsl/xhtml/task.xsl +76 -0
- data/xsl/xhtml/titlepage.templates.xsl +4005 -0
- data/xsl/xhtml/titlepage.xsl +1108 -0
- data/xsl/xhtml/toc.xsl +334 -0
- data/xsl/xhtml/verbatim.xsl +389 -0
- data/xsl/xhtml/xref.xsl +1268 -0
- data/xsl/xhtml5/docbook.xsl +22 -0
- data/xsl/xhtml5/html5-chunk-mods.xsl +112 -0
- data/xsl/xhtml5/html5-element-mods.xsl +791 -0
- data/xsl/xhtml5/xhtml-docbook.xsl +531 -0
- metadata +207 -27
- data/.rvmrc +0 -48
- data/xslt/obfuscate.xsl +0 -12
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b742b5b8c9a3e4e949bb1326bd7636849b772f56e9dc056e8598b5bcd16b5973
|
|
4
|
+
data.tar.gz: 91de30769f58801d6248f363c4c1264b50fb6e50f0faba800d12238c972ec202
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e5e3629a4080d708ebab618ca1c560000f463a704655433b0f4ef1522525f49c79af08df546cf7935d1ffada325ab49cb05ffb8610ada4cae576ed9c6fa59894
|
|
7
|
+
data.tar.gz: 5a9aae5725da000feb11cd98666b7bba4bab67f2bb4a5ccff10d9973ed3a0dc6d4002227c0aaaeb4059977c7a97df6779928d87f02d4e98e52cc406852d5a76c
|
data/.gitignore
CHANGED
data/CHANGELOG
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
= Release History
|
|
2
|
+
|
|
3
|
+
== 0.1.2 / 2013-04-02 Michael Cook
|
|
4
|
+
|
|
5
|
+
* Now using Namespaced XSL: should produce less errors with some XML
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
== 0.1.0 / 2013-03-27 Michael Cook
|
|
9
|
+
|
|
10
|
+
* EPUB3 output supported
|
|
11
|
+
* Some other small refactoring
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
== 0.0.7 / 2013-03-05 Michael Cook
|
|
15
|
+
|
|
16
|
+
* Refactored the way images are copied
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
== 0.0.6 / 2013-03-05 Michael Cook
|
|
20
|
+
|
|
21
|
+
* Fix bg with the OPF path in container.xml
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
== 0.0.4 / 2013-03-02 Michael Cook
|
|
25
|
+
|
|
26
|
+
* Bg refactor of the Epub class
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
== 0.0.3 / 2013-02-27 Michael Cook
|
|
30
|
+
|
|
31
|
+
* Removed development dependency on 'autotest'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
== 0.0.2 / 2013-02-23 Michael Cook
|
|
35
|
+
|
|
36
|
+
* Better command-line options
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
== 0.0.1 / 2013-02-22 Michael Cook
|
|
40
|
+
|
|
41
|
+
* Initial gemification of the original Ruby script
|
data/README.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# DocBook XSL Wrapper
|
|
2
2
|
|
|
3
|
+
**IMPORTANT NOTICE - THIS GEM IS NO LONGER UNDER DEVELOPMENT**
|
|
4
|
+
|
|
5
|
+
I've been struggling to re-work this GEM to be usable as a library, rather than just as a command-line tool. On top of that I think perhaps the GEM naming is not the best.
|
|
6
|
+
|
|
7
|
+
For these reasons, I'm unlikely to develop this GEM any further. I may release an alternate _Docbook to EPUB_ libary at a later date, so keep an eye on my Github account for that.
|
|
8
|
+
|
|
9
|
+
====
|
|
10
|
+
|
|
3
11
|
_Please consider this as an Alpha release._
|
|
4
12
|
|
|
5
13
|
The DocBook XSL stylesheets are very powerful and provide an easy way to output
|
|
@@ -16,24 +24,8 @@ The original Ruby script can be found at: http://docbook.sourceforge.net/release
|
|
|
16
24
|
## Requirements
|
|
17
25
|
|
|
18
26
|
* DocBook
|
|
19
|
-
* DocBook XSL (
|
|
20
|
-
* xsltproc
|
|
21
|
-
|
|
22
|
-
### NOTE
|
|
23
|
-
|
|
24
|
-
The Docbook XSL Wrapper uses xsltproc, which allows all stylesheets to be
|
|
25
|
-
pulled from the http://docbook.sourceforge.net... URI, but if you have the
|
|
26
|
-
stylesheets installed locally, xsltproc will rewrite the URI to use local files.
|
|
27
|
-
|
|
28
|
-
On my OSX Lion system, "docbook" was installed via Homebrew, but two issues
|
|
29
|
-
needed fixing before everything worked correctly.
|
|
30
|
-
|
|
31
|
-
The catalog file ($XML_CATALOG_FILES) needed updating;
|
|
32
|
-
|
|
33
|
-
1. Add an entry to your 1.78.1 path.
|
|
34
|
-
2. Remove older XSL entries (e.g. 1.76.0 & 1.77.0).
|
|
27
|
+
* DocBook XSL (included in this repo)
|
|
35
28
|
|
|
36
|
-
_Please make sure that xsltproc uses the *1.78.1* stylesheets as default_
|
|
37
29
|
|
|
38
30
|
|
|
39
31
|
## Installation
|
data/bin/docbook_xsl_wrapper
CHANGED
|
@@ -2,24 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
|
4
4
|
|
|
5
|
-
require 'tmpdir'
|
|
6
5
|
require 'docbook_xsl_wrapper'
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
options = DocbookXslWrapper::Options.parse(ARGV)
|
|
9
|
+
docbook = options.docbook
|
|
10
10
|
|
|
11
|
-
unless File.exist?(
|
|
12
|
-
raise ArgumentError.new("File #{options.docbook} does not exist")
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
tmp_dir = Dir.mktmpdir
|
|
16
|
-
options.destination = tmp_dir
|
|
11
|
+
raise ArgumentError.new("File #{docbook} does not exist") unless File.exist?(docbook)
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ensure
|
|
24
|
-
FileUtils.remove_entry_secure tmp_dir
|
|
13
|
+
doc = DocbookXslWrapper::Validate.new(File.open(docbook, 'rb'))
|
|
14
|
+
unless doc.valid?
|
|
15
|
+
puts "YOUR DOCBOOK XML DOES NOT SEEM TO BE VALID - PLEASE FIX."
|
|
16
|
+
puts
|
|
17
|
+
puts doc.errors
|
|
25
18
|
end
|
|
19
|
+
|
|
20
|
+
DocbookXslWrapper.build_epub(options)
|
data/docbook_xsl_wrapper.gemspec
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
1
|
require File.expand_path('../lib/docbook_xsl_wrapper/version', __FILE__)
|
|
3
2
|
|
|
4
3
|
Gem::Specification.new do |gem|
|
|
5
4
|
gem.name = "docbook_xsl_wrapper"
|
|
6
5
|
gem.version = DocbookXslWrapper::VERSION
|
|
7
|
-
gem.authors = ["
|
|
8
|
-
gem.email = ["
|
|
9
|
-
gem.summary = %q{
|
|
10
|
-
gem.description = %q{DocBook XSL Wrapper let's you easily convert DocBook XML to EPUB using the official DocBook XSL stylesheets.}
|
|
6
|
+
gem.authors = ["Michael R. Cook"]
|
|
7
|
+
gem.email = ["git@mrcook.uk"]
|
|
8
|
+
gem.summary = %q{DocBook XSL Wrapper: validate/transform DocBook 5.x XML documents}
|
|
9
|
+
gem.description = %q{DocBook XSL Wrapper let's you easily validate then convert DocBook 5.x XML documents to EPUB using the official DocBook XSL stylesheets.}
|
|
10
|
+
gem.license = 'MIT'
|
|
11
|
+
gem.homepage = 'https://mrcook.uk'
|
|
11
12
|
|
|
12
13
|
gem.platform = Gem::Platform::RUBY
|
|
13
14
|
gem.files = `git ls-files`.split($\)
|
|
@@ -15,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
|
15
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
16
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
17
18
|
|
|
18
|
-
gem.
|
|
19
|
+
gem.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.1'
|
|
19
20
|
|
|
20
|
-
gem.add_development_dependency
|
|
21
|
+
gem.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
|
|
21
22
|
end
|
data/lib/docbook_xsl_wrapper.rb
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'tmpdir'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
|
|
2
4
|
require 'docbook_xsl_wrapper/epub'
|
|
3
5
|
require 'docbook_xsl_wrapper/options'
|
|
6
|
+
require 'docbook_xsl_wrapper/validate'
|
|
7
|
+
|
|
8
|
+
require "docbook_xsl_wrapper/version"
|
|
9
|
+
|
|
10
|
+
module DocbookXslWrapper
|
|
11
|
+
GEM_PATH = File.expand_path(File.join('..', '..'), __FILE__)
|
|
12
|
+
|
|
13
|
+
def self.build_epub(options)
|
|
14
|
+
tmp_dir = Dir.mktmpdir
|
|
15
|
+
options.destination = tmp_dir
|
|
16
|
+
|
|
17
|
+
begin
|
|
18
|
+
puts "Rendering DocBook file #{options.docbook} to #{options.output}\n\n" if options.verbose
|
|
19
|
+
|
|
20
|
+
epub = Epub.new(options)
|
|
21
|
+
epub.create
|
|
22
|
+
ensure
|
|
23
|
+
FileUtils.remove_entry_secure tmp_dir
|
|
24
|
+
end
|
|
25
|
+
end
|
|
4
26
|
|
|
27
|
+
end
|
|
@@ -4,184 +4,154 @@ require 'rexml/parsers/pullparser'
|
|
|
4
4
|
module DocbookXslWrapper
|
|
5
5
|
|
|
6
6
|
class Epub
|
|
7
|
-
attr_reader :options
|
|
7
|
+
attr_reader :options, :xml
|
|
8
8
|
|
|
9
9
|
def initialize(options)
|
|
10
10
|
@options = options
|
|
11
|
-
|
|
12
|
-
case options.format
|
|
13
|
-
when 'epub3'
|
|
14
|
-
xsl = File.join('epub3', 'chunk.xsl')
|
|
15
|
-
else
|
|
16
|
-
xsl = File.join('epub', 'docbook.xsl')
|
|
17
|
-
end
|
|
18
|
-
official_docbook_xsl = File.join('http://docbook.sourceforge.net/release/xsl-ns/current', xsl)
|
|
19
|
-
|
|
20
|
-
@options.stylesheet = official_docbook_xsl unless options.stylesheet
|
|
11
|
+
@xml = Nokogiri::XML(File.open(@options.docbook, 'rb'))
|
|
21
12
|
end
|
|
22
13
|
|
|
23
14
|
def create
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
# Nokogiri doesn't create directories, so we do it manually
|
|
16
|
+
Dir.mkdir(File.join(options.destination, meta_inf_directory))
|
|
17
|
+
Dir.mkdir(File.join(options.destination, oebps_directory))
|
|
18
|
+
|
|
19
|
+
render_to_epub
|
|
20
|
+
bundle_epub
|
|
30
21
|
end
|
|
31
22
|
|
|
32
23
|
private
|
|
33
24
|
|
|
34
25
|
def render_to_epub
|
|
35
|
-
|
|
26
|
+
errors = xslt_transform_and_rescue_because_it_currently_throws_unknown_runtime_error
|
|
27
|
+
raise "Could not render as .epub to #{options.output}\n\n(#{errors})" unless errors.empty?
|
|
28
|
+
end
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def xsl_parser_options
|
|
45
|
-
chunk_quietly = "--stringparam chunk.quietly 1" if options.verbose == false
|
|
46
|
-
css = "--stringparam html.stylesheet #{File.basename(options.css)}/" if options.css
|
|
47
|
-
base = "--stringparam base.dir #{oebps_path}/"
|
|
48
|
-
unless options.fonts.empty?
|
|
49
|
-
fonts = options.fonts.map {|f| File.basename(f)}.join(',')
|
|
50
|
-
font = "--stringparam epub.embedded.fonts \"#{fonts}\""
|
|
30
|
+
def xslt_transform_and_rescue_because_it_currently_throws_unknown_runtime_error
|
|
31
|
+
begin
|
|
32
|
+
errors = stylesheet.transform(xml, params)
|
|
33
|
+
rescue
|
|
34
|
+
errors = ''
|
|
51
35
|
end
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
errors
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def stylesheet
|
|
40
|
+
xsl = docbook_xsl_path
|
|
41
|
+
xsl = options.stylesheet unless options.stylesheet.empty?
|
|
42
|
+
|
|
43
|
+
Nokogiri::XSLT(File.open(xsl, 'rb'))
|
|
44
|
+
end
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
].join(" ")
|
|
46
|
+
def docbook_xsl_path
|
|
47
|
+
case options.format
|
|
48
|
+
when 'epub3'
|
|
49
|
+
File.join(GEM_PATH, 'xsl', 'epub3', 'chunk.xsl')
|
|
50
|
+
else
|
|
51
|
+
File.join(GEM_PATH, 'xsl', 'epub', 'docbook.xsl')
|
|
52
|
+
end
|
|
63
53
|
end
|
|
64
54
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
def params
|
|
56
|
+
params_list = [
|
|
57
|
+
'chunk.quietly', "#{verbosity}",
|
|
58
|
+
'chunk.first.sections', 1,
|
|
59
|
+
'othercredit.like.author.enabled', 1,
|
|
60
|
+
'chapter.autolabel', 0,
|
|
61
|
+
'section.autolabel', 0,
|
|
62
|
+
'part.autolabel', 0,
|
|
63
|
+
'base.dir', File.join(options.destination, '/'),
|
|
64
|
+
]
|
|
65
|
+
params_list.concat(css) if options.css
|
|
66
|
+
params_list.concat(fonts) unless options.fonts.empty?
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
'.collapsed.' + File.basename(options.docbook))
|
|
73
|
-
entity_collapse_command = %Q(xmllint --loaddtd --noent -o "#{collapsed_file}" "#{options.docbook}")
|
|
74
|
-
entity_success = system(entity_collapse_command)
|
|
75
|
-
raise "Could not collapse named entites in #{options.docbook}" unless entity_success
|
|
68
|
+
Nokogiri::XSLT.quote_params(params_list)
|
|
69
|
+
end
|
|
76
70
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
def fonts
|
|
72
|
+
['epub.embedded.fonts', options.fonts.map {|f| File.basename(f)}.join(',')]
|
|
73
|
+
end
|
|
80
74
|
|
|
81
|
-
|
|
75
|
+
def css
|
|
76
|
+
['html.stylesheet', File.join(File.basename(options.css), '/')]
|
|
82
77
|
end
|
|
83
78
|
|
|
84
79
|
def bundle_epub
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
fonts = copy_fonts
|
|
90
|
-
callouts = copy_callouts
|
|
91
|
-
# zip -X -r ../book.epub mimetype META-INF OEBPS
|
|
80
|
+
copy_media_files_to_epub_dir
|
|
81
|
+
create_mimetype_file if options.format == 'epub' # EPUB3 stylesheet creates this automatically
|
|
82
|
+
|
|
83
|
+
quiet = options.verbose ? '' : '-q'
|
|
92
84
|
# Double-quote stylesheet & file to help Windows cmd.exe
|
|
93
|
-
zip_cmd = %Q(cd "#{options.destination}" && zip #{quiet} -X -r "#{File.expand_path(options.output)}" "
|
|
85
|
+
zip_cmd = %Q(cd "#{options.destination}" && zip #{quiet} -X -r "#{File.expand_path(options.output)}" "mimetype" "#{meta_inf_directory}" "#{oebps_directory}")
|
|
86
|
+
|
|
94
87
|
puts zip_cmd if options.debug
|
|
95
88
|
success = system(zip_cmd)
|
|
96
89
|
raise "Could not bundle into .epub file to #{options.output}" unless success
|
|
97
90
|
end
|
|
98
91
|
|
|
99
|
-
def
|
|
92
|
+
def create_mimetype_file
|
|
100
93
|
filename = File.join(options.destination, "mimetype")
|
|
101
94
|
File.open(filename, "w") {|f| f.print "application/epub+zip"}
|
|
102
95
|
File.basename(filename)
|
|
103
96
|
end
|
|
104
97
|
|
|
105
|
-
def
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
calloutglob = "#{options.callout_full_path}/*#{options.callout_ext}"
|
|
110
|
-
Dir.glob(calloutglob).each do |image|
|
|
111
|
-
new_filename = File.join(oebps_path, options.callout_path, File.basename(image))
|
|
112
|
-
|
|
113
|
-
# TODO: What to rescue for these two?
|
|
114
|
-
FileUtils.mkdir_p(File.dirname(new_filename))
|
|
115
|
-
FileUtils.cp(image, new_filename)
|
|
116
|
-
images << image
|
|
117
|
-
end
|
|
118
|
-
images
|
|
119
|
-
end
|
|
98
|
+
def copy_media_files_to_epub_dir
|
|
99
|
+
copy_fonts
|
|
100
|
+
copy_css
|
|
101
|
+
copy_images
|
|
120
102
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
parser = REXML::Parsers::PullParser.new(File.new(@collapsed_docbook_file))
|
|
124
|
-
while parser.has_next?
|
|
125
|
-
element = parser.pull
|
|
126
|
-
return true if element.start_element? and (element[0] == "calloutlist" or element[0] == "co")
|
|
127
|
-
end
|
|
128
|
-
false
|
|
103
|
+
# Callouts disabled in this release until more testing can be done
|
|
104
|
+
#copy_callouts
|
|
129
105
|
end
|
|
130
106
|
|
|
131
107
|
def copy_fonts
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
108
|
+
return if options.fonts.empty?
|
|
109
|
+
|
|
110
|
+
font_directory = File.join(options.destination, oebps_directory, 'fonts')
|
|
111
|
+
Dir.mkdir(font_directory)
|
|
112
|
+
|
|
113
|
+
options.fonts.each do |font|
|
|
114
|
+
FileUtils.cp(font, File.join(font_directory, File.basename(font)))
|
|
115
|
+
end
|
|
139
116
|
end
|
|
140
117
|
|
|
141
118
|
def copy_css
|
|
142
119
|
return unless options.css
|
|
143
120
|
|
|
144
|
-
|
|
145
|
-
FileUtils.cp(options.css, filename)
|
|
121
|
+
FileUtils.cp(options.css, File.join(options.destination, oebps_directory, File.basename(options.css)))
|
|
146
122
|
end
|
|
147
123
|
|
|
148
124
|
def copy_images
|
|
149
|
-
images = Array.new
|
|
150
125
|
xml_image_references.each do |image|
|
|
151
|
-
|
|
126
|
+
copy_image(image)
|
|
152
127
|
end
|
|
153
|
-
images
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def copy_image(image)
|
|
157
|
-
source_file = File.join(File.expand_path(File.dirname(options.docbook)), image)
|
|
158
|
-
destination_file = File.join(oebps_path, image)
|
|
159
|
-
|
|
160
|
-
FileUtils.mkdir_p(File.dirname(destination_file))
|
|
161
|
-
|
|
162
|
-
puts "Copying image: #{source_file} to #{destination_file}" if options.debug
|
|
163
|
-
FileUtils.cp(source_file, destination_file)
|
|
164
|
-
|
|
165
|
-
destination_file
|
|
166
128
|
end
|
|
167
129
|
|
|
168
130
|
def xml_image_references
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
references << element[1]['fileref'] if is_valid_image_reference?(element)
|
|
131
|
+
refs = Array.new
|
|
132
|
+
xml.xpath('//xmlns:imagedata', '//xmlns:graphic', 'xmlns' => 'http://docbook.org/ns/docbook').each do |node|
|
|
133
|
+
img = node.attribute('fileref').value
|
|
134
|
+
refs << img if is_valid_image?(img)
|
|
174
135
|
end
|
|
175
|
-
|
|
136
|
+
|
|
137
|
+
refs.uniq
|
|
176
138
|
end
|
|
177
139
|
|
|
178
|
-
def
|
|
179
|
-
return
|
|
180
|
-
return false unless element[0] == 'graphic' or element[0] == 'imagedata'
|
|
181
|
-
return true if element[1]['fileref'].match(/\.(jpe?g|png|gif|svg|xml)\Z/i)
|
|
140
|
+
def is_valid_image?(image)
|
|
141
|
+
return true if File.extname(image).match(/\.(jpe?g|png|gif|svg|xml)\z/i)
|
|
182
142
|
false
|
|
183
143
|
end
|
|
184
144
|
|
|
145
|
+
def copy_image(image)
|
|
146
|
+
source = File.join(File.dirname(options.docbook), image)
|
|
147
|
+
destination = File.join(options.destination, oebps_directory, image)
|
|
148
|
+
|
|
149
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
|
150
|
+
|
|
151
|
+
puts "Copying image: #{source} to #{destination}" if options.debug
|
|
152
|
+
FileUtils.cp(source, destination)
|
|
153
|
+
end
|
|
154
|
+
|
|
185
155
|
def oebps_directory
|
|
186
156
|
'OEBPS'
|
|
187
157
|
end
|
|
@@ -194,5 +164,37 @@ module DocbookXslWrapper
|
|
|
194
164
|
'META-INF'
|
|
195
165
|
end
|
|
196
166
|
|
|
167
|
+
def verbosity
|
|
168
|
+
return 0 if options.verbose == true
|
|
169
|
+
return 1
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# TODO: This method is not being called for the moment....needs to be tested
|
|
174
|
+
def copy_callouts
|
|
175
|
+
return unless has_callouts?
|
|
176
|
+
|
|
177
|
+
images = Array.new
|
|
178
|
+
calloutglob = "#{options.callout_full_path}/*#{options.callout_ext}"
|
|
179
|
+
Dir.glob(calloutglob).each do |image|
|
|
180
|
+
new_filename = File.join(oebps_path, options.callout_path, File.basename(image))
|
|
181
|
+
|
|
182
|
+
# TODO: What to rescue for these two?
|
|
183
|
+
FileUtils.mkdir_p(File.dirname(new_filename))
|
|
184
|
+
FileUtils.cp(image, new_filename)
|
|
185
|
+
images << image
|
|
186
|
+
end
|
|
187
|
+
images
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def has_callouts?
|
|
191
|
+
parser = REXML::Parsers::PullParser.new(File.new(@collapsed_docbook_file))
|
|
192
|
+
while parser.has_next?
|
|
193
|
+
element = parser.pull
|
|
194
|
+
return true if element.start_element? and (element[0] == "calloutlist" or element[0] == "co")
|
|
195
|
+
end
|
|
196
|
+
false
|
|
197
|
+
end
|
|
198
|
+
|
|
197
199
|
end
|
|
198
200
|
end
|