booky 0.0.3 → 0.0.4

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.
@@ -4,7 +4,9 @@ require 'redcloth-formatters-docbook'
4
4
 
5
5
  module Booky
6
6
  require 'booky/version'
7
+ require 'booky/exceptions'
7
8
  require 'booky/fonts'
9
+ require 'booky/textile'
8
10
  require 'booky/docbook'
9
11
  require 'booky/fo'
10
12
  require 'booky/pdf'
@@ -118,6 +120,10 @@ module Booky
118
120
  @@source
119
121
  end
120
122
 
123
+ def self.source=(value)
124
+ @@source = value
125
+ end
126
+
121
127
  def self.root
122
128
  "#{__FILE__}".gsub("/lib/booky.rb", "")
123
129
  end
@@ -4,7 +4,7 @@ module Booky::Docbook
4
4
  puts "\n-> Creating Docbook XML"
5
5
  raise "File #{Booky.source} not found. Sorry" if !File.exists?("#{Booky.source}")
6
6
 
7
- textile = File.open("#{Booky.source}", 'rb') { |f| f.read }
7
+ textile = Booky::Textile.precompile
8
8
  File.open("#{Booky.name}.xml", 'w') {|f| f.write(RedCloth.new(textile).to_docbook) }
9
9
 
10
10
  puts "Done.\n"
@@ -0,0 +1,10 @@
1
+ module Booky
2
+ class LoadError < StandardError # :nodoc:
3
+ def to_s
4
+ %Q(
5
+ Sorry, couldn't load #{message}.
6
+ You always need to specify the file with respect to your main textile file, did you?
7
+ )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,44 @@
1
+ require_relative "textile/precompiler"
2
+ require_relative "textile/load"
3
+ require_relative "textile/source"
4
+
5
+ module Booky::Textile
6
+
7
+ @@base = nil
8
+
9
+ def self.precompile textile = Booky.source
10
+ puts "\n-> Precompiling Textile"
11
+ raise "File #{Booky.source} not found. Sorry" if !File.exists?("#{Booky.source}")
12
+
13
+ # Open Textile file
14
+ @@base = File.expand_path(textile)
15
+ @textile = File.open(textile, 'rb') { |f| f.read }
16
+
17
+ # Apply Precompilers
18
+ @precompilers.each { |precompiler| @textile = precompiler.apply(@textile) }
19
+
20
+ @textile
21
+ end
22
+
23
+ # Set the precompilers
24
+ def self.precompilers=(value)
25
+ @precompilers = value
26
+ end
27
+
28
+ # Get the precompilers
29
+ def self.precompilers
30
+ @precompilers
31
+ end
32
+
33
+ def self.base
34
+ @@base
35
+ end
36
+
37
+ end
38
+
39
+ # Register Precompilers
40
+ Booky::Textile.precompilers = [
41
+ Booky::Textile::Load,
42
+ Booky::Textile::Source
43
+ ]
44
+
@@ -0,0 +1,21 @@
1
+ module Booky::Textile
2
+ class Load
3
+ include Booky::Textile::Precompiler
4
+
5
+ # Does the current line need to be precompiled?
6
+ def matches line
7
+ return false unless line.match /^load./
8
+ line.gsub("load.", "").strip
9
+ end
10
+
11
+ # Replace the path with the contents of the file
12
+ def compile_to options
13
+ begin
14
+ File.open("#{File.dirname(Booky.source)}/#{options}", 'rb') { |f| f.read }
15
+ rescue
16
+ raise Booky::LoadError.new "#{File.dirname(Booky.source)}/#{options}"
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ module Booky::Textile
2
+ module Precompiler
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def apply(textile)
11
+
12
+ @output = ""
13
+ @precompiler = self.new
14
+
15
+ textile.each_line do |line|
16
+ if options = @precompiler.matches(line)
17
+ @output += "\n\n" unless @output.empty?
18
+ @output += self.apply(@precompiler.compile_to(options))
19
+ else
20
+ @output += line
21
+ end
22
+ end
23
+
24
+ @output
25
+ end
26
+
27
+ end
28
+
29
+ def matches line
30
+ false
31
+ end
32
+
33
+ def compile_to options
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ module Booky::Textile
2
+ class Source
3
+ include Booky::Textile::Precompiler
4
+
5
+ # Does the current line need to be precompiled?
6
+ def matches line
7
+ return false unless line.match /^source/
8
+ line.gsub("source", "").strip
9
+ end
10
+
11
+ # Replace the path with the contents of the file
12
+ def compile_to options
13
+ begin
14
+ options = parse(options)
15
+ @output = "bc{name: #{options[:name]};}.. "
16
+ @output += File.open("#{File.dirname(Booky.source)}/#{options[:file]}", 'rb') { |f| f.read }
17
+ @output += "\n\np. \n"
18
+ @output
19
+ rescue
20
+ raise Booky::LoadError.new "#{File.dirname(Booky.source)}/#{options[:name]}"
21
+ end
22
+ end
23
+
24
+ # Parses the options for a name and the file
25
+ def parse options
26
+ if name_match = options.match(/{(.*?)}/)
27
+ options = options.gsub(name_match[0], "")
28
+ name = name_match[1]
29
+ end
30
+
31
+ file = options[1..-1].strip
32
+ name = File.basename("#{File.dirname(Booky.source)}/#{file}") unless name
33
+
34
+ { :name => name, :file => file }
35
+ end
36
+
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module Booky
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
Binary file
Binary file
Binary file
@@ -248,7 +248,7 @@ version="1.0">
248
248
  <xsl:attribute name="space-after.minimum">0.5em</xsl:attribute>
