bookshop 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +13 -0
- data/README.rdoc +21 -6
- data/lib/bookshop/commands/build.rb +12 -37
- data/lib/bookshop/commands/yaml/book.rb +43 -0
- data/lib/bookshop/generators/bookshop/app/templates/README.rdoc +22 -7
- data/lib/bookshop/generators/bookshop/app/templates/book/book.html.erb +8 -3
- data/lib/bookshop/generators/bookshop/app/templates/config/book.yml +16 -12
- data/lib/bookshop/version.rb +1 -1
- metadata +3 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
0.0.18:
|
2
|
+
Features
|
3
|
+
Added @output variable for use in ERB source files so conditionals can be used to
|
4
|
+
define custom layouts based upon the type of output being built
|
5
|
+
(e.g. html, pdf, etc)
|
6
|
+
|
7
|
+
Abstracted the book-to-yaml class into it's own class under */commands/yaml/book.rb
|
8
|
+
|
9
|
+
Documentation
|
10
|
+
Edited the example book to demonstrate use of "output" conditionals in ERB source
|
11
|
+
files.
|
12
|
+
Added documentation in README's to show use of "output" conditionals in ERB source
|
13
|
+
|
1
14
|
0.0.17:
|
2
15
|
Features
|
3
16
|
Added config/book.yml, providing a data structure for elements accessible within the
|
data/README.rdoc
CHANGED
@@ -73,6 +73,21 @@ All of the source documents and assets for your book are stored in the +book/+ f
|
|
73
73
|
|
74
74
|
<%= import(your_source_file.html.erb) %>
|
75
75
|
|
76
|
+
* specify content only for certain build outputs (e.g. html, pdf, epub, etc.)
|
77
|
+
|
78
|
+
# to generate titles that change depending on the build
|
79
|
+
|
80
|
+
<p>Title:
|
81
|
+
<% if @output == :html %>
|
82
|
+
<%= book.html.title %>
|
83
|
+
<% elsif @output == :pdf %>
|
84
|
+
<%= book.pdf.title %>
|
85
|
+
<% end %>
|
86
|
+
</p>
|
87
|
+
|
88
|
+
# did you notice the book.html.title? Look below at the book.yml for explanation
|
89
|
+
|
90
|
+
|
76
91
|
* explore other creative ways to structure and enhance your book (we'd love to see how you are doing it)
|
77
92
|
|
78
93
|
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
|
@@ -107,9 +122,13 @@ http://en.wikipedia.org/wiki/YAML
|
|
107
122
|
|
108
123
|
=== Building Your First Book
|
109
124
|
|
110
|
-
To build a pdf format of your book from the
|
125
|
+
To build a pdf format of your book from the ERB source:
|
126
|
+
|
127
|
+
$ bookshop build pdf # -> find the output in builds/pdf/book_(date).pdf
|
111
128
|
|
112
|
-
|
129
|
+
To build an HTML format of your book from the ERB source:
|
130
|
+
|
131
|
+
$ bookshop build html # -> find the output in builds/html/book_(date).html
|
113
132
|
|
114
133
|
== Getting Help
|
115
134
|
|
@@ -127,7 +146,6 @@ The default directory structure of a generated bookshop project:
|
|
127
146
|
pdf
|
128
147
|
|
129
148
|
|-- config
|
130
|
-
|-- tools
|
131
149
|
|
132
150
|
book
|
133
151
|
Holds all the manuscript html code/files. This is where your master manuscript lives from which everything is built.
|
@@ -146,9 +164,6 @@ build/pdf
|
|
146
164
|
|
147
165
|
config
|
148
166
|
application-wide variables and configurations will go here
|
149
|
-
|
150
|
-
tools
|
151
|
-
Holds all third-party tools: epubcheck, kindlegen
|
152
167
|
|
153
168
|
== Get Involved
|
154
169
|
1. Fork the repository.
|
@@ -3,43 +3,11 @@ require 'erb'
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
+
require 'bookshop/commands/yaml/book'
|
7
|
+
|
6
8
|
module Bookshop
|
7
9
|
module Commands
|
8
|
-
|
9
|
-
class Book
|
10
|
-
|
11
|
-
def initialize(data={})
|
12
|
-
@data = {}
|
13
|
-
update!(data)
|
14
|
-
end
|
15
|
-
|
16
|
-
def update!(data)
|
17
|
-
data.each do |key, value|
|
18
|
-
self[key] = value
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def [](key)
|
23
|
-
@data[key.to_sym]
|
24
|
-
end
|
25
|
-
|
26
|
-
def []=(key, value)
|
27
|
-
if value.class == Hash
|
28
|
-
@data[key.to_sym] = Book.new(value)
|
29
|
-
else
|
30
|
-
@data[key.to_sym] = value
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def method_missing(sym, *args)
|
35
|
-
if sym.to_s =~ /(.+)=$/
|
36
|
-
self[$1] = args.first
|
37
|
-
else
|
38
|
-
self[sym]
|
39
|
-
end
|
40
|
-
end
|
41
10
|
|
42
|
-
end
|
43
11
|
# Define build commands for bookshop command line
|
44
12
|
class Build < Thor::Group
|
45
13
|
include Thor::Actions
|
@@ -67,22 +35,27 @@ module Bookshop
|
|
67
35
|
# When a new import() is encountered within source files it is
|
68
36
|
# processed with this method and the result is added to 'erb'
|
69
37
|
def self.import(file)
|
70
|
-
|
38
|
+
|
39
|
+
# Load the book.yml into the Book object
|
71
40
|
book = Book.new(YAML.load_file('config/book.yml'))
|
41
|
+
|
42
|
+
# Parse the source erb file
|
72
43
|
ERB.new(File.read('book/'+file)).result(binding).gsub(/\n$/,'')
|
73
44
|
end
|
74
45
|
|
75
|
-
erb = import('book.html.erb')
|
76
|
-
|
77
46
|
case build
|
78
47
|
|
79
48
|
# 'build html' generates a html version of the book from the
|
80
49
|
# book/book.html.erb source file
|
50
|
+
# @output variable is set to "html" for access as a conditional
|
51
|
+
# in the source erb's
|
81
52
|
when 'html'
|
82
53
|
# Clean up any old builds
|
83
54
|
puts "Deleting any old builds"
|
84
55
|
FileUtils.rm_r Dir.glob('builds/html/*')
|
85
56
|
|
57
|
+
@output = :html
|
58
|
+
erb = import('book.html.erb')
|
86
59
|
puts "Generating new html from erb"
|
87
60
|
File.open("builds/html/book_#{Time.now.strftime('%m-%e-%y')}.html", 'a') do |f|
|
88
61
|
f << erb
|
@@ -99,6 +72,8 @@ module Bookshop
|
|
99
72
|
FileUtils.rm_r Dir.glob('builds/pdf/*')
|
100
73
|
FileUtils.rm_r Dir.glob('builds/html/*')
|
101
74
|
|
75
|
+
@output = :pdf
|
76
|
+
erb = import('book.html.erb')
|
102
77
|
# Generate the html from ERB
|
103
78
|
puts "Generating new html from erb"
|
104
79
|
File.open('builds/html/book.html', 'a') do |f|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Take a YAML data structure and express it in a 'class.method.method' convention so
|
2
|
+
# it can be passed to the build command, used in the source files to call data
|
3
|
+
# from the book.yml file
|
4
|
+
#
|
5
|
+
# # book.yml
|
6
|
+
# foo:
|
7
|
+
# bar: foobar
|
8
|
+
#
|
9
|
+
# is referenced in the source files as <%= book.foo.bar %> and yields in build 'foobar'
|
10
|
+
class Book
|
11
|
+
|
12
|
+
def initialize(data={})
|
13
|
+
@data = {}
|
14
|
+
update!(data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update!(data)
|
18
|
+
data.each do |key, value|
|
19
|
+
self[key] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](key)
|
24
|
+
@data[key.to_sym]
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(key, value)
|
28
|
+
if value.class == Hash
|
29
|
+
@data[key.to_sym] = Book.new(value)
|
30
|
+
else
|
31
|
+
@data[key.to_sym] = value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def method_missing(sym, *args)
|
36
|
+
if sym.to_s =~ /(.+)=$/
|
37
|
+
self[$1] = args.first
|
38
|
+
else
|
39
|
+
self[sym]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -4,7 +4,7 @@ bookShop is a publishing framework for html-to-pdf/(e)book toolchain happiness a
|
|
4
4
|
|
5
5
|
bookshop hopes to simplify the process by:
|
6
6
|
* using common developer 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'
|
7
|
+
* providing a Ruby Gem to make building a pdf or (e)book from HTML as easy as 'gem install bookshop'
|
8
8
|
* pulling all the html-to-(e)book tools together into one place (wkhtmltopdf, kindlegen, epubcheck)
|
9
9
|
* sticking with open-source tools
|
10
10
|
* giving the developer a set of scripts to automate the redundant stuff
|
@@ -73,6 +73,21 @@ All of the source documents and assets for your book are stored in the +book/+ f
|
|
73
73
|
|
74
74
|
<%= import(your_source_file.html.erb) %>
|
75
75
|
|
76
|
+
* specify content only for certain build outputs (e.g. html, pdf, epub, etc.)
|
77
|
+
|
78
|
+
# to generate titles that change depending on the build
|
79
|
+
|
80
|
+
<p>Title:
|
81
|
+
<% if @output == :html %>
|
82
|
+
<%= book.html.title %>
|
83
|
+
<% elsif @output == :pdf %>
|
84
|
+
<%= book.pdf.title %>
|
85
|
+
<% end %>
|
86
|
+
</p>
|
87
|
+
|
88
|
+
# did you notice the book.html.title? Look below at the book.yml for explanation
|
89
|
+
|
90
|
+
|
76
91
|
* explore other creative ways to structure and enhance your book (we'd love to see how you are doing it)
|
77
92
|
|
78
93
|
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
|
@@ -107,9 +122,13 @@ http://en.wikipedia.org/wiki/YAML
|
|
107
122
|
|
108
123
|
=== Building Your First Book
|
109
124
|
|
110
|
-
To build a pdf format of your book from the
|
125
|
+
To build a pdf format of your book from the ERB source:
|
126
|
+
|
127
|
+
$ bookshop build pdf # -> find the output in builds/pdf/book_(date).pdf
|
111
128
|
|
112
|
-
|
129
|
+
To build an HTML format of your book from the ERB source:
|
130
|
+
|
131
|
+
$ bookshop build html # -> find the output in builds/html/book_(date).html
|
113
132
|
|
114
133
|
== Getting Help
|
115
134
|
|
@@ -127,7 +146,6 @@ The default directory structure of a generated bookshop project:
|
|
127
146
|
pdf
|
128
147
|
|
129
148
|
|-- config
|
130
|
-
|-- tools
|
131
149
|
|
132
150
|
book
|
133
151
|
Holds all the manuscript html code/files. This is where your master manuscript lives from which everything is built.
|
@@ -146,9 +164,6 @@ build/pdf
|
|
146
164
|
|
147
165
|
config
|
148
166
|
application-wide variables and configurations will go here
|
149
|
-
|
150
|
-
tools
|
151
|
-
Holds all third-party tools: epubcheck, kindlegen
|
152
167
|
|
153
168
|
== Get Involved
|
154
169
|
1. Fork the repository.
|
@@ -6,7 +6,12 @@
|
|
6
6
|
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
|
7
7
|
</head>
|
8
8
|
<body>
|
9
|
-
<p>Title:
|
9
|
+
<p>Title:
|
10
|
+
<% if @output == :html %>
|
11
|
+
<%= book.html.title %>
|
12
|
+
<% elsif @output == :pdf %>
|
13
|
+
<%= book.pdf.title %>
|
14
|
+
<% end %></p>
|
10
15
|
<p>Subtitle: <%= book.subtitle %></p>
|
11
16
|
<p>ISBN: <%= book.isbn %></p>
|
12
17
|
|
@@ -15,10 +20,10 @@
|
|
15
20
|
<%= import('toc.html.erb')%>
|
16
21
|
<%= import('preface.html.erb')%>
|
17
22
|
|
18
|
-
<!-- Chapter 01 has
|
23
|
+
<!-- Chapter 01 has additional imports included inside of it -->
|
19
24
|
<%= import('ch01/ch01.html.erb')%>
|
20
25
|
|
21
|
-
<!-- Chapter 01 has
|
26
|
+
<!-- Chapter 01 has additional imports included inside of it -->
|
22
27
|
<%= import('ch02/ch02.html.erb')%>
|
23
28
|
|
24
29
|
</body></html>
|
@@ -2,37 +2,41 @@
|
|
2
2
|
#
|
3
3
|
# in book/book.html.erb
|
4
4
|
#
|
5
|
-
# <p><b>Version:</b> <%= book.version %></p>
|
5
|
+
# <p><b>Version:</b> <%= book.epub.version %></p>
|
6
6
|
#
|
7
7
|
# or
|
8
8
|
#
|
9
|
-
# <% if book.epub.version
|
9
|
+
# <% if book.epub.version == '1.0.0' %>
|
10
10
|
# <p>Whew! We made it!</p>
|
11
11
|
# <% end %>
|
12
12
|
|
13
|
-
version: 0.0.1
|
14
13
|
title: Bookshop
|
15
14
|
subtitle: An HTML-to-PDF/(e)Book Publishing Framework
|
16
15
|
isbn: 1234567891011 # ISBN-13
|
17
16
|
|
18
17
|
|
19
|
-
|
20
|
-
# Place the epub specific settings here. Use whatever you want.
|
18
|
+
# Place the pdf specific settings here. Use whatever you want.
|
21
19
|
# You can use these settings in your source layouts by using a tag
|
22
|
-
# in book.html.erb you could use <%= book.
|
23
|
-
|
24
|
-
|
20
|
+
# in book.html.erb you could use <%= book.pdf.title %>
|
21
|
+
pdf:
|
22
|
+
version: 0.0.1
|
23
|
+
title: Bookshop (PDF Version)
|
25
24
|
|
26
25
|
|
26
|
+
# Place the epub specific settings here.
|
27
|
+
epub:
|
28
|
+
version: 0.0.1
|
29
|
+
title: Bookshop (eBook)
|
30
|
+
|
27
31
|
|
28
|
-
# Place the
|
32
|
+
# Place the html specific settings here
|
29
33
|
html:
|
30
|
-
title: Bookshop (
|
34
|
+
title: Bookshop (HTML version)
|
31
35
|
|
32
36
|
|
33
|
-
# You can add any additional variables
|
37
|
+
# You can add any additional variables you want
|
34
38
|
#
|
35
39
|
# foo:
|
36
40
|
# bar: foobar
|
37
41
|
#
|
38
|
-
# in book.html.erb you
|
42
|
+
# in book.html.erb you can then use <%= foo.bar %> # --> foobar
|
data/lib/bookshop/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bookshop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.18
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- D.a. Thompson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-12-
|
13
|
+
date: 2011-12-14 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/bookshop/commands.rb
|
72
72
|
- lib/bookshop/commands/application.rb
|
73
73
|
- lib/bookshop/commands/build.rb
|
74
|
+
- lib/bookshop/commands/yaml/book.rb
|
74
75
|
- lib/bookshop/generators/bookshop/app/USAGE
|
75
76
|
- lib/bookshop/generators/bookshop/app/app_generator.rb
|
76
77
|
- lib/bookshop/generators/bookshop/app/templates/CHANGELOG
|