bookshop 0.0.19 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,12 +1,18 @@
1
- == Welcome to bookshop
1
+ === http://blueheadpublishing.github.com/bookshop/assets/logo.png
2
2
 
3
- bookShop is a publishing framework for html-to-pdf/(e)book toolchain happiness and sustainable productivity. The framework is optimized to help developers quickly ramp-up, allowing them to more rapidly jump in and develop their html-to-pdf/(e)book (print-pdf, epub, mobi, etc.) flows, by favoring convention over configuration, setting them up with best practices, standards and tools from the start.
3
+ "a book publishing framework for today's publishing world"
4
+
5
+ bookshop is a book publishing framework for publishers, editors, and coders in today's publishing industry. bookshop provides a framework for developing books using well-known/standard web languages like HTML/CSS, which are then converted into pdf and other (e)book formats. The framework is optimized to help developers quickly ramp-up, allowing them to jump in and develop their html-to-pdf/(e)book flows, by favoring convention over configuration, setting them up with best-practices, standards and tools from the start.
4
6
 
5
7
  bookshop hopes to simplify the process by:
6
- * using common tools like HTML, CSS, etc. to make the creation of your book comfortable and familiar, greatly reducing the learning curve for your developers, authors, agents, and other team members
7
- * providing a Ruby Gem to make building a book from HTML as easy as 'gem install bookshop'
8
+ * separating the book into layers
9
+ * *Content*: the book's source - <i>writings, images, videos, copy</i>
10
+ * *Structure*: using div/css microformat to describe the book's structure - <i>chapter, section, etc.</i>
11
+ * *Style*: stylesheets to create the book's layout - <i>fonts, margins, color, etc.</i>
12
+ * using common tools like HTML/CSS to make the creation of your book comfortable and familiar, greatly reducing the learning curve for your developers, authors, agents, and other team members
13
+ * providing a Ruby Gem to make building a book in HTML as easy as 'gem install bookshop'
8
14
  * pulling all the html-to-pdf/(e)book tools together into one place (wkhtmltopdf, kindlegen, epubcheck)
9
- * sticking with open-source tools
15
+ * sticking with open-source tools to encourage community development
10
16
  * giving the developer a set of scripts to automate the redundant stuff
