bookshop 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.rdoc +28 -2
- data/lib/bookshop/commands/build.rb +53 -9
- data/lib/bookshop/generators/bookshop/app/templates/README.rdoc +28 -2
- data/lib/bookshop/generators/bookshop/app/templates/book/book.html.erb +4 -0
- data/lib/bookshop/generators/bookshop/app/templates/config/book.yml +38 -0
- data/lib/bookshop/generators/bookshop/app/templates/script/bookshop +0 -2
- data/lib/bookshop/version.rb +1 -1
- metadata +3 -9
- data/lib/bookshop/generators/bookshop/app/templates/config/application.rb +0 -46
- data/lib/bookshop/generators/bookshop/app/templates/config/boot.rb +0 -13
- data/lib/bookshop/generators/bookshop/generator/USAGE +0 -12
- data/lib/bookshop/generators/bookshop/generator/generator_generator.rb +0 -26
- data/lib/bookshop/generators/bookshop/generator/templates/%file_name%_generator.rb.tt +0 -3
- data/lib/bookshop/generators/bookshop/generator/templates/USAGE.tt +0 -8
- data/lib/bookshop/generators/bookshop/generator/templates/templates/.empty_directory +0 -0
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
0.0.17:
|
2
|
+
Features
|
3
|
+
Added config/book.yml, providing a data structure for elements accessible within the
|
4
|
+
book/ source files.
|
5
|
+
|
6
|
+
Added 'current date' to the end of the generated filename of builds.
|
7
|
+
|
8
|
+
Clean-up
|
9
|
+
Removed Template Generator for now, this has become part of the 0.2.0 milestone
|
10
|
+
|
1
11
|
0.0.16:
|
2
12
|
Features
|
3
13
|
Added importing <%= import(your_source_file.html.erb) %> functionality for ERB source
|
data/README.rdoc
CHANGED
@@ -53,7 +53,7 @@ bookshop hopes to simplify the process by:
|
|
53
53
|
|
54
54
|
=== Editing Your New Book
|
55
55
|
|
56
|
-
All of the source documents
|
56
|
+
All of the source documents and assets for your book are stored in the +book/+ folder. The source files are all in ERB. The master file, from which everything is built is +book/book.html.erb+. Since this is an ERB file, you can do all kinds of things like:
|
57
57
|
|
58
58
|
* embed ruby functions and calls
|
59
59
|
|
@@ -71,14 +71,40 @@ All of the source documents/code/assets (yay... HTML/CSS) for your book are stor
|
|
71
71
|
|
72
72
|
* include other files or template structures
|
73
73
|
|
74
|
-
<%= import(your_source_file.erb
|
74
|
+
<%= import(your_source_file.html.erb) %>
|
75
75
|
|
76
76
|
* explore other creative ways to structure and enhance your book (we'd love to see how you are doing it)
|
77
77
|
|
78
|
+
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
|
79
|
+
|
78
80
|
When the book is built, your master +book/book.html.erb+ file will be compiled into the final HTML which will be used to build the book types.
|
79
81
|
|
80
82
|
When you are finished editing your source you can build whichever type of your book that you would like. Currently the only supported builds are pdf and html (and soon epub and mobi).
|
81
83
|
|
84
|
+
=== The book.yml file (config/book.yml)
|
85
|
+
|
86
|
+
We've provided a data structure for your book (in YAML) so you can store pieces of data or variables that you can call within your source files.
|
87
|
+
|
88
|
+
# book.yml
|
89
|
+
|
90
|
+
title: A Book Title
|
91
|
+
subtitle: A Book Subtitle
|
92
|
+
|
93
|
+
epub:
|
94
|
+
title: A EPUB Title
|
95
|
+
|
96
|
+
In your book source file:
|
97
|
+
|
98
|
+
# book/book.html.erb
|
99
|
+
|
100
|
+
<p>The book title is <%= book.title %></p>
|
101
|
+
<p>The book subtitle is <%= book.subtitle %></p>
|
102
|
+
<p>The epub title is <%= book.epub.title %></p>
|
103
|
+
|
104
|
+
More info about YAML:
|
105
|
+
|
106
|
+
http://en.wikipedia.org/wiki/YAML
|
107
|
+
|
82
108
|
=== Building Your First Book
|
83
109
|
|
84
110
|
To build a pdf format of your book from the html source:
|
@@ -1,9 +1,45 @@
|
|
1
1
|
require 'thor/group'
|
2
2
|
require 'erb'
|
3
3
|
require 'fileutils'
|
4
|
+
require 'yaml'
|
4
5
|
|
5
6
|
module Bookshop
|
6
7
|
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
|
+
|
42
|
+
end
|
7
43
|
# Define build commands for bookshop command line
|
8
44
|
class Build < Thor::Group
|
9
45
|
include Thor::Actions
|
@@ -17,10 +53,6 @@ module Bookshop
|
|
17
53
|
build = ARGV.shift
|
18
54
|
build = aliases[build] || build
|
19
55
|
|
20
|
-
# Renders <%= import(source.html.erb) %> files with ERB
|
21
|
-
def self.import(file)
|
22
|
-
ERB.new(File.read('book/'+file)).result(binding).gsub(/\n$/,'')
|
23
|
-
end
|
24
56
|
|
25
57
|
# Define arguments and options
|
26
58
|
argument :type
|
@@ -29,26 +61,38 @@ module Bookshop
|
|
29
61
|
def self.source_root
|
30
62
|
File.dirname(__FILE__)
|
31
63
|
end
|
64
|
+
|
65
|
+
# Renders <%= import(source.html.erb) %> files with ERB
|
66
|
+
#
|
67
|
+
# When a new import() is encountered within source files it is
|
68
|
+
# processed with this method and the result is added to 'erb'
|
69
|
+
def self.import(file)
|
70
|
+
# Load book settings into the book object
|
71
|
+
book = Book.new(YAML.load_file('config/book.yml'))
|
72
|
+
ERB.new(File.read('book/'+file)).result(binding).gsub(/\n$/,'')
|
73
|
+
end
|
32
74
|
|
33
75
|
erb = import('book.html.erb')
|
34
76
|
|
35
77
|
case build
|
36
78
|
|
37
|
-
# 'build html'
|
79
|
+
# 'build html' generates a html version of the book from the
|
80
|
+
# book/book.html.erb source file
|
38
81
|
when 'html'
|
39
82
|
# Clean up any old builds
|
40
83
|
puts "Deleting any old builds"
|
41
84
|
FileUtils.rm_r Dir.glob('builds/html/*')
|
42
85
|
|
43
86
|
puts "Generating new html from erb"
|
44
|
-
File.open(
|
87
|
+
File.open("builds/html/book_#{Time.now.strftime('%m-%e-%y')}.html", 'a') do |f|
|
45
88
|
f << erb
|
46
89
|
end
|
47
90
|
|
48
91
|
FileUtils.cp_r('book/css/', 'builds/html/', :verbose => true)
|
49
92
|
FileUtils.cp_r('book/images/', 'builds/html/', :verbose => true)
|
50
93
|
|
51
|
-
# 'build pdf'
|
94
|
+
# 'build pdf' generates a pdf version of the book from the builds/html/book.html
|
95
|
+
# which is generated from the book/book.html.erb source file
|
52
96
|
when 'pdf'
|
53
97
|
# Clean up any old builds
|
54
98
|
puts "Deleting any old builds"
|
@@ -65,9 +109,9 @@ module Bookshop
|
|
65
109
|
FileUtils.cp_r('book/css/', 'builds/html/', :verbose => true)
|
66
110
|
FileUtils.cp_r('book/images/', 'builds/html/', :verbose => true)
|
67
111
|
|
68
|
-
#
|
112
|
+
# Builds the pdf from builds/html/book.html
|
69
113
|
puts "Building new pdf at builds/pdf/book.pdf from new html build"
|
70
|
-
cmd = %x[wkhtmltopdf builds/html/book.html builds/pdf/
|
114
|
+
cmd = %x[wkhtmltopdf builds/html/book.html builds/pdf/book_#{Time.now.strftime('%m-%e-%y')}.pdf]
|
71
115
|
|
72
116
|
else
|
73
117
|
puts "Error: Command not recognized" unless %w(-h --help).include?(build)
|
@@ -53,7 +53,7 @@ bookshop hopes to simplify the process by:
|
|
53
53
|
|
54
54
|
=== Editing Your New Book
|
55
55
|
|
56
|
-
All of the source documents
|
56
|
+
All of the source documents and assets for your book are stored in the +book/+ folder. The source files are all in ERB. The master file, from which everything is built is +book/book.html.erb+. Since this is an ERB file, you can do all kinds of things like:
|
57
57
|
|
58
58
|
* embed ruby functions and calls
|
59
59
|
|
@@ -71,14 +71,40 @@ All of the source documents/code/assets (yay... HTML/CSS) for your book are stor
|
|
71
71
|
|
72
72
|
* include other files or template structures
|
73
73
|
|
74
|
-
<%= import(your_source_file.erb
|
74
|
+
<%= import(your_source_file.html.erb) %>
|
75
75
|
|
76
76
|
* explore other creative ways to structure and enhance your book (we'd love to see how you are doing it)
|
77
77
|
|
78
|
+
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/erb/rdoc/ERB.html
|
79
|
+
|
78
80
|
When the book is built, your master +book/book.html.erb+ file will be compiled into the final HTML which will be used to build the book types.
|
79
81
|
|
80
82
|
When you are finished editing your source you can build whichever type of your book that you would like. Currently the only supported builds are pdf and html (and soon epub and mobi).
|
81
83
|
|
84
|
+
=== The book.yml file (config/book.yml)
|
85
|
+
|
86
|
+
We've provided a data structure for your book (in YAML) so you can store pieces of data or variables that you can call within your source files.
|
87
|
+
|
88
|
+
# book.yml
|
89
|
+
|
90
|
+
title: A Book Title
|
91
|
+
subtitle: A Book Subtitle
|
92
|
+
|
93
|
+
epub:
|
94
|
+
title: A EPUB Title
|
95
|
+
|
96
|
+
In your book source file:
|
97
|
+
|
98
|
+
# book/book.html.erb
|
99
|
+
|
100
|
+
<p>The book title is <%= book.title %></p>
|
101
|
+
<p>The book subtitle is <%= book.subtitle %></p>
|
102
|
+
<p>The epub title is <%= book.epub.title %></p>
|
103
|
+
|
104
|
+
More info about YAML:
|
105
|
+
|
106
|
+
http://en.wikipedia.org/wiki/YAML
|
107
|
+
|
82
108
|
=== Building Your First Book
|
83
109
|
|
84
110
|
To build a pdf format of your book from the html source:
|
@@ -6,6 +6,10 @@
|
|
6
6
|
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
|
7
7
|
</head>
|
8
8
|
<body>
|
9
|
+
<p>Title: <%= book.title %></p>
|
10
|
+
<p>Subtitle: <%= book.subtitle %></p>
|
11
|
+
<p>ISBN: <%= book.isbn %></p>
|
12
|
+
|
9
13
|
|
10
14
|
<%= import('cover.html.erb')%>
|
11
15
|
<%= import('toc.html.erb')%>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Settings for the book which can be called within the book source files
|
2
|
+
#
|
3
|
+
# in book/book.html.erb
|
4
|
+
#
|
5
|
+
# <p><b>Version:</b> <%= book.version %></p>
|
6
|
+
#
|
7
|
+
# or
|
8
|
+
#
|
9
|
+
# <% if book.epub.version >= 1.0.0 %>
|
10
|
+
# <p>Whew! We made it!</p>
|
11
|
+
# <% end %>
|
12
|
+
|
13
|
+
version: 0.0.1
|
14
|
+
title: Bookshop
|
15
|
+
subtitle: An HTML-to-PDF/(e)Book Publishing Framework
|
16
|
+
isbn: 1234567891011 # ISBN-13
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
# Place the epub specific settings here. Use whatever you want.
|
21
|
+
# You can use these settings in your source layouts by using a tag
|
22
|
+
# in book.html.erb you could use <%= book.epub.title %>
|
23
|
+
epub:
|
24
|
+
title: Bookshop (the eBook)
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
# Place the epub specific settings here
|
29
|
+
html:
|
30
|
+
title: Bookshop (html version)
|
31
|
+
|
32
|
+
|
33
|
+
# You can add any additional variables
|
34
|
+
#
|
35
|
+
# foo:
|
36
|
+
# bar: foobar
|
37
|
+
#
|
38
|
+
# in book.html.erb you could use <%= foo.bar %> # --> foobar
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# This command will automatically be run when you run "bookshop" with Bookshop gem installed from the root of your application.
|
2
2
|
|
3
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
4
|
-
require File.expand_path('../../config/boot', __FILE__)
|
5
3
|
require 'bookshop/commands'
|
6
4
|
|
7
5
|
|
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.17
|
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-13 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|
@@ -92,14 +92,8 @@ files:
|
|
92
92
|
- lib/bookshop/generators/bookshop/app/templates/builds/html/.empty_directory
|
93
93
|
- lib/bookshop/generators/bookshop/app/templates/builds/mobi/.empty_directory
|
94
94
|
- lib/bookshop/generators/bookshop/app/templates/builds/pdf/.empty_directory
|
95
|
-
- lib/bookshop/generators/bookshop/app/templates/config/
|
96
|
-
- lib/bookshop/generators/bookshop/app/templates/config/boot.rb
|
95
|
+
- lib/bookshop/generators/bookshop/app/templates/config/book.yml
|
97
96
|
- lib/bookshop/generators/bookshop/app/templates/script/bookshop
|
98
|
-
- lib/bookshop/generators/bookshop/generator/USAGE
|
99
|
-
- lib/bookshop/generators/bookshop/generator/generator_generator.rb
|
100
|
-
- lib/bookshop/generators/bookshop/generator/templates/%file_name%_generator.rb.tt
|
101
|
-
- lib/bookshop/generators/bookshop/generator/templates/USAGE.tt
|
102
|
-
- lib/bookshop/generators/bookshop/generator/templates/templates/.empty_directory
|
103
97
|
- lib/bookshop/post_install.rb
|
104
98
|
- lib/bookshop/ruby_version_check.rb
|
105
99
|
- lib/bookshop/script_bookshop_loader.rb
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.expand_path('../boot', __FILE__)
|
2
|
-
|
3
|
-
require 'bookshop'
|
4
|
-
|
5
|
-
# If you have a Gemfile, require the gems listed there, including any gems
|
6
|
-
# you've limited to :test, :development, or :production.
|
7
|
-
Bundler.require(:default, Bookshop.env) if defined?(Bundler)
|
8
|
-
|
9
|
-
module <%= app_const_base %>
|
10
|
-
class Application < Bookshop::Application
|
11
|
-
# Settings in config/environments/* take precedence over those specified here.
|
12
|
-
# Application configuration should go into files in config/initializers
|
13
|
-
# -- all .rb files in that directory are automatically loaded.
|
14
|
-
|
15
|
-
# Custom directories with classes and modules you want to be autoloadable.
|
16
|
-
# config.autoload_paths += %W(#{config.root}/extras)
|
17
|
-
|
18
|
-
# Only load the plugins named here, in the order given (default is alphabetical).
|
19
|
-
# :all can be used as a placeholder for all plugins not explicitly named.
|
20
|
-
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
21
|
-
|
22
|
-
# Activate observers that should always be running.
|
23
|
-
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
24
|
-
|
25
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
26
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
27
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
28
|
-
|
29
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
30
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
31
|
-
# config.i18n.default_locale = :de
|
32
|
-
|
33
|
-
# JavaScript files you want as :defaults (application.js is always included).
|
34
|
-
<% if options[:skip_prototype] -%>
|
35
|
-
config.action_view.javascript_expansions[:defaults] = %w()
|
36
|
-
<% else -%>
|
37
|
-
# config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
38
|
-
<% end -%>
|
39
|
-
|
40
|
-
# Configure the default encoding used in templates for Ruby 1.9.
|
41
|
-
config.encoding = "utf-8"
|
42
|
-
|
43
|
-
# Configure sensitive parameters which will be filtered from the log file.
|
44
|
-
config.filter_parameters += [:password]
|
45
|
-
end
|
46
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
# Set up gems listed in the Gemfile.
|
4
|
-
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
5
|
-
begin
|
6
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
-
require 'bundler'
|
8
|
-
Bundler.setup
|
9
|
-
rescue Bundler::GemNotFound => e
|
10
|
-
STDERR.puts e.message
|
11
|
-
STDERR.puts "Try running `bundle install`."
|
12
|
-
exit!
|
13
|
-
end if File.exist?(gemfile)
|
@@ -1,12 +0,0 @@
|
|
1
|
-
Description:
|
2
|
-
Stubs out a new generator at lib/generators. Pass the generator name as an argument,
|
3
|
-
either CamelCased or snake_cased.
|
4
|
-
|
5
|
-
Example:
|
6
|
-
`bookshop generate generator Awesome`
|
7
|
-
|
8
|
-
creates a standard awesome generator:
|
9
|
-
lib/generators/awesome/
|
10
|
-
lib/generators/awesome/awesome_generator.rb
|
11
|
-
lib/generators/awesome/USAGE
|
12
|
-
lib/generators/awesome/templates/
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Bookshop
|
2
|
-
module Generators
|
3
|
-
#
|
4
|
-
class GeneratorGenerator < NamedBase
|
5
|
-
check_class_collision :suffix => "Generator"
|
6
|
-
|
7
|
-
class_option :namespace, :type => :boolean, :default => true,
|
8
|
-
:desc => "Namespace generator under lib/generators/name"
|
9
|
-
|
10
|
-
def create_generator_files
|
11
|
-
directory '.', generator_dir
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
def generator_dir
|
17
|
-
if options[:namespace]
|
18
|
-
File.join("lib", "generators", file_name)
|
19
|
-
else
|
20
|
-
File.join("lib", "generators")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
File without changes
|