249
249
  <xsl:attribute name="space-after.optimum">1em</xsl:attribute>
250
250
  <xsl:attribute name="space-after.maximum">2em</xsl:attribute>
251
- <xsl:attribute name="keep-together.within-column">always</xsl:attribute>
251
+ <xsl:attribute name="keep-together.within-column">auto</xsl:attribute>
252
252
  </xsl:attribute-set>
253
253
  <xsl:param name="formal.procedures" select="1"/>
254
254
  <xsl:param name="formal.title.placement">
@@ -438,7 +438,7 @@ set toc,title
438
438
  <xsl:param name="marker.section.level">2</xsl:param>
439
439
  <xsl:param name="menuchoice.menu.separator"> &#8594; </xsl:param>
440
440
  <xsl:param name="menuchoice.separator">+</xsl:param>
441
- <xsl:param name="monospace.font.family">monospace</xsl:param>
441
+ <xsl:param name="monospace.font.family">Monaco</xsl:param>
442
442
  <xsl:attribute-set name="monospace.properties">
443
443
  <xsl:attribute name="font-family">
444
444
  <xsl:value-of select="$monospace.font.family"/>
@@ -449,7 +449,7 @@ set toc,title
449
449
  <xsl:attribute name="wrap-option">wrap</xsl:attribute>
450
450
  <xsl:attribute name="hyphenation-character">\</xsl:attribute>
451
451
  </xsl:attribute-set>
452
- <xsl:param name="monospace.verbatim.font.width">0.60em</xsl:param>
452
+ <xsl:param name="monospace.verbatim.font.width">0.6em</xsl:param>
453
453
  <xsl:param name="nominal.table.width">6in</xsl:param>
454
454
  <xsl:attribute-set name="normal.para.spacing">
455
455
  <xsl:attribute name="space-before.optimum">1em</xsl:attribute>
