docbook_xsl_wrapper 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in docbook_xsl_wrapper.gemspec
4
2
  gemspec
@@ -1,76 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
- # This program converts DocBook documents into .epub files.
3
- #
4
- # Usage: dbtoepub [OPTIONS] [DocBook Files]
5
- #
6
- # .epub is defined by the IDPF at www.idpf.org and is made up of 3 standards:
7
- # - Open Publication Structure (OPS)
8
- # - Open Packaging Format (OPF)
9
- # - Open Container Format (OCF)
10
- #
11
- # Specific options:
12
- # -c, --css [FILE] Use FILE for CSS on generated XHTML.
13
- # -d, --debug Show debugging output.
14
- # -f, --font [OTF FILE] Embed OTF FILE in .epub.
15
- # -h, --help Display usage info.
16
- # -s, --stylesheet [XSL FILE] Use XSL FILE as a customization
17
- # layer (imports epub/docbook.xsl).
18
- # -v, --verbose Make output verbose.
19
2
 
20
3
  $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
21
4
 
22
-
23
5
  require 'fileutils'
24
- require 'optparse'
25
6
  require 'tmpdir'
26
-
27
7
  require 'docbook_xsl_wrapper'
28
8
 
29
- verbose = false
30
- debug = false
31
- css_file = nil
32
- otf_files = []
33
- customization_layer = nil
34
- output_file = nil
35
-
36
- #$DEBUG=true
37
-
38
- # Set up the OptionParser
39
- opts = OptionParser.new
40
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [DocBook Files]
41
-
42
- #{File.basename($0)} converts DocBook <book> and <article>s into to .epub files.
43
-
44
- .epub is defined by the IDPF at www.idpf.org and is made up of 3 standards:
45
- - Open Publication Structure (OPS)
46
- - Open Packaging Format (OPF)
47
- - Open Container Format (OCF)
48
-
49
- Specific options:"
50
- opts.on("-c", "--css [FILE]", "Use FILE for CSS on generated XHTML.") {|f| css_file = f}
51
- opts.on("-d", "--debug", "Show debugging output.") {debug = true; verbose = true}
52
- opts.on("-f", "--font [OTF FILE]", "Embed OTF FILE in .epub.") {|f| otf_files << f}
53
- opts.on("-h", "--help", "Display usage info.") {puts opts.to_s; exit 0}
54
- opts.on("-o", "--output [OUTPUT FILE]", "Output ePub file as OUTPUT FILE.") {|f| output_file = f}
55
- opts.on("-s", "--stylesheet [XSL FILE]", "Use XSL FILE as a customization layer (imports epub/docbook.xsl).") {|f| customization_layer = f}
56
- opts.on("-v", "--verbose", "Make output verbose.") {verbose = true}
57
9
 
58
- db_files = opts.parse(ARGV)
59
- if db_files.size == 0
60
- puts opts.to_s
61
- exit 0
62
- end
10
+ options = DocbookXslWrapper::Options.parse(ARGV)
63
11
 
