bookie 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/examples/basic-features.rb +14 -0
- data/examples/bookie-basic-feature.pdf +0 -0
- data/lib/bookie/book.rb +28 -0
- data/lib/bookie/emitters/epub.rb +37 -0
- data/lib/bookie/emitters/html.rb +46 -0
- data/lib/bookie/emitters/mobi.rb +33 -0
- data/lib/bookie/emitters/null.rb +17 -0
- data/lib/bookie/emitters/pdf.rb +151 -0
- data/lib/bookie/emitters.rb +5 -244
- data/lib/bookie/version.rb +1 -1
- data/lib/bookie.rb +1 -1
- data/test/suite.rb +0 -1
- metadata +12 -12
- data/bin/bookie +0 -6
- data/examples/headings.rb +0 -25
- data/examples/lists.rb +0 -24
- data/examples/preformatted.rb +0 -25
- data/examples/simple_emitters.rb +0 -9
- data/lib/bookie/application.rb +0 -30
- data/lib/bookie/document.rb +0 -14
- data/test/units/document_test.rb +0 -10
data/CHANGELOG.md
CHANGED
@@ -51,3 +51,9 @@ Add barely useful command line app
|
|
51
51
|
## 0.0.10 (2011.04.28)
|
52
52
|
|
53
53
|
Fix some PDF bugs and make a little draw() helper for emitter.
|
54
|
+
|
55
|
+
## 0.0.11 (2011.04.30)
|
56
|
+
|
57
|
+
Remove Document class for now. Remove bookie executable for now. Remove all old
|
58
|
+
examples from <= 0.0.10. Move towards a book manifest type API. Much work needs
|
59
|
+
to be done to make this actually usable.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "../lib/bookie"
|
2
|
+
|
3
|
+
fixture_dir = "#{File.dirname(__FILE__)}/../test/fixtures/"
|
4
|
+
|
5
|
+
book = Bookie::Book.new("Basic Features of Bookie")
|
6
|
+
book.chapter "A single paragraph", "#{fixture_dir}/single_paragraph.md"
|
7
|
+
book.chapter "Multiple paragraphs", "#{fixture_dir}/multi_paragraph_document.md"
|
8
|
+
book.chapter "Preformatted text blocks", "#{fixture_dir}/preformatted_blocks.md"
|
9
|
+
book.chapter "Section headings", "#{fixture_dir}/document_with_headings.md"
|
10
|
+
book.chapter "Unordered lists", "#{fixture_dir}/lists.md"
|
11
|
+
|
12
|
+
book.render("bookie-basic-feature", [Bookie::Emitters::PDF.new,
|
13
|
+
Bookie::Emitters::EPUB.new,
|
14
|
+
Bookie::Emitters::MOBI.new])
|
Binary file
|
data/lib/bookie/book.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Bookie
|
2
|
+
class Book
|
3
|
+
def initialize(name)
|
4
|
+
@name = name
|
5
|
+
@chapters = []
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :name, :chapters
|
9
|
+
|
10
|
+
def chapter(name, file)
|
11
|
+
chapters << [name, file]
|
12
|
+
end
|
13
|
+
|
14
|
+
# FIXME: This is inefficient, it should be possible to fire up the parser
|
15
|
+
# just once with many emitters.
|
16
|
+
def render(basename, emitters)
|
17
|
+
emitters.each do |emitter|
|
18
|
+
chapters.each_with_index do |(name, file), i|
|
19
|
+
emitter.start_new_chapter(header: "Chapter #{i+1}",
|
20
|
+
title: name)
|
21
|
+
Bookie::Parser.parse(File.read(file), emitter)
|
22
|
+
output_file = "#{basename}#{emitter.class.extension}"
|
23
|
+
emitter.render(file: output_file)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Bookie
|
2
|
+
module Emitters
|
3
|
+
class EPUB < HTML
|
4
|
+
def self.extension
|
5
|
+
".epub"
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(params)
|
9
|
+
t = Tempfile.new(params[:file])
|
10
|
+
t << %{<?xml version="1.0" encoding="UTF-8"?>
|
11
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
12
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
13
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
14
|
+
<head>
|
15
|
+
<style type="text/css">
|
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
|
32
|
+
|
33
|
+
epub.save(params[:file])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Bookie
|
2
|
+
module Emitters
|
3
|
+
class HTML
|
4
|
+
def self.extension
|
5
|
+
".html"
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@body = ""
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :body
|
13
|
+
|
14
|
+
def start_new_chapter(params)
|
15
|
+
@body << "<h1>#{params[:header]}: #{params[:title]}</h1>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_paragraph(paragraph)
|
19
|
+
@body << "<p>#{paragraph.contents}</p>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_raw_text(raw_text)
|
23
|
+
@body << "<pre>#{raw_text.contents}</pre>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_section_heading(header)
|
27
|
+
@body << "<h2>#{header.contents}</h2>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_list(list)
|
31
|
+
list_elements = list.contents.map { |li| "<li>#{li}</li>" }.join
|
32
|
+
@body << "<ul>"+list_elements+"</ul>"
|
33
|
+
end
|
34
|
+
|
35
|
+
def render(params)
|
36
|
+
File.open(params[:file], "w") do |file|
|
37
|
+
file << %{
|
38
|
+
<html>
|
39
|
+
<body>#{@body}</body>
|
40
|
+
</html>
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Bookie
|
2
|
+
module Emitters
|
3
|
+
class MOBI < HTML
|
4
|
+
def self.extension
|
5
|
+
".mobi"
|
6
|
+
end
|
7
|
+
|
8
|
+
def render(params)
|
9
|
+
t = Tempfile.new(params[:file])
|
10
|
+
t << %{
|
11
|
+
<html>
|
12
|
+
<head>
|
13
|
+
<style type="text/css">
|
14
|
+
h1 { margin-bottom: 3em; font-size: xx-large }
|
15
|
+
h2 { font-size: large }
|
16
|
+
p { margin-bottom: 1.1em; text-indent: 0 }
|
17
|
+
pre { font-size: xx-small }
|
18
|
+
li { margin-bottom: 1.1em }
|
19
|
+
ul { margin-top: 0em; margin-bottom: 0em;}
|
20
|
+
</style>
|
21
|
+
</head>
|
22
|
+
<body><h1>#{params[:title]}</h1>#{@body}</body>
|
23
|
+
</html>
|
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]}", ".")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
|
3
|
+
module Bookie
|
4
|
+
module Emitters
|
5
|
+
class PDF
|
6
|
+
include Prawn::Measurements
|
7
|
+
|
8
|
+
def self.extension
|
9
|
+
".pdf"
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@document = new_prawn_document
|
14
|
+
@document.extend(Prawn::Measurements)
|
15
|
+
|
16
|
+
register_fonts
|
17
|
+
end
|
18
|
+
|
19
|
+
def start_new_chapter(params)
|
20
|
+
@document.save_graphics_state # HACK for what might be a Prawn bug
|
21
|
+
@document.start_new_page
|
22
|
+
render_header(params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_list(list)
|
26
|
+
items = list.contents
|
27
|
+
|
28
|
+
draw do
|
29
|
+
font("serif", :size => 9) do
|
30
|
+
items.each do |li|
|
31
|
+
li_text = li.gsub(/\s+/," ")
|
32
|
+
|
33
|
+
group do
|
34
|
+
float { text "•" }
|
35
|
+
indent(in2pt(0.15)) do
|
36
|
+
text li_text,
|
37
|
+
inline_format: true,
|
38
|
+
leading: 2
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
move_down in2pt(0.05)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
move_down in2pt(0.05)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_section_heading(section_text)
|
51
|
+
draw do
|
52
|
+
start_new_page unless cursor > in2pt(0.4)
|
53
|
+
|
54
|
+
move_down in2pt(0.1)
|
55
|
+
|
56
|
+
float do
|
57
|
+
font("sans", :style => :bold, :size => 14) do
|
58
|
+
text(section_text.contents.strip)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
move_down in2pt(0.3)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_paragraph(paragraph)
|
67
|
+
draw do
|
68
|
+
font("serif", size: 9) do
|
69
|
+
text(paragraph.contents.strip, align: :justify, leading: 2)
|
70
|
+
end
|
71
|
+
move_down in2pt(0.1)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def build_raw_text(raw_text)
|
76
|
+
sanitized_text = raw_text.contents.gsub(" ", Prawn::Text::NBSP).strip
|
77
|
+
|
78
|
+
draw do
|
79
|
+
font("mono", size: 8) do
|
80
|
+
text sanitized_text
|
81
|
+
move_down in2pt(0.1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def render(params)
|
87
|
+
@document.render_file(params[:file])
|
88
|
+
end
|
89
|
+
|
90
|
+
def render_header(params)
|
91
|
+
draw do
|
92
|
+
font("sans") do
|
93
|
+
text "<b>#{params[:header]}</b>",
|
94
|
+
size: 12, align: :right, inline_format: true
|
95
|
+
stroke_horizontal_rule
|
96
|
+
|
97
|
+
move_down in2pt(0.1)
|
98
|
+
|
99
|
+
text "<b>#{params[:title]}</b>",
|
100
|
+
size: 18, align: :right, inline_format: true
|
101
|
+
|
102
|
+
move_down in2pt(1.25)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def register_fonts
|
108
|
+
dejavu_path = File.dirname(__FILE__) + "/../../../data/fonts/dejavu"
|
109
|
+
|
110
|
+
draw do
|
111
|
+
font_families["sans"] = {
|
112
|
+
:normal => "#{dejavu_path}/DejaVuSansCondensed.ttf",
|
113
|
+
:italic => "#{dejavu_path}/DejaVuSansCondensed-Oblique.ttf",
|
114
|
+
:bold => "#{dejavu_path}/DejaVuSansCondensed-Bold.ttf",
|
115
|
+
:bold_italic => "#{dejavu_path}/DejaVuSansCondensed-BoldOblique.ttf"
|
116
|
+
}
|
117
|
+
|
118
|
+
font_families["mono"] = {
|
119
|
+
:normal => "#{dejavu_path}/DejaVuSansMono.ttf",
|
120
|
+
:italic => "#{dejavu_path}/DejaVuSansMono-Oblique.ttf",
|
121
|
+
:bold => "#{dejavu_path}/DejaVuSansMono-Bold.ttf",
|
122
|
+
:bold_italic => "#{dejavu_path}/DejaVuSansMono-BoldOblique.ttf"
|
123
|
+
}
|
124
|
+
|
125
|
+
font_families["serif"] = {
|
126
|
+
:normal => "#{dejavu_path}/DejaVuSerif.ttf",
|
127
|
+
:italic => "#{dejavu_path}/DejaVuSerif-Italic.ttf",
|
128
|
+
:bold => "#{dejavu_path}/DejaVuSerif-Bold.ttf",
|
129
|
+
:bold_italic => "#{dejavu_path}/DejaVuSerif-BoldItalic.ttf"
|
130
|
+
}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def draw(&block)
|
135
|
+
@document.instance_eval(&block)
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def new_prawn_document
|
142
|
+
Prawn::Document.new( top_margin: in2pt(0.75),
|
143
|
+
bottom_margin: in2pt(1),
|
144
|
+
left_margin: in2pt(1),
|
145
|
+
right_margin: in2pt(1),
|
146
|
+
page_size: [in2pt(7.0), in2pt(9.19)],
|
147
|
+
skip_page_creation: true)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/lib/bookie/emitters.rb
CHANGED
@@ -1,246 +1,7 @@
|
|
1
1
|
# coding: UTF-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def build_raw_text(raw_text)
|
10
|
-
end
|
11
|
-
|
12
|
-
def build_section_heading(header)
|
13
|
-
end
|
14
|
-
|
15
|
-
def build_list(content)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class HTML
|
20
|
-
def initialize
|
21
|
-
@body = ""
|
22
|
-
end
|
23
|
-
|
24
|
-
attr_reader :body
|
25
|
-
|
26
|
-
def build_paragraph(paragraph)
|
27
|
-
@body << "<p>#{paragraph.contents}</p>"
|
28
|
-
end
|
29
|
-
|
30
|
-
def build_raw_text(raw_text)
|
31
|
-
@body << "<pre>#{raw_text.contents}</pre>"
|
32
|
-
end
|
33
|
-
|
34
|
-
def build_section_heading(header)
|
35
|
-
@body << "<h2>#{header.contents}</h2>"
|
36
|
-
end
|
37
|
-
|
38
|
-
def build_list(list)
|
39
|
-
list_elements = list.contents.map { |li| "<li>#{li}</li>" }.join
|
40
|
-
@body << "<ul>"+list_elements+"</ul>"
|
41
|
-
end
|
42
|
-
|
43
|
-
def render(params)
|
44
|
-
File.open(params[:file], "w") do |file|
|
45
|
-
file << %{
|
46
|
-
<html>
|
47
|
-
<body><h1>#{params[:title]}</h1>#{@body}</body>
|
48
|
-
</html>
|
49
|
-
}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class EPUB < HTML
|
55
|
-
def render(params)
|
56
|
-
t = Tempfile.new(params[:file])
|
57
|
-
t << %{<?xml version="1.0" encoding="UTF-8"?>
|
58
|
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
59
|
-
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
60
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
61
|
-
<head>
|
62
|
-
<style type="text/css">
|
63
|
-
pre { font-size: 1.1em }
|
64
|
-
</style>
|
65
|
-
</head>
|
66
|
-
<body><h1>#{params[:title]}</h1>#{@body}</body>
|
67
|
-
</html>
|
68
|
-
}
|
69
|
-
t.close
|
70
|
-
FileUtils.mv(t.path, "#{t.path}.html")
|
71
|
-
|
72
|
-
epub = EeePub.make do
|
73
|
-
title params[:title]
|
74
|
-
identifier '', :scheme => 'URL'
|
75
|
-
uid ''
|
76
|
-
|
77
|
-
files [File.expand_path("#{t.path}.html")]
|
78
|
-
end
|
79
|
-
|
80
|
-
epub.save(params[:file])
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class MOBI < HTML
|
85
|
-
def render(params)
|
86
|
-
t = Tempfile.new(params[:file])
|
87
|
-
t << %{
|
88
|
-
<html>
|
89
|
-
<head>
|
90
|
-
<style type="text/css">
|
91
|
-
h1 { margin-bottom: 3em; font-size: xx-large }
|
92
|
-
h2 { font-size: large }
|
93
|
-
p { margin-bottom: 1.1em; text-indent: 0 }
|
94
|
-
pre { font-size: xx-small }
|
95
|
-
li { margin-bottom: 1.1em }
|
96
|
-
ul { margin-top: 0em; margin-bottom: 0em;}
|
97
|
-
</style>
|
98
|
-
</head>
|
99
|
-
<body><h1>#{params[:title]}</h1>#{@body}</body>
|
100
|
-
</html>
|
101
|
-
}
|
102
|
-
t.close
|
103
|
-
FileUtils.mv(t.path, "#{t.path}.html")
|
104
|
-
|
105
|
-
`kindlegen #{t.path+'.html'} -o #{params[:file]}`
|
106
|
-
FileUtils.mv("#{Dir.tmpdir}/#{params[:file]}", ".")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
class PDF
|
111
|
-
include Prawn::Measurements
|
112
|
-
|
113
|
-
def initialize(params)
|
114
|
-
@document = new_prawn_document
|
115
|
-
@document.extend(Prawn::Measurements)
|
116
|
-
|
117
|
-
register_fonts
|
118
|
-
render_header(params)
|
119
|
-
end
|
120
|
-
|
121
|
-
def build_list(list)
|
122
|
-
items = list.contents
|
123
|
-
|
124
|
-
draw do
|
125
|
-
font("serif", :size => 9) do
|
126
|
-
items.each do |li|
|
127
|
-
li_text = li.gsub(/\s+/," ")
|
128
|
-
|
129
|
-
group do
|
130
|
-
float { text "•" }
|
131
|
-
indent(in2pt(0.15)) do
|
132
|
-
text li_text,
|
133
|
-
inline_format: true,
|
134
|
-
leading: 2
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
move_down in2pt(0.05)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
move_down in2pt(0.05)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def build_section_heading(section_text)
|
147
|
-
draw do
|
148
|
-
start_new_page unless cursor > in2pt(0.4)
|
149
|
-
|
150
|
-
move_down in2pt(0.1)
|
151
|
-
|
152
|
-
float do
|
153
|
-
font("sans", :style => :bold, :size => 14) do
|
154
|
-
text(section_text.contents.strip)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
move_down in2pt(0.3)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def build_paragraph(paragraph)
|
163
|
-
draw do
|
164
|
-
font("serif", size: 9) do
|
165
|
-
text(paragraph.contents.strip, align: :justify, leading: 2)
|
166
|
-
end
|
167
|
-
move_down in2pt(0.1)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
def build_raw_text(raw_text)
|
172
|
-
sanitized_text = raw_text.contents.gsub(" ", Prawn::Text::NBSP).strip
|
173
|
-
|
174
|
-
draw do
|
175
|
-
font("mono", size: 8) do
|
176
|
-
text sanitized_text
|
177
|
-
move_down in2pt(0.1)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
def render(params)
|
183
|
-
@document.render_file(params[:file])
|
184
|
-
end
|
185
|
-
|
186
|
-
def render_header(params)
|
187
|
-
draw do
|
188
|
-
font("sans") do
|
189
|
-
text "<b>#{params[:header]}</b>",
|
190
|
-
size: 12, align: :right, inline_format: true
|
191
|
-
stroke_horizontal_rule
|
192
|
-
|
193
|
-
move_down in2pt(0.1)
|
194
|
-
|
195
|
-
text "<b>#{params[:title]}</b>",
|
196
|
-
size: 18, align: :right, inline_format: true
|
197
|
-
|
198
|
-
move_down in2pt(1.25)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def register_fonts
|
204
|
-
dejavu_path = File.dirname(__FILE__) + "/../../data/fonts/dejavu"
|
205
|
-
|
206
|
-
draw do
|
207
|
-
font_families["sans"] = {
|
208
|
-
:normal => "#{dejavu_path}/DejaVuSansCondensed.ttf",
|
209
|
-
:italic => "#{dejavu_path}/DejaVuSansCondensed-Oblique.ttf",
|
210
|
-
:bold => "#{dejavu_path}/DejaVuSansCondensed-Bold.ttf",
|
211
|
-
:bold_italic => "#{dejavu_path}/DejaVuSansCondensed-BoldOblique.ttf"
|
212
|
-
}
|
213
|
-
|
214
|
-
font_families["mono"] = {
|
215
|
-
:normal => "#{dejavu_path}/DejaVuSansMono.ttf",
|
216
|
-
:italic => "#{dejavu_path}/DejaVuSansMono-Oblique.ttf",
|
217
|
-
:bold => "#{dejavu_path}/DejaVuSansMono-Bold.ttf",
|
218
|
-
:bold_italic => "#{dejavu_path}/DejaVuSansMono-BoldOblique.ttf"
|
219
|
-
}
|
220
|
-
|
221
|
-
font_families["serif"] = {
|
222
|
-
:normal => "#{dejavu_path}/DejaVuSerif.ttf",
|
223
|
-
:italic => "#{dejavu_path}/DejaVuSerif-Italic.ttf",
|
224
|
-
:bold => "#{dejavu_path}/DejaVuSerif-Bold.ttf",
|
225
|
-
:bold_italic => "#{dejavu_path}/DejaVuSerif-BoldItalic.ttf"
|
226
|
-
}
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
def draw(&block)
|
231
|
-
@document.instance_eval(&block)
|
232
|
-
end
|
233
|
-
|
234
|
-
|
235
|
-
private
|
236
|
-
|
237
|
-
def new_prawn_document
|
238
|
-
Prawn::Document.new( top_margin: in2pt(0.75),
|
239
|
-
bottom_margin: in2pt(1),
|
240
|
-
left_margin: in2pt(1),
|
241
|
-
right_margin: in2pt(1),
|
242
|
-
page_size: [in2pt(7.0), in2pt(9.19)] )
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
3
|
+
require_relative "emitters/null"
|
4
|
+
require_relative "emitters/html"
|
5
|
+
require_relative "emitters/epub"
|
6
|
+
require_relative "emitters/mobi"
|
7
|
+
require_relative "emitters/pdf"
|
data/lib/bookie/version.rb
CHANGED
data/lib/bookie.rb
CHANGED
data/test/suite.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.11
|
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-04-
|
13
|
+
date: 2011-04-30 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -38,16 +38,19 @@ dependencies:
|
|
38
38
|
description: Eventually this may be a markdown to PDF, ePUB, MOBI processor. For now it's just something I'm playing around with, so use at your own risk
|
39
39
|
email:
|
40
40
|
- gregory.t.brown@gmail.com
|
41
|
-
executables:
|
42
|
-
|
41
|
+
executables: []
|
42
|
+
|
43
43
|
extensions: []
|
44
44
|
|
45
45
|
extra_rdoc_files: []
|
46
46
|
|
47
47
|
files:
|
48
|
-
-
|
49
|
-
- lib/bookie/
|
50
|
-
- lib/bookie/
|
48
|
+
- lib/bookie/book.rb
|
49
|
+
- lib/bookie/emitters/epub.rb
|
50
|
+
- lib/bookie/emitters/html.rb
|
51
|
+
- lib/bookie/emitters/mobi.rb
|
52
|
+
- lib/bookie/emitters/null.rb
|
53
|
+
- lib/bookie/emitters/pdf.rb
|
51
54
|
- lib/bookie/emitters.rb
|
52
55
|
- lib/bookie/parser.rb
|
53
56
|
- lib/bookie/version.rb
|
@@ -59,12 +62,9 @@ files:
|
|
59
62
|
- test/fixtures/single_paragraph.md
|
60
63
|
- test/suite.rb
|
61
64
|
- test/test_helper.rb
|
62
|
-
- test/units/document_test.rb
|
63
65
|
- test/units/parser_test.rb
|
64
|
-
- examples/
|
65
|
-
- examples/
|
66
|
-
- examples/preformatted.rb
|
67
|
-
- examples/simple_emitters.rb
|
66
|
+
- examples/basic-features.rb
|
67
|
+
- examples/bookie-basic-feature.pdf
|
68
68
|
- doc/banner.png
|
69
69
|
- doc/markdown_syntax.pdf
|
70
70
|
- data/fonts/dejavu/DejaVuSans-Bold.ttf
|
data/bin/bookie
DELETED
data/examples/headings.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative "../lib/bookie"
|
2
|
-
Prawn.debug = true
|
3
|
-
|
4
|
-
file = "#{File.dirname(__FILE__)}/../test/fixtures/document_with_headings.md"
|
5
|
-
|
6
|
-
pdf_document = Bookie::Document.new(file, Bookie::Emitters::PDF.new(
|
7
|
-
header: "Ruby Best Practices", title: "Learning From Bad Ideas"))
|
8
|
-
|
9
|
-
pdf_document.render(file: "output.pdf")
|
10
|
-
|
11
|
-
html_document = Bookie::Document.new(file, Bookie::Emitters::HTML.new)
|
12
|
-
|
13
|
-
html_document.render(title: "Learning From Bad Ideas",
|
14
|
-
file: "output.html")
|
15
|
-
|
16
|
-
mobi_document = Bookie::Document.new(file, Bookie::Emitters::MOBI.new)
|
17
|
-
|
18
|
-
mobi_document.render(title: "Learning From Bad Ideas",
|
19
|
-
file: "output.mobi")
|
20
|
-
|
21
|
-
epub_document = Bookie::Document.new(file, Bookie::Emitters::EPUB.new)
|
22
|
-
|
23
|
-
epub_document.render(title: "Learning From Bad Ideas",
|
24
|
-
file: "output.epub")
|
25
|
-
|
data/examples/lists.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "../lib/bookie"
|
2
|
-
Prawn.debug = true
|
3
|
-
|
4
|
-
file = "#{File.dirname(__FILE__)}/../test/fixtures/lists.md"
|
5
|
-
|
6
|
-
pdf_document = Bookie::Document.new(file, Bookie::Emitters::PDF.new(
|
7
|
-
header: "Ruby Mendicant University", title: "Project Guidelines"))
|
8
|
-
|
9
|
-
pdf_document.render(file: "output.pdf")
|
10
|
-
|
11
|
-
html_document = Bookie::Document.new(file, Bookie::Emitters::HTML.new)
|
12
|
-
|
13
|
-
html_document.render(title: "Project Guidelines",
|
14
|
-
file: "output.html")
|
15
|
-
|
16
|
-
mobi_document = Bookie::Document.new(file, Bookie::Emitters::MOBI.new)
|
17
|
-
|
18
|
-
mobi_document.render(title: "Project Guidelines",
|
19
|
-
file: "output.mobi")
|
20
|
-
|
21
|
-
epub_document = Bookie::Document.new(file, Bookie::Emitters::EPUB.new)
|
22
|
-
|
23
|
-
epub_document.render(title: "Project Guidelines",
|
24
|
-
file: "output.epub")
|
data/examples/preformatted.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative "../lib/bookie"
|
2
|
-
Prawn.debug = true
|
3
|
-
|
4
|
-
file = "#{File.dirname(__FILE__)}/../test/fixtures/preformatted_blocks.md"
|
5
|
-
|
6
|
-
pdf_document = Bookie::Document.new(file, Bookie::Emitters::PDF.new(
|
7
|
-
header: "Practicing Ruby: Issue #1", title: "Ruby's Method Lookup Path"
|
8
|
-
))
|
9
|
-
|
10
|
-
pdf_document.render(file: "output.pdf")
|
11
|
-
|
12
|
-
html_document = Bookie::Document.new(file, Bookie::Emitters::HTML.new)
|
13
|
-
|
14
|
-
html_document.render(title: "Ruby's Method Lookup Path",
|
15
|
-
file: "output.html")
|
16
|
-
|
17
|
-
mobi_document = Bookie::Document.new(file, Bookie::Emitters::MOBI.new)
|
18
|
-
|
19
|
-
mobi_document.render(title: "Ruby's Method Lookup Path",
|
20
|
-
file: "output.mobi")
|
21
|
-
|
22
|
-
epub_document = Bookie::Document.new(file, Bookie::Emitters::EPUB.new)
|
23
|
-
|
24
|
-
epub_document.render(title: "Ruby's Method Lookup Path",
|
25
|
-
file: "output.epub")
|
data/examples/simple_emitters.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require_relative "../lib/bookie"
|
2
|
-
Prawn.debug = true
|
3
|
-
|
4
|
-
file = "#{File.dirname(__FILE__)}/../test/fixtures/multi_paragraph_document.md"
|
5
|
-
|
6
|
-
pdf_document = Bookie::Document.new(file, Bookie::Emitters::PDF.new(
|
7
|
-
header: "Majestic Sea Creature Blog", title: "Why does RbMU exist?"))
|
8
|
-
|
9
|
-
pdf_document.render(file: "output.pdf")
|
data/lib/bookie/application.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require "optparse"
|
2
|
-
|
3
|
-
module Bookie
|
4
|
-
module Application
|
5
|
-
extend self
|
6
|
-
|
7
|
-
def run(*args)
|
8
|
-
options = {}
|
9
|
-
|
10
|
-
input = OptionParser.new do |opts|
|
11
|
-
opts.on("-n", "--name NAME", "Document name") do |v|
|
12
|
-
options[:header] = v
|
13
|
-
end
|
14
|
-
|
15
|
-
opts.on("-t", "--title TITLE", "Document title") do |v|
|
16
|
-
options[:title] = v
|
17
|
-
end
|
18
|
-
end.parse!(args).first
|
19
|
-
|
20
|
-
basename = File.basename(input, ".md")
|
21
|
-
|
22
|
-
Bookie::Document.new(input, Bookie::Emitters::PDF.new(options))
|
23
|
-
.render(file: "#{basename}.pdf")
|
24
|
-
Bookie::Document.new(input, Bookie::Emitters::MOBI.new)
|
25
|
-
.render({file: "#{basename}.mobi"}.merge(options))
|
26
|
-
Bookie::Document.new(input, Bookie::Emitters::EPUB.new)
|
27
|
-
.render({file: "#{basename}.mobi"}.merge(options))
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/bookie/document.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module Bookie
|
2
|
-
class Document
|
3
|
-
def initialize(filename, emitter=Bookie::Emitters::Null.new, parser=Bookie::Parser)
|
4
|
-
@emitter = emitter
|
5
|
-
@contents = parser.parse(File.read(filename), emitter)
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_reader :emitter, :contents
|
9
|
-
|
10
|
-
def render(*args)
|
11
|
-
@emitter.render(*args)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
data/test/units/document_test.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require_relative "../test_helper"
|
2
|
-
|
3
|
-
context "A Document" do
|
4
|
-
test "should be parsed into an array of contents" do
|
5
|
-
sample_text = fixture("multi_paragraph_document.md")
|
6
|
-
document = Bookie::Document.new(sample_text)
|
7
|
-
|
8
|
-
refute document.contents.empty?, "contents should not be empty"
|
9
|
-
end
|
10
|
-
end
|