bookshop 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.rdoc +24 -2
  2. data/lib/bookshop/commands/build.rb +53 -1
  3. data/lib/bookshop/generators/bookshop/app/templates/README.rdoc +24 -2
  4. data/lib/bookshop/generators/bookshop/app/templates/book/assets/css/stylesheet.epub.css +17 -9
  5. data/lib/bookshop/generators/bookshop/app/templates/book/assets/css/stylesheet.html.css +16 -8
  6. data/lib/bookshop/generators/bookshop/app/templates/book/assets/css/stylesheet.mobi.css +17 -9
  7. data/lib/bookshop/generators/bookshop/app/templates/book/assets/css/stylesheet.pdf.css +16 -8
  8. data/lib/bookshop/generators/bookshop/app/templates/book/assets/images/cover.png +0 -0
  9. data/lib/bookshop/generators/bookshop/app/templates/book/backmatter/index.html.erb +2 -2
  10. data/lib/bookshop/generators/bookshop/app/templates/book/bodymatter/ch02/ch02.html.erb +1 -1
  11. data/lib/bookshop/generators/bookshop/app/templates/book/book.html.erb +11 -4
  12. data/lib/bookshop/{commands/epub/templates → generators/bookshop/app/templates/book/epub}/META-INF/container.xml +0 -0
  13. data/lib/bookshop/generators/bookshop/app/templates/book/epub/OEBPS/content.opf.erb +41 -0
  14. data/lib/bookshop/generators/bookshop/app/templates/book/epub/OEBPS/toc.ncx.erb +57 -0
  15. data/lib/bookshop/{commands/epub/templates → generators/bookshop/app/templates/book/epub}/mimetype +0 -0
  16. data/lib/bookshop/generators/bookshop/app/templates/book/frontmatter/cover.html.erb +26 -7
  17. data/lib/bookshop/generators/bookshop/app/templates/book/frontmatter/preface.html.erb +2 -2
  18. data/lib/bookshop/generators/bookshop/app/templates/book/frontmatter/title.html.erb +8 -6
  19. data/lib/bookshop/generators/bookshop/app/templates/book/frontmatter/toc.html.erb +58 -21
  20. data/lib/bookshop/generators/bookshop/app/templates/config/book.yml +18 -7
  21. data/lib/bookshop/version.rb +1 -1
  22. metadata +21 -27
  23. data/lib/bookshop/commands/epub/epub_build.rb +0 -91
  24. data/lib/bookshop/commands/epub/templates/OEBPS/.empty_directory +0 -0
  25. data/lib/bookshop/commands/epub/templates/OEBPS/content.opf.tt +0 -106
  26. data/lib/bookshop/commands/epub/templates/OEBPS/toc.opf.tt +0 -107
  27. data/lib/bookshop/commands/yaml/toc.rb +0 -46
  28. data/lib/bookshop/generators/bookshop/app/templates/builds/epub/META-INF/.empty_directory +0 -0
  29. data/lib/bookshop/generators/bookshop/app/templates/builds/epub/META-INF/container.xml +0 -6
  30. data/lib/bookshop/generators/bookshop/app/templates/builds/epub/OEBPS/.empty_directory +0 -0
  31. data/lib/bookshop/generators/bookshop/app/templates/builds/epub/mimetype +0 -1