@@ -0,0 +1,3 @@
1
+ h0. Abstract
2
+
3
+ The content of the abstract
@@ -0,0 +1,7 @@
1
+ title. Sample Document
2
+
3
+ subtitle. How to load multiple documents
4
+
5
+ author. Thomas Fankhauser
6
+
7
+ copyright. 2010, Thomas Fankhauser, All rights reserved.
@@ -0,0 +1,3 @@
1
+ h1. Introduction
2
+
3
+ This is the content of the introduction
@@ -0,0 +1,3 @@
1
+ load. chapters/abstract.textile
2
+ load. chapters/intro.textile
3
+ load. chapters/summary.textile
@@ -0,0 +1,3 @@
1
+ h1. Summary
2
+
3
+ This is the summary
@@ -0,0 +1,4 @@
1
+ load. chapters/cover.textile
2
+ load. chapters/abstract.textile
3
+ load. chapters/intro.textile
4
+ load. chapters/summary.textile
@@ -0,0 +1 @@
1
+ load. something/not/here.textile
@@ -0,0 +1,2 @@
1
+ load. chapters/cover.textile
2
+ load. chapters/main.textile
@@ -0,0 +1,19 @@
1
+ title. Sample Document
2
+
3
+ subtitle. How to load multiple documents
4
+
5
+ author. Thomas Fankhauser
6
+
7
+ copyright. 2010, Thomas Fankhauser, All rights reserved.
8
+
9
+ h0. Abstract
10
+
11
+ The content of the abstract
12
+
13
+ h1. Introduction
14
+
15
+ This is the content of the introduction
16
+
17
+ h1. Summary
18
+
19
+ This is the summary
@@ -0,0 +1,25 @@
1
+ title. Sample Document
2
+
3
+ subtitle. How to load multiple documents
4
+
5
+ author. Thomas Fankhauser
6
+
7
+ copyright. 2010, Thomas Fankhauser, All rights reserved.
8
+
9
+
10
+ h1. Application
11
+
12
+ Okay lets see how this source file looks like
13
+
14
+ source{Application Sample}. src/app.rb
15
+
16
+ This is very interesting to see.
17
+
18
+
19
+ h1. Test
20
+
21
+ But how would we test it?
22
+
23
+ Most probably like this:
24
+
25
+ source. src/test.rb
@@ -0,0 +1 @@
1
+ source. something/not/here.textile
@@ -0,0 +1,53 @@
1
+ title. Sample Document
2
+
3
+ subtitle. How to load multiple documents
4
+
5
+ author. Thomas Fankhauser
6
+
7
+ copyright. 2010, Thomas Fankhauser, All rights reserved.
8
+
9
+
10
+ h1. Application
11
+
12
+ Okay lets see how this source file looks like
13
+
14
+
15
+
16
+ bc{name: Application Sample;}.. module App
17
+ module Sample
18
+ class Base
19
+
20
+ def initialize
21
+ "Some sample code"
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+ p.
29
+
30
+ This is very interesting to see.
31
+
32
+
33
+ h1. Test
34
+
35
+ But how would we test it?
36
+
37
+ Most probably like this:
38
+
39
+
40
+
41
+ bc{name: test.rb;}.. module App
42
+ module Test
43
+ class Base
44
+
45
+ def initialize
46
+ "Starting the tests"
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ p.
@@ -0,0 +1,11 @@
1
+ module App
2
+ module Sample
3
+ class Base
4
+
5
+ def initialize
6
+ "Some sample code"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module App
2
+ module Test
3
+ class Base
4
+
5
+ def initialize
6
+ "Starting the tests"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Helpers
2
+
3
+ # Loads the contents of a fixture
4
+ def load_fixture(path)
5
+ File.open("spec/fixtures/#{path}", 'rb') { |f| f.read }
6
+ end
7
+
8
+ end
9
+
10
+ RSpec.configure do |c|
11
+ c.include Helpers
12
+ end
@@ -0,0 +1,68 @@
1
+ require "booky"
2
+ require_relative "helpers"
3
+
4
+ describe Booky::Textile do
5
+
6
+ it "should have precompilers registered" do
7
+ Booky::Textile.precompilers.should_not be_empty
8
+ end
9
+
10
+ end
11
+
12
+
13
+ describe Booky::Textile::Precompiler do
14
+
15
+ it "should return the same textile if its not changed" do
16
+ textile = load_fixture "textile/load/chapters/cover.textile"
17
+
18
+ class EmptyPrecompiler
19
+ include Booky::Textile::Precompiler
20
+ end
21
+
22
+ precompiled_textile = EmptyPrecompiler.apply(textile)
23
+ precompiled_textile.should eql(textile)
24
+ end
25
+
26
+ end
27
+
28
+ describe Booky::Textile::Load do
29
+
30
+ it "should load the referenced files and replace the selected lines" do
31
+ index = load_fixture "textile/load/index.textile"
32
+ precompiled_index = load_fixture "textile/load/precompiled_index.textile"
33
+
34
+ Booky.source = File.expand_path("spec/fixtures/textile/load/index.textile")
35
+ Booky::Textile::Load.apply(index).should eql(precompiled_index)
36
+ end
37
+
38
+ it "should load the referenced files and replace the selected lines recursive" do
39
+ index = load_fixture "textile/load/index_recursive.textile"
40
+ precompiled_index = load_fixture "textile/load/precompiled_index.textile"
41
+
42
+ Booky.source = File.expand_path("spec/fixtures/textile/load/index_recursive.textile")
43
+ Booky::Textile::Load.apply(index).should eql(precompiled_index)
44
+ end
45
+
46
+ it "should raise a load exception if a file is not found" do
47
+ index_exception = load_fixture "textile/load/index_exception.textile"
48
+ expect { Booky::Textile::Load.apply(index_exception) }.to raise_error(Booky::LoadError)
49
+ end
50
+
51
+ end
52
+
53
+ describe Booky::Textile::Source do
54
+
55
+ it "should load the referenced source" do
56
+ index = load_fixture "textile/source/index.textile"
57
+ precompiled_index = load_fixture "textile/source/precompiled_index.textile"
58
+
59
+ Booky.source = File.expand_path("spec/fixtures/textile/source/index.textile")
60
+ Booky::Textile::Source.apply(index).should eql(precompiled_index)
61
+ end
62
+
63
+ it "should raise a load exception if a file is not found" do
64
+ index_exception = load_fixture "textile/source/index_exception.textile"
65
+ expect { Booky::Textile::Source.apply(index_exception) }.to raise_error(Booky::LoadError)
66
+ end
67
+
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: booky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-02-26 00:00:00.000000000 Z
12
+ date: 2012-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: RedCloth
16
- requirement: &70264805148780 !ruby/object:Gem::Requirement
16
+ requirement: &70213660371200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.2.8
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70264805148780
24
+ version_requirements: *70213660371200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcloth-formatters-docbook
27
- requirement: &70264805147840 !ruby/object:Gem::Requirement
27
+ requirement: &70213660370660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.0.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70264805147840
35
+ version_requirements: *70213660370660
36
36
  description: Create a full blown book pdf from a textile file using docbook and xsl