64
- db_files.each {|docbook_file|
12
+ options.docbooks.each {|docbook_file|
65
13
  dir = File.expand_path(File.join(Dir.tmpdir, ".epubtmp#{Time.now.to_f.to_s}"))
66
14
  FileUtils.mkdir_p(dir)
67
- e = DocbookXslWrapper::Epub.new(docbook_file, dir, css_file, customization_layer, otf_files)
15
+ e = DocbookXslWrapper::Epub.new(docbook_file, dir, options.css, options.customization, options.fonts)
68
16
 
69
- if output_file
70
- epub_file = output_file
17
+ if options.output
18
+ epub_file = options.output
71
19
  else
72
20
  epub_file = File.join(File.dirname(docbook_file), File.basename(docbook_file, ".xml") + ".epub")
73
21
  end
74
- puts "Rendering DocBook file #{docbook_file} to #{epub_file}" if verbose
22
+ puts "Rendering DocBook file #{docbook_file} to #{epub_file}" if options.verbose
75
23
  e.render_to_file(epub_file)
76
24
  }
@@ -18,8 +18,5 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.required_ruby_version = '~> 1.9.3'
20
20
 
21
- gem.add_development_dependency('rspec', '~> 2.12.0')
22
- gem.add_development_dependency('autotest-standalone')
23
- gem.add_development_dependency('autotest-growl')
24
- gem.add_development_dependency('autotest-fsevent')
21
+ gem.add_development_dependency('rspec', '~> 2.13.0')
25
22
  end
@@ -0,0 +1,86 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module DocbookXslWrapper
5
+ class Options
6
+
7
+ def self.parse(args)
8
+ options = OpenStruct.new
9
+ options.css = nil
10
+ options.customization = nil
11
+ options.fonts = []
12
+ options.output = nil
13
+ options.debug = false
14
+ options.verbose = false
15
+ options.docbooks = []
16
+
17
+ opts = OptionParser.new do |opts|
18
+ opts.banner = "Usage: #{opts.program_name} [OPTIONS] [DocBook Files]"
19
+ opts.separator ""
20
+ opts.separator "#{opts.program_name} converts DocBook <book> and <article>s into to .epub files."
21
+ opts.separator ""
22
+ opts.separator ".epub is defined by the IDPF at www.idpf.org and is made up of 3 standards:"
23
+ opts.separator "- Open Publication Structure (OPS)"
24
+ opts.separator "- Open Packaging Format (OPF)"
25
+ opts.separator "- Open Container Format (OCF)"
26
+ opts.separator ""
27
+ opts.separator "Specific options:"
28
+
29
+
30
+ opts.on("-c", "--css [FILE]", "Use FILE for CSS on generated XHTML.") do |css|
31
+ options.css = css
32
+ end
33
+
34
+ opts.on("-s", "--stylesheet [XSL FILE]", "Use XSL FILE as a customization layer (imports epub/docbook.xsl).") do |xsl|
35
+ options.customization = xsl
36
+ end
37
+
38
+ opts.on("-f", "--font [OTF FILE]", "Embed OTF FILE in .epub.") do |otf|
39
+ options.fonts << otf
40
+ end
41
+
42
+ opts.on("-o", "--output [OUTPUT FILE]", "Output EPUB file as OUTPUT FILE.") do |output|
43
+ options.output = output
44
+ end
45
+
46
+ opts.separator ""
47
+
48
+ opts.on("-d", "--[no-]debug", "Show debugging output.") do |d|
49
+ options.debug = d
50
+ options.verbose = d
51
+ end
52
+
53
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
54
+ options.verbose = v
55
+ end
56
+
57
+
58
+ opts.separator ""
59
+ opts.separator "Common options:"
60
+
61
+ opts.on_tail("-h", "--help", "Show this message") do
62
+ puts opts
63
+ exit
64
+ end
65
+
66
+ opts.on_tail("--version", "Show version") do
67
+ puts OptionParser::Version.join('.')
68
+ exit
69
+ end
70
+
71
+ end
72
+
73
+ args = ['-h'] if args.empty?
74
+ opts.parse!(args)
75
+
76
+ options.docbooks = args
77
+ if options.docbooks.empty?
78
+ puts "No DocBook XML file(s) specified"
79
+ exit
80
+ end
81
+
82
+ options
83
+ end
84
+
85
+ end
86
+ end
@@ -1,3 +1,3 @@
1
1
  module DocbookXslWrapper
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require "docbook_xsl_wrapper/version"
2
+ require 'docbook_xsl_wrapper/epub'
3
+ require 'docbook_xsl_wrapper/options'
2
4
 
3
- module DocbookXslWrapper
4
- require 'docbook_xsl_wrapper/epub'
5
- end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module DocbookXslWrapper
4
+ describe Options do
5
+
6
+ describe "#parse" do
7
+ it "should set some defaults" do
8
+ options = Options.parse(['etext.xml'])
9
+ options.css.should be nil
10
+ options.customization.should be nil
11
+ options.fonts.should eql []
12
+ options.output.should be nil
13
+ options.debug.should be false
14
+ options.verbose.should be false
15
+ end
16
+ it "should put the XML file in the docbooks array" do
17
+ options = Options.parse(['etext.xml'])
18
+ options.docbooks.should eql ['etext.xml']
19
+ end
20
+
21
+ context "when verbose option" do
22
+ it "should set verbose to true" do
23
+ options = Options.parse(['--verbose', 'etext.xml'])
24
+ options.verbose.should be true
25
+ end
26
+ end
27
+ context "when debug option" do
28
+ it "should set debug to true" do
29
+ options = Options.parse(['--debug', 'etext.xml'])
30
+ options.debug.should be true
31
+ end
32
+ it "should set verbose to true" do
33
+ options = Options.parse(['--debug', 'etext.xml'])
34
+ options.verbose.should be true
35
+ end
36
+ end
37
+ context "when css option used" do
38
+ it "should assign value to .css" do
39
+ options = Options.parse(['--css', 'stylesheet.css', 'etext.xml'])
40
+ options.css.should eq 'stylesheet.css'
41
+ end
42
+ end
43
+ context "when customization stylsheet given option" do
44
+ it "should set .customiztion with the value" do
45
+ options = Options.parse(['--stylesheet', 'some.xsl', 'etext.xml'])
46
+ options.customization.should eq 'some.xsl'
47
+ end
48
+ end
49
+ context "when fonts option" do
50
+ it "should sets fonts with the OTF files" do
51
+ options = Options.parse(['--font', 'one.otf', '--font', 'two.otf', 'etext.xml'])
52
+ options.fonts.should eq ['one.otf', 'two.otf']
53
+ end
54
+ end
55
+ context "when output file given" do
56
+ it "should assign output with the path/filename" do
57
+ options = Options.parse(['--output', '/path/to/new.epub', 'etext.xml'])
58
+ options.output.should eq '/path/to/new.epub'
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docbook_xsl_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.12.0
21
+ version: 2.13.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,55 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 2.12.0
30
- - !ruby/object:Gem::Dependency
31
- name: autotest-standalone
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: autotest-growl
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: autotest-fsevent
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
29
+ version: 2.13.0
78
30
  description: DocBook XSL Wrapper let's you easily convert DocBook XML to EPUB using
79
31
  the official DocBook XSL stylesheets.
80
32
  email:
@@ -84,7 +36,6 @@ executables:
84
36
  extensions: []
85
37
  extra_rdoc_files: []
86
38
  files:
87
- - .autotest
88
39
  - .gitignore
89
40
  - .rspec
90
41
  - .rvmrc
@@ -96,7 +47,9 @@ files:
96
47
  - docbook_xsl_wrapper.gemspec
97
48
  - lib/docbook_xsl_wrapper.rb
98
49
  - lib/docbook_xsl_wrapper/epub.rb
50
+ - lib/docbook_xsl_wrapper/options.rb
99
51
  - lib/docbook_xsl_wrapper/version.rb
52
+ - spec/docbook_xsl_wrapper/options_spec.rb
100
53
  - spec/spec_helper.rb
101
54
  - xslt/obfuscate.xsl
102
55
  homepage: ''
@@ -124,4 +77,5 @@ signing_key:
124
77
  specification_version: 3
125
78
  summary: Wrapper for the DocBook XSL stylesheets for easy XML to EPUB
126
79
  test_files:
80
+ - spec/docbook_xsl_wrapper/options_spec.rb
127
81
  - spec/spec_helper.rb
data/.autotest DELETED
@@ -1,9 +0,0 @@
1
- require "autotest/growl"
2
- require "autotest/fsevent"
3
-
4
- Autotest.add_hook :initialize do |at|
5
- at.add_mapping(%r%^spec/(docbook_xsl_wrapper)/.*rb$%) {|filename, _|
6
- filename
7
- }
8
- end
9
-