data/README.rdoc CHANGED
@@ -191,11 +191,15 @@ Please explore other creative ways to structure and enhance your book (we'd love
191
191
 
192
192
  To build an HTML format of your book from the ERB source:
193
193
 
194
- $ bookshop build html # -> find the output in builds/html/book_(date).html
194
+ $ bookshop build html # -> find the output in builds/html/book.html
195
195
 
196
196
  To build a pdf format of your book from the ERB source:
197
197
 
198
- $ bookshop build pdf # -> find the output in builds/pdf/book_(date).pdf
198
+ $ bookshop build pdf # -> find the output in builds/pdf/book.pdf
199
+
200
+ To build an epub format of your book from the ERB source:
201
+
202
+ $ bookshop build epub # -> find the output in builds/epub/book.pdf
199
203
 
200
204
  ==== Editing your pdf document options
201
205
 
@@ -203,6 +207,24 @@ We recommend consulting PrinceXML's documentation concerning PDF options.
203
207
 
204
208
  http://www.princexml.com/doc/8.0/
205
209
 
210
+ ==== Editing you epub document and options
211
+
212
+ http://idpf.org/epub/30 - For an overview of EPUB
213
+ http://idpf.org/epub/30/spec/epub30-ocf.html - For the specs on the epub file structures and contents
214
+
215
+
216
+ We recommend consulting the EPUB documentation for specifics.
217
+
218
+ There are two main files (besides your actual book source) you will need to edit for the epub build are located in the +book/epub/OEBPS+ folder: content.opf (the Open Packaging Format) and the toc.ncx (the Navigation file).
219
+
220
+ ===== The *content.opf* file is the file which contains all of the primary information about your epub ebook (publisher, files included, date, etc.).
221
+
222
+ http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm - Specs on the .opf file
223
+
224
+ ===== The toc.ncx file is the file which contains the structural tree of your book's navigation.
225
+
226
+ http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.4.1.2 - Specs on the .ncx file.
227
+
206
228
  == Example Book
207
229
 
208
230
  We've provided an example book for you already in the +book/+ folder. You can use this as an example of how to structure your book and to use ERB, Book Variables, and Output Variables.
@@ -4,7 +4,6 @@ require 'fileutils'
4
4
  require 'yaml'
5
5
 
6
6
  require 'bookshop/commands/yaml/book'
7
- # require 'bookshop/commands/epub/epub_build'
8
7
 
9
8
  module Bookshop
10
9
  module Commands
@@ -75,6 +74,59 @@ module Bookshop
75
74
 
76
75
  FileUtils.cp_r('book/assets/', 'builds/html/', :verbose => true)
77
76
 
77
+ when 'epub'
78
+ # Clean up any old builds
79
+ puts "Deleting any old builds"
80
+ FileUtils.rm_r Dir.glob('builds/epub/*')
81
+
82
+ @output = :epub
83
+
84
+ FileUtils.cp_r('book/epub/META-INF', 'builds/epub/', :verbose => true)
85
+ FileUtils.mkdir 'builds/epub/OEBPS'
86
+ FileUtils.cp_r('book/epub/mimetype', 'builds/epub/', :verbose => true)
87
+
88
+ erb = import(BOOK_SOURCE)
89
+ puts "Generating new html from erb"
90
+ File.open("builds/epub/OEBPS/book.html", 'a') do |f|
91
+ f << erb
92
+ end
93
+
94
+ # Generate the cover.html file
95
+ opf = import("frontmatter/cover.html.erb")
96
+ puts "Generating new cover.html from erb"
97
+ File.open("builds/epub/OEBPS/cover.html", 'a') do |f|
98
+ f << opf
99
+ end
100
+
101
+ # Generate the nav.html file
102
+ opf = import("frontmatter/toc.html.erb")
103
+ puts "Generating new toc.html from erb"
104
+ File.open("builds/epub/OEBPS/toc.html", 'a') do |f|
105
+ f << opf
106
+ end
107
+
108
+ # Generate the OPF file
109
+ opf = import("epub/OEBPS/content.opf.erb")
110
+ puts "Generating new content.opf from erb"
111
+ File.open("builds/epub/OEBPS/content.opf", 'a') do |f|
112
+ f << opf
113
+ end
114
+
115
+ # Generate the NCX file
116
+ ncx = import("epub/OEBPS/toc.ncx.erb")
117
+ puts "Generating new toc.ncx from erb"
118
+ File.open("builds/epub/OEBPS/toc.ncx", 'a') do |f|
119
+ f << ncx
120
+ end
121
+
122
+ FileUtils.cp_r 'book/assets', 'builds/epub/OEBPS/assets/', :verbose => true
123
+ FileUtils.rm %w( builds/epub/OEBPS/assets/css/stylesheet.pdf.css
124
+ builds/epub/OEBPS/assets/css/stylesheet.html.css
125
+ builds/epub/OEBPS/assets/css/stylesheet.mobi.css )
126
+
127
+ puts "Zipping up into epub"
128
+ cmd = %x[cd builds/epub/ && zip -X0 "book.epub" mimetype && zip -rDX9 "book.epub" * -x "*.DS_Store" -x mimetype]
129
+
78
130
  # 'build pdf' generates a pdf version of the book from the builds/html/book.html
79
131
  # which is generated from the book/book.html.erb source file
80
132
  when 'pdf'
@@ -191,11 +191,15 @@ Please explore other creative ways to structure and enhance your book (we'd love
191
191
 
192
192
  To build an HTML format of your book from the ERB source:
193
193
 
194
- $ bookshop build html # -> find the output in builds/html/book_(date).html
194
+ $ bookshop build html # -> find the output in builds/html/book.html
195
195
 
196
196
  To build a pdf format of your book from the ERB source:
197
197
 
198
- $ bookshop build pdf # -> find the output in builds/pdf/book_(date).pdf
198
+ $ bookshop build pdf # -> find the output in builds/pdf/book.pdf
199
+
200
+ To build an epub format of your book from the ERB source:
201
+
202
+ $ bookshop build epub # -> find the output in builds/epub/book.pdf
199
203
 
200
204
  ==== Editing your pdf document options
201
205
 
@@ -203,6 +207,24 @@ We recommend consulting PrinceXML's documentation concerning PDF options.
203
207
 
204
208
  http://www.princexml.com/doc/8.0/
205
209
 
210
+ ==== Editing you epub document and options
211
+
212
+ http://idpf.org/epub/30 - For an overview of EPUB
213
+ http://idpf.org/epub/30/spec/epub30-ocf.html - For the specs on the epub file structures and contents
214
+
215
+
216
+ We recommend consulting the EPUB documentation for specifics.
217
+
218
+ There are two main files (besides your actual book source) you will need to edit for the epub build are located in the +book/epub/OEBPS+ folder: content.opf (the Open Packaging Format) and the toc.ncx (the Navigation file).
219
+
220
+ ===== The *content.opf* file is the file which contains all of the primary information about your epub ebook (publisher, files included, date, etc.).
221
+
222
+ http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm - Specs on the .opf file
223
+
224
+ ===== The toc.ncx file is the file which contains the structural tree of your book's navigation.
225
+
226
+ http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.4.1.2 - Specs on the .ncx file.
227
+
206
228
  == Example Book
207
229
 
208
230
  We've provided an example book for you already in the +book/+ folder. You can use this as an example of how to structure your book and to use ERB, Book Variables, and Output Variables.
@@ -364,34 +364,42 @@ div.titlepage p, div.halftitlepage p {
364
364
  margin: 0; padding: 0;
365
365
  }
366
366
 
367
+ /* imprint */
368
+ div.imprint p {
369
+ text-indent: 0;
370
+ margin-bottom: 1em;
371
+ }
372
+ div.imprint img {
373
+ width: 200px; height: 157px;
374
+ }
367
375
 
368
376
  /* TOC */
369
377
 
370
- ul.toc, ul.toc ul {
378
+ ol.toc, ol.toc ol {
371
379
  list-style-type: none;
372
380
  margin: 0; padding: 0;
373
381
  }
374
- ul.toc ul {
382
+ ol.toc ol {
375
383
  margin-left: 1em;
376
384
  font-weight: normal;
377
385
  }
378
- ul.toc > li {
386
+ ol.toc > li {
379
387
  font-weight: bold;
380
388
  margin-bottom: 0.5em;
381
389
  }
382
- ul.toc a::after {
390
+ ol.toc a::after {
383
391
  content: leader('.') target-counter(attr(href), page);
384
392
  font-style: normal;
385
393
  }
386
- ul.toc > li.frontmatter a::after {
394
+ ol.toc > li.frontmatter a::after {
387
395
  content: leader('.') target-counter(attr(href), page, lower-roman);
388
396
  font-style: normal;
389
397
  }
390
- ul.toc > li.endmatter a::after {
398
+ ol.toc > li.backmatter a::after {
391
399
  content: leader('.') target-counter(attr(href), page);
392
400
  font-style: normal;
393
401
  }
394
- ul.toc > li.chapter::before {
402
+ ol.toc > li.chapter::before {
395
403
  content: "Chapter " counter(toc-chapter, decimal);
396
404
  display: block;
397
405
  margin: 1em 0 0.1em -2.5cm;
@@ -422,7 +430,7 @@ div.chapter h1 { string-set: header "Chapter " counter(chapter) ": " content();
422
430
 
423
431
  /* index */
424
432
 
425
- ul.index {
433
+ ol.index {
426
434
  list-style-type: none;
427
435
  margin: 0; padding: 0;
428
436
  column-count: 2;
@@ -446,6 +454,6 @@ code, span.css, span.value, span.declaration {
446
454
  @media screen, handheld {
447
455
  html { margin: 1em; font: 14px "Gill Sans", sans-serif; }
448
456
  h1 { margin-bottom: 0.5em }
449
- div.frontcover, div.halftitlepage, div.titlepage, div.imprint,
457
+ div.frontcover, div.halftitlepage,
450
458
  div.dedication, div.foreword, div.toc, div.index { display: none }
451
459
  }
@@ -364,34 +364,42 @@ div.titlepage p, div.halftitlepage p {
364
364
  margin: 0; padding: 0;
365
365
  }
366
366
 
367
+ /* imprint */
368
+ div.imprint p {
369
+ text-indent: 0;
370
+ margin-bottom: 1em;
371
+ }
372
+ div.imprint img {
373
+ width: 200px; height: 157px;
374
+ }
367
375
 
368
376
  /* TOC */
369
377
 
370
- ul.toc, ul.toc ul {
378
+ ol.toc, ol.toc ol {
371
379
  list-style-type: none;
372
380
  margin: 0; padding: 0;
373
381
  }
374
- ul.toc ul {
382
+ ol.toc ol {
375
383
  margin-left: 1em;
376
384
  font-weight: normal;
377
385
  }
378
- ul.toc > li {
386
+ ol.toc > li {
379
387
  font-weight: bold;
380
388
  margin-bottom: 0.5em;
381
389
  }
382
- ul.toc a::after {
390
+ ol.toc a::after {
383
391
  content: leader('.') target-counter(attr(href), page);
384
392
  font-style: normal;
385
393
  }
386
- ul.toc > li.frontmatter a::after {
394
+ ol.toc > li.frontmatter a::after {
387
395
  content: leader('.') target-counter(attr(href), page, lower-roman);
388
396
  font-style: normal;
389
397
  }
390
- ul.toc > li.endmatter a::after {
398
+ ol.toc > li.backmatter a::after {
391
399
  content: leader('.') target-counter(attr(href), page);
392
400
  font-style: normal;
393
401
  }
394
- ul.toc > li.chapter::before {
402
+ ol.toc > li.chapter::before {
395
403
  content: "Chapter " counter(toc-chapter, decimal);
396
404
  display: block;
397
405
  margin: 1em 0 0.1em -2.5cm;
@@ -422,7 +430,7 @@ div.chapter h1 { string-set: header "Chapter " counter(chapter) ": " content();
422
430
 
423
431
  /* index */
424
432
 
425
- ul.index {
433
+ ol.index {
426
434
  list-style-type: none;
427
435
  margin: 0; padding: 0;
428
436
  column-count: 2;
@@ -364,34 +364,42 @@ div.titlepage p, div.halftitlepage p {
364
364
  margin: 0; padding: 0;
365
365
  }
366
366
 
367
+ /* imprint */
368
+ div.imprint p {
369
+ text-indent: 0;
370
+ margin-bottom: 1em;
371
+ }
372
+ div.imprint img {
373
+ width: 200px; height: 157px;
374
+ }
367
375
 
368
376
  /* TOC */
369
377
 
370
- ul.toc, ul.toc ul {
378
+ ol.toc, ol.toc ol {
371
379
  list-style-type: none;
372
380
  margin: 0; padding: 0;
373
381
  }
374
- ul.toc ul {
382
+ ol.toc ol {
375
383
  margin-left: 1em;
376
384
  font-weight: normal;
377
385
  }
378
- ul.toc > li {
386
+ ol.toc > li {
379
387
  font-weight: bold;
380
388
  margin-bottom: 0.5em;
381
389
  }
382
- ul.toc a::after {
390
+ ol.toc a::after {
383
391
  content: leader('.') target-counter(attr(href), page);
384
392
  font-style: normal;
385
393
  }
386
- ul.toc > li.frontmatter a::after {
394
+ ol.toc > li.frontmatter a::after {
387
395
  content: leader('.') target-counter(attr(href), page, lower-roman);
388
396
  font-style: normal;
389
397
  }
390
- ul.toc > li.endmatter a::after {
398
+ ol.toc > li.backmatter a::after {
391
399
  content: leader('.') target-counter(attr(href), page);
392
400
  font-style: normal;
393
401
  }
394
- ul.toc > li.chapter::before {
402
+ ol.toc > li.chapter::before {
395
403
  content: "Chapter " counter(toc-chapter, decimal);
396
404
  display: block;
397
405
  margin: 1em 0 0.1em -2.5cm;
@@ -422,7 +430,7 @@ div.chapter h1 { string-set: header "Chapter " counter(chapter) ": " content();
422
430
 
423
431
  /* index */
424
432
 
425
- ul.index {
433
+ ol.index {
426
434
  list-style-type: none;
427
435
  margin: 0; padding: 0;
428
436
  column-count: 2;
@@ -446,6 +454,6 @@ code, span.css, span.value, span.declaration {
446
454
  @media screen, handheld {
447
455
  html { margin: 1em; font: 14px "Gill Sans", sans-serif; }
448
456
  h1 { margin-bottom: 0.5em }
449
- div.frontcover, div.halftitlepage, div.titlepage, div.imprint,
457
+ div.frontcover, div.halftitlepage,
450
458
  div.dedication, div.foreword, div.toc, div.index { display: none }
451
459
  }
@@ -364,34 +364,42 @@ div.titlepage p, div.halftitlepage p {
364
364
  margin: 0; padding: 0;
365
365
  }
366
366
 
367
+ /* imprint */
368
+ div.imprint p {
369
+ text-indent: 0;
370
+ margin-bottom: 1em;
371
+ }
372
+ div.imprint img {
373
+ width: 200px; height: 157px;
374
+ }
367
375
 
368
376
  /* TOC */
369
377
 
370
- ul.toc, ul.toc ul {
378
+ ol.toc, ol.toc ol {
371
379
  list-style-type: none;
372
380
  margin: 0; padding: 0;
373
381
  }
374
- ul.toc ul {
382
+ ol.toc ol {
375
383
  margin-left: 1em;
376
384
  font-weight: normal;
377
385
  }
378
- ul.toc > li {
386
+ ol.toc > li {
379
387
  font-weight: bold;
380
388
  margin-bottom: 0.5em;
381
389
  }
382
- ul.toc a::after {
390
+ ol.toc a::after {
383
391
  content: leader('.') target-counter(attr(href), page);
384
392
  font-style: normal;
385
393
  }
386
- ul.toc > li.frontmatter a::after {
394
+ ol.toc > li.frontmatter a::after {
387
395
  content: leader('.') target-counter(attr(href), page, lower-roman);
388
396
  font-style: normal;
389
397
  }
390
- ul.toc > li.endmatter a::after {
398
+ ol.toc > li.backmatter a::after {
391
399
  content: leader('.') target-counter(attr(href), page);
392
400
  font-style: normal;
393
401
  }
394
- ul.toc > li.chapter::before {
402
+ ol.toc > li.chapter::before {
395
403
  content: "Chapter " counter(toc-chapter, decimal);
396
404
  display: block;
397
405
  margin: 1em 0 0.1em -2.5cm;
@@ -422,7 +430,7 @@ div.chapter h1 { string-set: header "Chapter " counter(chapter) ": " content();
422
430
 
423
431
  /* index */
424
432
 
425
- ul.index {
433
+ ol.index {
426
434
  list-style-type: none;
427
435
  margin: 0; padding: 0;
428
436
  column-count: 2;
@@ -1,7 +1,7 @@
1
1
  <div class="index" id="index-h-1">
2
2
  <h1>Index</h1>
3
3
 
4
- <ul class="index">
4
+ <ol class="index">
5
5
  <li><a href="#dfn-cern">CERN</a></li>
6
6
  <li><a href="#dfn-internet">Internet</a></li>
7
7
  <li><a href="#dfn-hyperlink">hyperlink</a></li>
@@ -10,6 +10,6 @@
10
10
  <li><a href="#dfn-w3c">W3C</a></li>
11
11
  <li><a href="#dfn-web-server">Web server</a></li>
12
12
  <li><a href="#dfn-w3c">World Wide Web Consortium</a></li>
13
- </ul>
13
+ </ol>
14
14
 
15
15
  </div>
@@ -4,7 +4,7 @@
4
4
  <p class="sidenote">HTML is the most popular document format on the
5
5
  Web, and it is used in most of the examples in this book.</p>
6
6
 
7
- <p>As we explained in <a class="chapref" href="http://people.opera.com/howcome/2005/ala/html-h-1"><q>The Web and HTML,</q></a>
7
+ <p>As we explained in <a class="chapref" href="#html-h-1"><q>The Web and HTML,</q></a>
8
8
  HTML elements enable Web-page designers to
9
9
  mark up a document's structure. The HTML specification lists
10
10
  guidelines on how browsers should display these elements. For example,
@@ -1,18 +1,25 @@
1
- <!--?xml version="1.0" encoding="iso-8859-1"?-->
1
+ <!--?xml version="1.0" encoding="UTF-8"?-->
2
2
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
3
  <html>
4
4
  <head>
5
5
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
6
- <title>how-to bookshop</title>
6
+ <title>Cascading Style Sheets</title>
7
7
  <link rel="stylesheet" type="text/css" href="assets/css/stylesheet.<%= @output %>.css" />
8
8
  <link rel="stylesheet" type="application/vnd.adobe-page-template+xml" href="assets/css/page-template.xpgt"/>
9
9
  </head>
10
10
  <body>
11
11
 
12
12
 
13
- <%= import('frontmatter/cover.html.erb')%>
13
+ <% if @output == (:pdf or :html) %>
14
+ <%= import('frontmatter/cover.html.erb')%>
15
+ <% end %>
16
+
14
17
  <%= import('frontmatter/title.html.erb')%>
15
- <%= import('frontmatter/toc.html.erb')%>
18
+
19
+ <% if @output == (:pdf or :html) %>
20
+ <%= import('frontmatter/toc.html.erb')%>
21
+ <% end %>
22
+
16
23
  <%= import('frontmatter/preface.html.erb')%>
17
24
 
18
25
  <!-- Chapter 01 has additional imports included inside of it -->