bookie 0.0.11 → 0.0.12
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.
- data/CHANGELOG.md +5 -0
- data/data/templates/epub_chapter.erb +11 -0
- data/data/templates/mobi_chapter.erb +13 -0
- data/data/templates/opf.erb +32 -0
- data/examples/simple-web-ui.rb +31 -0
- data/lib/bookie.rb +5 -0
- data/lib/bookie/book.rb +3 -2
- data/lib/bookie/emitters/epub.rb +36 -24
- data/lib/bookie/emitters/mobi.rb +31 -21
- data/lib/bookie/emitters/pdf.rb +3 -0
- data/lib/bookie/version.rb +1 -1
- metadata +6 -3
- data/examples/bookie-basic-feature.pdf +0 -0
data/CHANGELOG.md
CHANGED
|
@@ -57,3 +57,8 @@ Fix some PDF bugs and make a little draw() helper for emitter.
|
|
|
57
57
|
Remove Document class for now. Remove bookie executable for now. Remove all old
|
|
58
58
|
examples from <= 0.0.10. Move towards a book manifest type API. Much work needs
|
|
59
59
|
to be done to make this actually usable.
|
|
60
|
+
|
|
61
|
+
## 0.0.12 (2011.05.12)
|
|
62
|
+
|
|
63
|
+
Added rudimentary chapter support for EPUB, MOBI, and PDF. Render once per
|
|
64
|
+
emitter rather than once per chapter per emitter (bugfix).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
|
3
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
5
|
+
<head>
|
|
6
|
+
<style type="text/css">
|
|
7
|
+
pre { font-size: 1.1em }
|
|
8
|
+
</style>
|
|
9
|
+
</head>
|
|
10
|
+
<body><%= content %></body>
|
|
11
|
+
</html>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<style type="text/css">
|
|
4
|
+
h1 { margin-bottom: 3em; font-size: xx-large }
|
|
5
|
+
h2 { font-size: large }
|
|
6
|
+
p { margin-bottom: 1.1em; text-indent: 0 }
|
|
7
|
+
pre { font-size: xx-small }
|
|
8
|
+
li { margin-bottom: 1.1em }
|
|
9
|
+
ul { margin-top: 0em; margin-bottom: 0em;}
|
|
10
|
+
</style>
|
|
11
|
+
</head>
|
|
12
|
+
<body><%= content %></body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
the identifier specified in <metadata> as <dc:Identifier id="XYZ">.
|
|
3
|
+
-->
|
|
4
|
+
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="BookId">
|
|
5
|
+
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
|
|
6
|
+
<dc:title>Bookie Generated Example</dc:title>
|
|
7
|
+
<dc:language>en</dc:language>
|
|
8
|
+
<dc:creator>Gregory Brown</dc:creator>
|
|
9
|
+
</metadata>
|
|
10
|
+
|
|
11
|
+
<manifest>
|
|
12
|
+
<% @chapters.each_index do |i| %>
|
|
13
|
+
<item id="chapter<%= i %>" media-type="text/x-oeb1-document" href="<%= i %>.html"></item>
|
|
14
|
+
<% end %>
|
|
15
|
+
|
|
16
|
+
<spine>
|
|
17
|
+
<% @chapters.each_index do |i| %>
|
|
18
|
+
<itemref idref="chapter<%= i %>"/>
|
|
19
|
+
<% end %>
|
|
20
|
+
</spine>
|
|
21
|
+
</manifest>
|
|
22
|
+
|
|
23
|
+
<guide>
|
|
24
|
+
<% @chapters.each_with_index do |(title, content), i| %>
|
|
25
|
+
<% if i == 0 %>
|
|
26
|
+
<reference type="text" title="Beginning" href="<%= i %>.html"></reference>
|
|
27
|
+
<% elsif i == @chapters.length - 1 %>
|
|
28
|
+
<reference type="text" title="End" href="<%= i %>.html"></reference>
|
|
29
|
+
<% end %>
|
|
30
|
+
<% end %>
|
|
31
|
+
</guide>
|
|
32
|
+
</package>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "sinatra"
|
|
2
|
+
require_relative "../lib/bookie"
|
|
3
|
+
|
|
4
|
+
get "/" do
|
|
5
|
+
haml :index
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
post "/" do
|
|
9
|
+
content_type 'application/pdf'
|
|
10
|
+
attachment "#{params['title']}.pdf"
|
|
11
|
+
|
|
12
|
+
emitter = Bookie::Emitters::PDF.new
|
|
13
|
+
emitter.start_new_chapter(title: params["title"],
|
|
14
|
+
header: params["header"])
|
|
15
|
+
Bookie::Parser.parse(params["body"], emitter)
|
|
16
|
+
|
|
17
|
+
emitter.document.render
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
__END__
|
|
21
|
+
|
|
22
|
+
@@ index
|
|
23
|
+
|
|
24
|
+
%form{:method => "post"}
|
|
25
|
+
%input{:type => "text", :name => "title"}
|
|
26
|
+
%br
|
|
27
|
+
%input{:type => "text", :name => "header"}
|
|
28
|
+
%br
|
|
29
|
+
%textarea{:name => "body"}
|
|
30
|
+
%br
|
|
31
|
+
%input{:type => "submit"}
|
data/lib/bookie.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "date"
|
|
2
2
|
require "fileutils"
|
|
3
3
|
require "tempfile"
|
|
4
|
+
require "erb"
|
|
4
5
|
|
|
5
6
|
require "prawn"
|
|
6
7
|
require "eeepub"
|
|
@@ -9,3 +10,7 @@ require_relative "bookie/version"
|
|
|
9
10
|
require_relative "bookie/parser"
|
|
10
11
|
require_relative "bookie/emitters"
|
|
11
12
|
require_relative "bookie/book"
|
|
13
|
+
|
|
14
|
+
module Bookie
|
|
15
|
+
TEMPLATES_DIR = File.expand_path("#{File.dirname(__FILE__)}/../data/templates/")
|
|
16
|
+
end
|
data/lib/bookie/book.rb
CHANGED
|
@@ -19,9 +19,10 @@ module Bookie
|
|
|
19
19
|
emitter.start_new_chapter(header: "Chapter #{i+1}",
|
|
20
20
|
title: name)
|
|
21
21
|
Bookie::Parser.parse(File.read(file), emitter)
|
|
22
|
-
output_file = "#{basename}#{emitter.class.extension}"
|
|
23
|
-
emitter.render(file: output_file)
|
|
24
22
|
end
|
|
23
|
+
|
|
24
|
+
output_file = "#{basename}#{emitter.class.extension}"
|
|
25
|
+
emitter.render(file: output_file)
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
28
|
end
|
data/lib/bookie/emitters/epub.rb
CHANGED
|
@@ -5,32 +5,44 @@ module Bookie
|
|
|
5
5
|
".epub"
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
def initialize
|
|
9
|
+
@chapters = []
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def start_new_chapter(params)
|
|
13
|
+
@body = ""
|
|
14
|
+
|
|
15
|
+
@chapters << [params[:title], @body]
|
|
16
|
+
@body << "<h1>#{params[:title]}</h1>"
|
|
17
|
+
end
|
|
18
|
+
|
|
8
19
|
def render(params)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
pre { font-size: 1.1em }
|
|
17
|
-
</style>
|
|
18
|
-
</head>
|
|
19
|
-
<body><h1>#{params[:title]}</h1>#{@body}</body>
|
|
20
|
-
</html>
|
|
21
|
-
}
|
|
22
|
-
t.close
|
|
23
|
-
FileUtils.mv(t.path, "#{t.path}.html")
|
|
24
|
-
|
|
25
|
-
epub = EeePub.make do
|
|
26
|
-
title params[:title]
|
|
27
|
-
identifier '', :scheme => 'URL'
|
|
28
|
-
uid ''
|
|
29
|
-
|
|
30
|
-
files [File.expand_path("#{t.path}.html")]
|
|
31
|
-
end
|
|
20
|
+
Dir.mktmpdir("bookie-epub") do |dir|
|
|
21
|
+
@chapters.each_with_index do |(title, content),index|
|
|
22
|
+
File.open("#{dir}/#{index}.html", "w") do |f|
|
|
23
|
+
template = File.read("#{Bookie::TEMPLATES_DIR}/epub_chapter.erb")
|
|
24
|
+
f << ERB.new(template).result(binding)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
chapter_filenames = @chapters.length.times.map do |i|
|
|
29
|
+
File.expand_path("#{dir}/#{i}.html")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
chapter_outline = @chapters.map.with_index do |(title,_), i|
|
|
33
|
+
{ :label => title, :content => "#{i}.html" }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
epub = EeePub.make do
|
|
37
|
+
title params[:title]
|
|
38
|
+
identifier '', :scheme => 'URL'
|
|
39
|
+
uid ''
|
|
40
|
+
files chapter_filenames
|
|
41
|
+
nav chapter_outline
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
epub.save(params[:file])
|
|
45
|
+
end
|
|
34
46
|
end
|
|
35
47
|
end
|
|
36
48
|
end
|
data/lib/bookie/emitters/mobi.rb
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
module Bookie
|
|
2
2
|
module Emitters
|
|
3
3
|
class MOBI < HTML
|
|
4
|
+
OPF_TEMPLATE = %{
|
|
5
|
+
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
def self.extension
|
|
5
9
|
".mobi"
|
|
6
10
|
end
|
|
7
11
|
|
|
12
|
+
def initialize
|
|
13
|
+
@chapters = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def start_new_chapter(params)
|
|
17
|
+
@body = ""
|
|
18
|
+
|
|
19
|
+
@chapters << [params[:title], @body]
|
|
20
|
+
@body << "<h1>#{params[:header]}: #{params[:title]}</h1>"
|
|
21
|
+
end
|
|
22
|
+
|
|
8
23
|
def render(params)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
t.close
|
|
26
|
-
FileUtils.mv(t.path, "#{t.path}.html")
|
|
27
|
-
|
|
28
|
-
`kindlegen #{t.path+'.html'} -o #{params[:file]}`
|
|
29
|
-
FileUtils.mv("#{Dir.tmpdir}/#{params[:file]}", ".")
|
|
24
|
+
Dir.mktmpdir("bookie-mobi") do |dir|
|
|
25
|
+
@chapters.each_with_index do |(title, content),index|
|
|
26
|
+
File.open("#{dir}/#{index}.html", "w") do |f|
|
|
27
|
+
template = File.read("#{Bookie::TEMPLATES_DIR}/mobi_chapter.erb")
|
|
28
|
+
f << ERB.new(template).result(binding)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
File.open("#{dir}/book.opf", "w") do |f|
|
|
33
|
+
template = File.read("#{Bookie::TEMPLATES_DIR}/opf.erb")
|
|
34
|
+
f << ERB.new(template).result(binding)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
`kindlegen #{dir}/book.opf -o #{params[:file]}`
|
|
38
|
+
FileUtils.mv("#{dir}/#{params[:file]}", ".")
|
|
39
|
+
end
|
|
30
40
|
end
|
|
31
41
|
end
|
|
32
42
|
end
|
data/lib/bookie/emitters/pdf.rb
CHANGED
|
@@ -16,9 +16,12 @@ module Bookie
|
|
|
16
16
|
register_fonts
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
attr_reader :document
|
|
20
|
+
|
|
19
21
|
def start_new_chapter(params)
|
|
20
22
|
@document.save_graphics_state # HACK for what might be a Prawn bug
|
|
21
23
|
@document.start_new_page
|
|
24
|
+
@document.outline.section(params[:title], :destination => @document.page_number)
|
|
22
25
|
render_header(params)
|
|
23
26
|
end
|
|
24
27
|
|
data/lib/bookie/version.rb
CHANGED
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: bookie
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.0.
|
|
5
|
+
version: 0.0.12
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Gregory Brown
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-
|
|
13
|
+
date: 2011-05-12 00:00:00 -04:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -64,7 +64,7 @@ files:
|
|
|
64
64
|
- test/test_helper.rb
|
|
65
65
|
- test/units/parser_test.rb
|
|
66
66
|
- examples/basic-features.rb
|
|
67
|
-
- examples/
|
|
67
|
+
- examples/simple-web-ui.rb
|
|
68
68
|
- doc/banner.png
|
|
69
69
|
- doc/markdown_syntax.pdf
|
|
70
70
|
- data/fonts/dejavu/DejaVuSans-Bold.ttf
|
|
@@ -91,6 +91,9 @@ files:
|
|
|
91
91
|
- data/fonts/dejavu/encodings.dir
|
|
92
92
|
- data/fonts/dejavu/fonts.dir
|
|
93
93
|
- data/fonts/dejavu/fonts.scale
|
|
94
|
+
- data/templates/epub_chapter.erb
|
|
95
|
+
- data/templates/mobi_chapter.erb
|
|
96
|
+
- data/templates/opf.erb
|
|
94
97
|
- GPLv3
|
|
95
98
|
- README.md
|
|
96
99
|
- CHANGELOG.md
|
|
Binary file
|