37
37
  fo in the background
38
38
  email:
@@ -50,9 +50,14 @@ files:
50
50
  - booky.gemspec
51
51
  - lib/booky.rb
52
52
  - lib/booky/docbook.rb
53
+ - lib/booky/exceptions.rb
53
54
  - lib/booky/fo.rb
54
55
  - lib/booky/fonts.rb
55
56
  - lib/booky/pdf.rb
57
+ - lib/booky/textile.rb
58
+ - lib/booky/textile/load.rb
59
+ - lib/booky/textile/precompiler.rb
60
+ - lib/booky/textile/source.rb
56
61
  - lib/booky/version.rb
57
62
  - lib/custom_fonts.xml
58
63
  - lib/examples/bibliography.textile
@@ -65,6 +70,8 @@ files:
65
70
  - lib/examples/phrases.textile
66
71
  - lib/examples/source.textile
67
72
  - lib/examples/tables.textile
73
+ - lib/fonts/.DS_Store
74
+ - lib/fonts/Monaco.ttf
68
75
  - lib/fonts/Ubuntu-B.ttf
69
76
  - lib/fonts/Ubuntu-BI.ttf
70
77
  - lib/fonts/Ubuntu-L.ttf
@@ -83,6 +90,7 @@ files:
83
90
  - lib/fop/fop.bat