11
17
  * providing an architecture/structure that follows best-practices and simplification (DRY... Don't Repeat Yourself)
12
18
 
@@ -14,8 +20,7 @@ bookshop hopes to simplify the process by:
14
20
 
15
21
  === System Requirements
16
22
 
17
- * Ruby v1.8.7 or v1.9.2 http://www.ruby-lang.org/en/downloads/
18
- * Rubygems v1.3.6 http://docs.rubygems.org/read/chapter/3
23
+ * Ruby v1.8.7 or higher http://www.ruby-lang.org/en/downloads/
19
24
 
20
25
  == Installation
21
26
 
@@ -25,13 +30,13 @@ bookshop hopes to simplify the process by:
25
30
 
26
31
  === Install wkhtmltopdf
27
32
 
28
- 1. Install by hand (recommended):
33
+ 1. Try using the wkhtmltopdf-binary gem (mac + linux i386)
29
34
 
30
- https://github.com/blueheadpublishing/bookshop/wiki/Installing-wkhtmltopdf
35
+ $ gem install wkhtmltopdf-binary
31
36
 
32
- 2. Try using the wkhtmltopdf-binary gem (mac + linux i386)
37
+ 2. Install by hand (for windows or users who want to install newer builds):
33
38
 
34
- $ gem install wkhtmltopdf-binary
39
+ https://github.com/blueheadpublishing/bookshop/wiki/Installing-wkhtmltopdf
35
40
 
36
41
  3. The wkhtmltopdf site has more info
37
42
 
@@ -39,18 +44,30 @@ https://github.com/blueheadpublishing/bookshop/wiki/Installing-wkhtmltopdf
39
44
 
40
45
  == Using bookshop
41
46
 
42
- === Create a bookshop application
47
+ === Create a bookshop book
43
48
 
44
- $ bookshop new name_of_book
49
+ $ bookshop new my_new_book
45
50
 
46
- This will create a new bookshop app in /path/to/name_of_book
47
-
48
- * If you can't issue bookshop from your command line, make sure you have included your gems folder in your system $PATH. In unix you can add the following to your .bashrc file in your home folder (this example is for Ubuntu 10.10):
51
+ This will create a new bookshop book in /path/to/my_new_book with the following structure:
52
+
53
+ |-- book/ # Source files for your book
54
+ |--book.html.erb # The master file
55
+ |--css/
56
+ |--stylesheet.css
57
+ |--images/
58
+
59
+ |-- builds/ # All the builds are created here
60
+ |--epub/
61
+ |--html/
62
+ |--mobi/
63
+ |--pdf/
64
+
65
+ |-- config/ # Your config and data settings
66
+ |--book.yml # Settings/Data for your book
49
67
 
50
- PATH="$PATH:/var/lib/gems/1.8/bin"
51
- export PATH
52
68
 
53
69
  === Editing Your New Book
70
+
54
71
  ==== Where does my Book really live?
55
72
 
56
73
  All of the source documents and assets for your book are stored in the +book/+ folder. So your stylesheets, images, text - everything used for building your book - lives here. Ideally, you should only every edit files in your +book/+ folder (with the exception of your config/book.yml file).
@@ -59,23 +76,15 @@ All of the source documents and assets for your book are stored in the +book/+ f
59
76
 
60
77
  The source files are all in ERB. ERB is a templating language for the Ruby programming language. Why is this cool? Because it means that you can use HTML _and_ you can embed Ruby code in your source files. In other words, you can do all kinds of cool programmy things. Like embed ruby functions and calls:
61
78
 
62
- <p>Today is <%= Time.now.strftime('%A') %>.</p>
63
-
64
- or
79
+ <p>Today is <%= Time.now.strftime('%A') %>.</p> # creates -> <p>Today is Thursday.</p>
65
80
 
66
- items = [ "ball", "stick", "corgi" ]
67
-
68
- <ul>
69
- <% items.each do |item| %>
70
- <li><%= item %></li>
71
- <% end %>
72
- </ul>
81
+ More information on ERB - http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
73
82
 
74
83
  ==== One File to Rule Them All!
75
84
 
76
85
  Your master file (which is used to build everything) is the +book.html.erb+ file (remember that we are in the +book/+ folder). You could of course just use this file and put all of your book contents here, making one enormous file, but we don't recommend it...
77
86
 
78
- ==== The Magic of include()
87
+ ==== The Magic of import()
79
88
 
80
89
  Are you writing another "War and Peace"? We've created a nice way to make your epic book easier to manage. Rather than putting everything in the +book.html.erb+ file, you can +import+ files. This allows you to break your book up into smaller, more manageable pieces. This makes it soooooo much easier to manage your book. And others will thank you for it..
81
90
 
@@ -147,9 +156,9 @@ Here's an example +config/book.yml+ file with some Book Variables:
147
156
 
148
157
  You can then use these Book Variables in your book source file:
149
158
 
150
- <p>The book isbn is <%= book.isbn %></p>
151
- <p>The html title is <%= book.html.title %></p>
152
- <p>The epub pub_date is <%= book.epub.pub_date %></p>
159
+ <p>The book isbn is <%= @book.isbn %></p>
160
+ <p>The html title is <%= @book.html.title %></p>
161
+ <p>The epub pub_date is <%= @book.epub.pub_date %></p>
153
162
 
154
163
  Note that you can construct and/or nest variables however you want to:
155
164
 
@@ -162,7 +171,7 @@ Note that you can construct and/or nest variables however you want to:
162
171
 
163
172
  Then call it in your source file with the variable:
164
173
 
165
- <p>My made up friend's name is <%= book.my.madeup.friend.name %>
174
+ <p>My made up friend's name is <%= @book.my.madeup.friend.name %>
166
175
 
167
176
  More info about YAML:
168
177
 
@@ -172,30 +181,68 @@ http://en.wikipedia.org/wiki/YAML
172
181
 
173
182
  So, do you want to see something cool? Now that we have the Output Variable and Book Variables, we can combine them to do nifty things, like:
174
183
 
175
- <p>The ISBN is <%= book.isbn %></p>
184
+ <p>The ISBN is <%= @book.isbn %></p>
176
185
  <p>Title:
177
186
  <% if @output == :html %>
178
- <%= book.html.title %>
187
+ <%= @book.html.title %>
179
188
  <% elsif @output == :pdf %>
180
- <%= book.pdf.title %>
189
+ <%= @book.pdf.title %>
181
190
  <% elsif @output == :epub %>
182
- <%= book.epub.title %>
191
+ <%= @book.epub.title %>
183
192
  <% end %>
184
193
  </p>
185
194
 
186
195
  Please explore other creative ways to structure and enhance your book (we'd love to see how you are doing it).
187
196
 
188
- http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
189
-
190
197
  === Building Your First Book
191
198
 
199
+ To build an HTML format of your book from the ERB source:
200
+
201
+ $ bookshop build html # -> find the output in builds/html/book_(date).html
202
+
192
203
  To build a pdf format of your book from the ERB source:
193
204
 
194
205
  $ bookshop build pdf # -> find the output in builds/pdf/book_(date).pdf
195
206
 
196
- To build an HTML format of your book from the ERB source:
207
+ ==== Editing your pdf document options
197
208
 
198
- $ bookshop build html # -> find the output in builds/html/book_(date).html
209
+ What if you want your pdf to print as Lanscape, or a different page-size, or in grayscale? Because bookshop uses PDFKit, you can pass wkhtmltopdf (the pdf rendering engine) options by way of <meta> tags in your html source code.
210
+
211
+ For example, to print in Landscape mode, in your master +book/book.html.erb+ file we can add <meta name="pdfkit-orientation" content="Landscape" />:
212
+
213
+ so you html would be:
214
+
215
+ <html>
216
+ <head>
217
+ <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
218
+ <meta name="pdfkit-orientation" content="Landscape" />
219
+ <title>how-to bookshop</title>
220
+ <link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
221
+ </head>
222
+ <body>
223
+ <p>The ISBN is <%= @book.isbn %></p>
224
+
225
+ Here's a list of other options https://github.com/blueheadpublishing/bookshop/wiki/wkhtmltopdf-options
226
+
227
+ Or you can look at all of the possible wkhtmltopdf options by using the command:
228
+
229
+ $ wkhtmltopdf --extended-help
230
+
231
+ Your meta tags should use the following naming conventions.
232
+
233
+ * For each option, replace the double-dashes '--' before the option with +pdfkit-+ and change single-dashes '-' to an underscore +_+.
234
+ --page-size
235
+
236
+ becomes
237
+
238
+ <meta name="pdfkit-page_size" content="Letter" />
239
+
240
+ * For options that do not require an additional parameter/value, you still need to include the content attribute, but keep it blank.
241
+ --grayscale
242
+
243
+ becomes
244
+
245
+ <meta name="pdfkit-grayscale" content="" />
199
246
 
200
247
  == Example Book
201
248
 
@@ -213,14 +260,20 @@ You can then build the book into whatever format you like.
213
260
 
214
261
  The default directory structure of a generated bookshop project:
215
262
 
216
- |-- book
217
- |-- builds
218
- epub
219
- html
220
- mobi
221
- pdf
263
+ |-- book/ # Source files for your book
264
+ |--book.html.erb # The master file
265
+ |--css/
266
+ |--stylesheet.css
267
+ |--images/
268
+
269
+ |-- builds/ # All the builds are created here
270
+ |--epub/
271
+ |--html/
272
+ |--mobi/
273
+ |--pdf/
222
274
 
223
- |-- config
275
+ |-- config/ # Your config and data settings
276
+ |--book.yml # Settings/Data for your book
224
277
 
225
278
  book
226
279
  Holds all the manuscript html code/files. This is where your master manuscript lives from which everything is built.
@@ -249,9 +302,45 @@ config
249
302
  6. Let us know about your code and we'll review/merge it into the master.
250
303
  7. And pat yourself on the back for contributing to an open source project!!
251
304
 
252
- == Copyright (MIT-LICENSE)
305
+ == Copyright (LICENSE)
306
+
307
+ BookShop is available under *either* the terms of the modified BSD license *or* the
308
+ MIT License (2008). As a recipient of BookShop, you may choose which
309
+ license to receive this code under (except as noted in per-module LICENSE
310
+ files). Some modules may not be the copyright of BlueHead Publishing. These
311
+ modules contain explicit declarations of copyright in both the LICENSE files in
312
+ the directories in which they reside and in the code itself. No external
313
+ contributions are allowed under licenses which are fundamentally incompatible
314
+ with the MIT or BSD licenses that BookShop is distributed under.
315
+
316
+ The text of the MIT and BSD licenses is reproduced below.
317
+
318
+ === The "New" BSD License
319
+
320
+ Copyright (c) 2010-2011, BlueHead Publishing
321
+ All rights reserved.
322
+
323
+ Redistribution and use in source and binary forms, with or without
324
+ modification, are permitted provided that the following conditions are met:
325
+
326
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
327
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
328
+ * Neither the name of Bookshop/BlueHead/BlueHead Publishing nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
329
+
330
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
331
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
332
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
333
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
334
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
335
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
336
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
337
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
338
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
339
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
340
+
341
+ === The MIT License
253
342
 
254
- Copyright (C) 2010, 2011 by BlueHead Publishing, Inc (http://blueheadpublishing.com)
343
+ Copyright (c) 2010, 2011 BlueHead Publishing, et. al.,
255
344
 
256
345
  Permission is hereby granted, free of charge, to any person obtaining a copy
257
346
  of this software and associated documentation files (the "Software"), to deal
@@ -273,9 +362,9 @@ THE SOFTWARE.
273
362
 
274
363
  == The Boom Microformat License (as listed in the boom.css)
275
364
 
276
- Sample style sheet for boom!, the book microformat
277
- written by Hakon Wium Lie and Bert Bos, November 2005
278
- You may reuse this style sheet for any purpose without any fees
365
+ Sample style sheet for boom!, the book microformat
366
+ written by Hakon Wium Lie and Bert Bos, November 2005
367
+ You may reuse this style sheet for any purpose without any fees
279
368
 
280
369
  == Thanks
281
370
 
@@ -2,9 +2,13 @@ require 'thor/group'
2
2
  require 'erb'
3
3
  require 'fileutils'
4
4
  require 'yaml'
5
+ require 'PDFKit'
5
6
 
6
7
  require 'bookshop/commands/yaml/book'
7
8
 
9
+ # require 'bookshop/commands/yaml/toc'
10
+ # require 'bookshop/commands/epub/epub_build'
11
+
8
12
  module Bookshop
9
13
  module Commands
10
14
 
@@ -12,6 +16,12 @@ module Bookshop
12
16
  class Build < Thor::Group
13
17
  include Thor::Actions
14
18
 
19
+ BOOK_SOURCE = 'book.html.erb'
20
+
21
+ def initialize
22
+ @book = []
23
+ end
24
+
15
25
  ARGV << '--help' if ARGV.empty?
16
26
 
17
27
  aliases = {
@@ -31,19 +41,23 @@ module Bookshop
31
41
  File.dirname(__FILE__)
32
42
  end
33
43
 
44
+ # Load YAML files
45
+ def self.load_yaml_files
46
+ # Load the book.yml into the Book object
47
+ @book = Book.new(YAML.load_file('config/book.yml'))
48
+ # @toc = Toc.new(YAML.load_file('config/toc.yml'))
49
+ end
50
+
34
51
  # Renders <%= import(source.html.erb) %> files with ERB
35
52
  #
36
53
  # When a new import() is encountered within source files it is
37
54
  # processed with this method and the result is added to 'erb'
38
55
  def self.import(file)
39
-
40
- # Load the book.yml into the Book object
41
- book = Book.new(YAML.load_file('config/book.yml'))
42
-
56
+ load_yaml_files
43
57
  # Parse the source erb file
44
58
  ERB.new(File.read('book/'+file)).result(binding).gsub(/\n$/,'')
45
59
  end
46
-
60
+
47
61
  case build
48
62
 
49
63
  # 'build html' generates a html version of the book from the
@@ -56,7 +70,7 @@ module Bookshop
56
70
  FileUtils.rm_r Dir.glob('builds/html/*')
57
71
 
58
72
  @output = :html
59
- erb = import('book.html.erb')
73
+ erb = import(BOOK_SOURCE)
60
74
  puts "Generating new html from erb"
61
75
  File.open("builds/html/book.html", 'a') do |f|
62
76
  f << erb
@@ -68,13 +82,14 @@ module Bookshop
68
82
  # 'build pdf' generates a pdf version of the book from the builds/html/book.html
69
83
  # which is generated from the book/book.html.erb source file
70
84
  when 'pdf'
85
+
71
86
  # Clean up any old builds
72
87
  puts "Deleting any old builds"
73
88
  FileUtils.rm_r Dir.glob('builds/pdf/*')
74
89
  FileUtils.rm_r Dir.glob('builds/html/*')
75
90
 
76
91
  @output = :pdf
77
- erb = import('book.html.erb')
92
+ erb = import(BOOK_SOURCE)
78
93
  # Generate the html from ERB
79
94
  puts "Generating new html from erb"
80
95
  File.open('builds/html/book.html', 'a') do |f|
@@ -85,9 +100,20 @@ module Bookshop
85
100
  FileUtils.cp_r('book/css/', 'builds/html/', :verbose => true)
86
101
  FileUtils.cp_r('book/images/', 'builds/html/', :verbose => true)
87
102
 
88
- # Builds the pdf from builds/html/book.html
89
- puts "Building new pdf at builds/pdf/book.pdf from new html build"
90
- cmd = %x[wkhtmltopdf builds/html/book.html builds/pdf/book.pdf]
103
+
104
+ # PDFKit.new takes the HTML and any options for wkhtmltopdf
105
+ # run `wkhtmltopdf --extended-help` for a full list of options
106
+ kit = PDFKit.new(File.new('builds/html/book.html'))
107
+
108
+ # Git an inline PDF
109
+ pdf = kit.to_pdf
110
+
111
+ # Save the PDF to a file
112
+ file = kit.to_file('builds/pdf/book.pdf')
113
+
114
+ #when 'epub'
115
+ # require 'bookshop/commands/epub/epub_build'
116
+ #EpubBuild.new
91
117
 
92
118
  else
93
119
  puts "Error: Command not recognized" unless %w(-h --help).include?(build)
@@ -0,0 +1,67 @@
1
+ require 'thor/group'
2
+ require 'erb'
3
+ require 'yaml'
4
+
5
+
6
+ require 'bookshop/commands/yaml/book'
7
+
8
+ module Bookshop
9
+ module Commands
10
+
11
+ # Builds the EPUB version of the book
12
+ class EpubBuild < Thor::Group
13
+ include Thor::Actions
14
+
15
+ # Define source root of application
16
+ def self.source_root
17
+ File.dirname(__FILE__)
18
+ end
19
+
20
+
21
+
22
+ def clean_up
23
+ puts "Deleting any old builds"
24
+ FileUtils.rm_r Dir.glob('builds/epub/*')
25
+ FileUtils.rm_r Dir.glob('builds/html/*')
26
+ end
27
+
28
+ def compile_erb_source
29
+ @output = :epub
30
+
31
+ erb = import(BOOK_SOURCE)
32
+
33
+ # Generate the html from ERB
34
+ puts "Building new epub at builds/epub/book.epub"
35
+ File.open('builds/epub/OEBPS/book.html', 'a') do |f|
36
+ f << erb
37
+ end
38
+ FileUtils.cp_r('book/css/', 'builds/epub/OEBPS/', :verbose => true)
39
+ FileUtils.cp_r('book/images/', 'builds/epub/OEBPS/', :verbose => true)
40
+ end
41
+
42
+ # Load the book.yml into the Book object
43
+ @book = Book.new(YAML.load_file('config/book.yml'))
44
+ @toc = Toc.new(TAML.load_file('config/table_of_contents.yml'))
45
+
46
+ def create_epub_structure
47
+ directory "templates/epub", "builds/epub"
48
+ end
49
+
50
+ def generate_content_opf_file
51
+ template "templates/content.opf.tt" "builds/epub/OEBPS"
52
+ end
53
+
54
+ def generate_toc
55
+ template "templates/toc.ncs.tt" "builds/epub/OEBPS"
56
+ end
57
+
58
+ def zip_epub
59
+ # zip the contents into book.epub
60
+ end
61
+
62
+ def validate_epub
63
+ # cmd = %x[tools/epubcheck book_#{Time.now.strftime('%m-%e-%y').epub]
64
+ end
65
+ end
66
+ end
67
+ end