84
91
  - lib/fop/fop.cmd
85
92
  - lib/fop/fop.js
93
+ - lib/fop/lib/.DS_Store
86
94
  - lib/fop/lib/README.txt
87
95
  - lib/fop/lib/avalon-framework-4.2.0.jar
88
96
  - lib/fop/lib/avalon-framework.LICENSE.txt
@@ -127,6 +135,7 @@ files:
127
135
  - lib/fop/lib/xmlgraphics-commons-1.4.jar
128
136
  - lib/fop/lib/xmlgraphics-commons.LICENSE.txt
129
137
  - lib/fop/lib/xmlgraphics-commons.NOTICE.txt
138
+ - lib/fop/lib/xslthl-2.0.2.jar
130
139
  - lib/fop/status.xml
131
140
  - lib/params.pdf
132
141
  - lib/stylesheets/.CatalogManager.properties.example
@@ -1608,6 +1617,23 @@ files:
1608
1617
  - lib/stylesheets/xhtml/toc.xsl
1609
1618
  - lib/stylesheets/xhtml/verbatim.xsl
1610
1619
  - lib/stylesheets/xhtml/xref.xsl
1620
+ - spec/fixtures/textile/.DS_Store
1621
+ - spec/fixtures/textile/load/chapters/abstract.textile
1622
+ - spec/fixtures/textile/load/chapters/cover.textile
1623
+ - spec/fixtures/textile/load/chapters/intro.textile
1624
+ - spec/fixtures/textile/load/chapters/main.textile
1625
+ - spec/fixtures/textile/load/chapters/summary.textile
1626
+ - spec/fixtures/textile/load/index.textile
1627
+ - spec/fixtures/textile/load/index_exception.textile
1628
+ - spec/fixtures/textile/load/index_recursive.textile
1629
+ - spec/fixtures/textile/load/precompiled_index.textile
1630
+ - spec/fixtures/textile/source/index.textile
1631
+ - spec/fixtures/textile/source/index_exception.textile
1632
+ - spec/fixtures/textile/source/precompiled_index.textile
1633
+ - spec/fixtures/textile/source/src/app.rb
1634
+ - spec/fixtures/textile/source/src/test.rb
1635
+ - spec/helpers.rb
1636
+ - spec/textile_spec.rb
1611
1637
  homepage: http://www.southdesign.de
1612
1638
  licenses: []
1613
1639
  post_install_message:
@@ -1632,4 +1658,21 @@ rubygems_version: 1.8.15
1632
1658
  signing_key:
1633
1659
  specification_version: 3
1634
1660
  summary: Create a pdf book from a textile
1635
- test_files: []
1661
+ test_files:
1662
+ - spec/fixtures/textile/.DS_Store
1663
+ - spec/fixtures/textile/load/chapters/abstract.textile
1664
+ - spec/fixtures/textile/load/chapters/cover.textile
1665
+ - spec/fixtures/textile/load/chapters/intro.textile
1666
+ - spec/fixtures/textile/load/chapters/main.textile
1667
+ - spec/fixtures/textile/load/chapters/summary.textile
1668
+ - spec/fixtures/textile/load/index.textile
1669
+ - spec/fixtures/textile/load/index_exception.textile
1670
+ - spec/fixtures/textile/load/index_recursive.textile
1671
+ - spec/fixtures/textile/load/precompiled_index.textile
1672
+ - spec/fixtures/textile/source/index.textile
1673
+ - spec/fixtures/textile/source/index_exception.textile
1674
+ - spec/fixtures/textile/source/precompiled_index.textile
1675
+ - spec/fixtures/textile/source/src/app.rb
1676
+ - spec/fixtures/textile/source/src/test.rb
1677
+ - spec/helpers.rb
1678
+ - spec/textile_spec.rb