bookery 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -8
- data/.travis.yml +5 -0
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +26 -11
- data/Rakefile +2 -1
- data/bookery.gemspec +18 -14
- data/docs/config.md +61 -0
- data/docs/contributing.md +47 -0
- data/docs/editing.md +82 -0
- data/docs/project.md +77 -0
- data/lib/bookery.rb +27 -4
- data/lib/bookery/book.rb +13 -15
- data/lib/bookery/cli.rb +29 -12
- data/lib/bookery/config.rb +42 -0
- data/lib/bookery/factories/chapter_factory.rb +35 -0
- data/lib/bookery/factories/publisher_factory.rb +13 -0
- data/lib/bookery/processors/include_processor.rb +17 -0
- data/lib/bookery/project.rb +75 -0
- data/lib/bookery/publishers/html_publisher.rb +68 -0
- data/lib/bookery/version.rb +1 -1
- data/{bin → libexec}/bookery +1 -4
- data/templates/basic/Gemfile.tt +2 -0
- data/templates/basic/assets/css/base.css +7 -0
- data/templates/basic/assets/css/layout.css +23 -0
- data/templates/basic/assets/css/modules/code-block.css +132 -0
- data/templates/{book/assets → basic/assets/includes}/.empty_directory +0 -0
- data/templates/basic/assets/style.css +3 -0
- data/templates/basic/assets/templates/template.html.erb +30 -0
- data/templates/basic/book/en/001-first-chapter/01-chapter-file.md +9 -0
- data/templates/basic/config.yml +14 -0
- data/test/bookery/book_test.rb +32 -9
- data/test/bookery/cli_test.rb +25 -14
- data/test/bookery/config_test.rb +26 -0
- data/test/bookery/factories/chapter_factory_test.rb +24 -0
- data/test/bookery/factories/publisher_factory_test.rb +16 -0
- data/test/bookery/processor/include_processor_test.rb +38 -0
- data/test/bookery/project_test.rb +37 -0
- data/test/bookery/publishers/html_publisher_test.rb +78 -0
- data/test/data/project/Gemfile.tt +2 -0
- data/{templates/book/book/.empty_directory → test/data/project/assets/images/cover.png} +0 -0
- data/test/data/project/assets/includes/ruby/chapter2.rb +3 -0
- data/test/data/project/assets/style.css +1 -0
- data/test/data/project/assets/templates/template.html.erb +15 -0
- data/test/data/project/book/en/001-first-chapter/01-chapter-file.md +9 -0
- data/test/data/project/book/en/002-second-chapter/01-chapter-file.md +7 -0
- data/test/data/project/book/en/002-second-chapter/02-second-chapter-file.md +1 -0
- data/{templates/book/book/en/.empty_directory → test/data/project/book/es/.git-keep} +0 -0
- data/test/data/project/config.yml +19 -0
- data/test/test_helper.rb +3 -46
- metadata +107 -79
- data/Gemfile.lock +0 -64
- data/Guardfile +0 -9
- data/lib/bookery/chapter.rb +0 -30
- data/templates/book/Gemfile +0 -2
- data/templates/book/README.md +0 -3
- data/templates/book/config.yml +0 -5
- data/templates/sample/Gemfile +0 -2
- data/templates/sample/README.md +0 -3
- data/templates/sample/book/en/01-introduction/01-intro-to-book.md +0 -0
- data/templates/sample/book/en/02-second-chapter/01-first-things-first.md +0 -1
- data/templates/sample/book/en/02-second-chapter/02-before_intro.md +0 -1
- data/templates/sample/config.yml +0 -5
- data/test/bookery/chapter_test.rb +0 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f97ae9ea2ae24920a2039c25ff8c992f85ed3c8
|
4
|
+
data.tar.gz: c840b5b74a04f51cf2e618129fec5efb542043a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bd2ce35591d8e0afe82cf39792c1649cda9c3d61932a6e0851c89cac4ec7e58ef326791a81d50f54a8f67f9ad7dc81b8db4ca154e3ce94ac921e0c1f62ac9ac
|
7
|
+
data.tar.gz: 1497fedfe9038028789fb1118e58865a8665eb728d1a13e60f999fc1e02af8322694d8195b2d34cdbf236bc4e841b4f7b67261c30d602b5974ad4d315d7df5f0
|
data/.gitignore
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
bin
|
19
|
+
vendor
|
20
|
+
Guardfile
|
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
# Bookery
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/pseudomuto/bookery.png)](https://travis-ci.org/pseudomuto/bookery)
|
4
|
+
|
5
|
+
My own (very opinionated) custom tool for writing books. This is very much a work in progress right now.
|
4
6
|
|
5
7
|
## TODO's for a reasonable v1
|
6
8
|
|
7
|
-
* [ ] Support for variables (via config.yml)
|
8
|
-
* [ ] Support for embedded assets
|
9
|
-
* [ ] Build HTML
|
10
9
|
* [ ] Build PDF
|
11
10
|
* [ ] Build Mobi
|
12
11
|
* [ ] Build ePub
|
@@ -15,14 +14,30 @@ My own custom tool for writing books. This is very much a work in progress right
|
|
15
14
|
|
16
15
|
$ gem install bookery
|
17
16
|
|
18
|
-
|
17
|
+
_If you're using rbenv, run `rbenv rehash` after the installation to ensure the shim is created_
|
18
|
+
|
19
|
+
## Creating a New Book
|
20
|
+
|
21
|
+
$ bookery new <project_dir>
|
22
|
+
|
23
|
+
This will create a new [project] in the specified directory.
|
24
|
+
|
25
|
+
## Publishing
|
19
26
|
|
20
|
-
|
27
|
+
From within the project directory:
|
28
|
+
|
29
|
+
$ bookery publish
|
30
|
+
|
31
|
+
This will generate an HTML version of your book for each language in the [project].
|
32
|
+
|
33
|
+
## Editing
|
34
|
+
|
35
|
+
For a guideline on editing, checkout the [editing] docs.
|
21
36
|
|
22
37
|
## Contributing
|
23
38
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
39
|
+
Wanna contribute? Awesome! Check out the [contributing guidelines] to get started.
|
40
|
+
|
41
|
+
[project]: docs/project.md
|
42
|
+
[editing]: docs/editing.md
|
43
|
+
[contributing guidelines]: docs/contributing.md
|
data/Rakefile
CHANGED
data/bookery.gemspec
CHANGED
@@ -4,26 +4,30 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'bookery/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = "bookery"
|
8
8
|
spec.version = Bookery::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description = %q{
|
9
|
+
spec.authors = ["David Muto"]
|
10
|
+
spec.email = ["david.muto@gmail.com"]
|
11
|
+
spec.description = %q{
|
12
|
+
A gem that gives you the tools you need to write your own book
|
13
|
+
}
|
12
14
|
spec.summary = %q{A simple way to author your book}
|
13
15
|
spec.homepage = 'https://github.com/pseudomuto/bookery'
|
14
|
-
spec.license =
|
16
|
+
spec.license = "MIT"
|
15
17
|
|
16
18
|
spec.files = `git ls-files`.split($/)
|
17
|
-
spec.
|
19
|
+
spec.bindir = 'libexec'
|
20
|
+
spec.executables = spec.files.grep(%r{^libexec/}) { |f| File.basename(f) }
|
18
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ["lib"]
|
20
23
|
|
21
|
-
spec.add_dependency '
|
22
|
-
spec.add_dependency '
|
24
|
+
spec.add_dependency('thor', '~> 0.18.1')
|
25
|
+
spec.add_dependency('kramdown', '~> 1.3.0')
|
26
|
+
spec.add_dependency('coderay', '~> 1.1.0')
|
23
27
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency '
|
28
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency('bundler', '~> 1.3.5')
|
29
|
+
spec.add_development_dependency('rake', '~> 10.1.1')
|
30
|
+
spec.add_development_dependency('minitest', '~> 5.2.0')
|
31
|
+
spec.add_development_dependency('mocha', '~> 0.14.0')
|
32
|
+
spec.add_development_dependency('simplecov', '~> 0.8.2')
|
29
33
|
end
|
data/docs/config.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Project Configuration
|
2
|
+
|
3
|
+
The _config.yml_ file contains configuration information for your book. A typical file might look like this:
|
4
|
+
|
5
|
+
```yaml
|
6
|
+
---
|
7
|
+
book:
|
8
|
+
title: My Book
|
9
|
+
authors:
|
10
|
+
- Your Name
|
11
|
+
- Your Co-Author's Name
|
12
|
+
editors:
|
13
|
+
- Your Editor's Name
|
14
|
+
- Other Editor's Names
|
15
|
+
template: assets/templates/template.html.erb
|
16
|
+
```
|
17
|
+
|
18
|
+
You can override any of the values above for a particular language, by providing a subkey for that language. For example, if you want to change the title for the Spanish version, your file would look like this:
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
---
|
22
|
+
book:
|
23
|
+
title: My Book
|
24
|
+
authors:
|
25
|
+
- Your Name
|
26
|
+
- Your Co-Author's Name
|
27
|
+
editors:
|
28
|
+
- Your Editor's Name
|
29
|
+
- Other Editor's Names
|
30
|
+
template: assets/templates/template.html.erb
|
31
|
+
|
32
|
+
# overrides for Spanish
|
33
|
+
es:
|
34
|
+
title: Mi Libro
|
35
|
+
```
|
36
|
+
|
37
|
+
If there is no value specified for the current language (when publishing) the default will be used. So in the case of the file above, the template would be the same for both _en_ and _es_ books.
|
38
|
+
|
39
|
+
## Optional Configuration
|
40
|
+
|
41
|
+
If you want more control over how kramdown handles your markdown files you can provide some additional configuration options via the `generator` key. Here's an example:
|
42
|
+
|
43
|
+
```yaml
|
44
|
+
---
|
45
|
+
book:
|
46
|
+
...
|
47
|
+
...
|
48
|
+
|
49
|
+
generator:
|
50
|
+
input: Kramdown
|
51
|
+
enable_coderay: false
|
52
|
+
```
|
53
|
+
|
54
|
+
For a list of available options, see [kramdown's options](http://kramdown.gettalong.org/options.html). By default the following options are supplied:
|
55
|
+
|
56
|
+
```yaml
|
57
|
+
input: 'GFM'
|
58
|
+
enable_coderay: true
|
59
|
+
coderay_css: 'class'
|
60
|
+
coderay_line_numbers: 'inline'
|
61
|
+
```
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# How to Contribute
|
2
|
+
|
3
|
+
I love Pull Requests! Your contributions help make bookery great.
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
So you want to contribute to bookery. Great! Contributions take many forms from
|
8
|
+
submitting issues, writing docs, to making code changes. I welcome it all.
|
9
|
+
|
10
|
+
But first things first...
|
11
|
+
|
12
|
+
* Make sure you have a [GitHub account](https://github.com/signup/free)
|
13
|
+
* Submit a ticket for your issue, assuming one does not already exist.
|
14
|
+
* Clearly describe the issue including steps to reproduce when it is a bug.
|
15
|
+
* Make sure you fill in the earliest version that you know has the issue.
|
16
|
+
* Fork the repository on GitHub or run the following command in a git shell.
|
17
|
+
```
|
18
|
+
git clone git@github.com:pseudomuto/bookery.git
|
19
|
+
```
|
20
|
+
* Make sure the project builds and all tests pass on your machine by running
|
21
|
+
`rake test`
|
22
|
+
|
23
|
+
## Making Changes
|
24
|
+
|
25
|
+
* Create a topic branch off master (don't work directly on master).
|
26
|
+
* Make commits of logical units.
|
27
|
+
* Provide descriptive commit messages in the proper format
|
28
|
+
* Make sure you have added the necessary tests for your changes.
|
29
|
+
* Run _all_ the tests to assure nothing else was accidentally broken.
|
30
|
+
|
31
|
+
## Submitting Changes
|
32
|
+
|
33
|
+
* Push your changes to a topic branch in your fork of the repository.
|
34
|
+
* Submit a pull request. Note what issue/issues your patch fixes.
|
35
|
+
|
36
|
+
Some things that will increase the chance that your pull request is accepted.
|
37
|
+
|
38
|
+
* Follow existing code conventions. The usual ruby stuff like soft tabs, etc.
|
39
|
+
* Include tests that would otherwise fail without your code, but pass with
|
40
|
+
it.
|
41
|
+
* Update the documentation, the surrounding one, examples elsewhere, guides,
|
42
|
+
whatever is affected by your contribution
|
43
|
+
|
44
|
+
# Additional Resources
|
45
|
+
|
46
|
+
* [General GitHub documentation](http://help.github.com/)
|
47
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
data/docs/editing.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Editing
|
2
|
+
|
3
|
+
All book content is written in markdown. For a run down on markdown, check out Daring Fireball's [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax).
|
4
|
+
|
5
|
+
When using the default options, [Github Flavored Markdown](https://help.github.com/articles/github-flavored-markdown) is fully supported.
|
6
|
+
|
7
|
+
## Useful Information
|
8
|
+
|
9
|
+
* Markdown inside HTML blocks will not be processed
|
10
|
+
* CodeRay is used for syntax highlighting. For a list of supported languages check out the [home page].
|
11
|
+
|
12
|
+
[home page]: http://coderay.rubychan.de/
|
13
|
+
|
14
|
+
## Using Images
|
15
|
+
|
16
|
+
Images should be stored in the assets folder. You're free to choose any structure you like, but I would suggest an aptly named folder like _images_ or _img_.
|
17
|
+
|
18
|
+
When referencing an image in your markdown files, use the relative path from the project directory. For example, in _book/en/001-first-chapter.md_ you can reference _assets/images/cover.png_ like so:
|
19
|
+
|
20
|
+
<pre>
|
21
|
+
![My Image Alt Text](assets/images/cover.png)
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
## For technical writers, these might be of particular interest
|
25
|
+
|
26
|
+
### Fenced Code Blocks
|
27
|
+
|
28
|
+
You can include codce samples using fenced code blocks using back ticks and optionally the language name. For example, you could include a ruby class like this:
|
29
|
+
|
30
|
+
<pre>
|
31
|
+
```ruby
|
32
|
+
module Demo
|
33
|
+
class Foo
|
34
|
+
attr_reader :baz
|
35
|
+
|
36
|
+
def initialize(baz = 'demo')
|
37
|
+
@baz = baz
|
38
|
+
end
|
39
|
+
|
40
|
+
def bar(suffix)
|
41
|
+
"#{baz}#{suffix}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
</pre>
|
47
|
+
|
48
|
+
This would result in output like this:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
module Demo
|
52
|
+
class Foo
|
53
|
+
attr_reader :baz
|
54
|
+
|
55
|
+
def initialize(baz = 'demo')
|
56
|
+
@baz = baz
|
57
|
+
end
|
58
|
+
|
59
|
+
def bar(suffix)
|
60
|
+
"#{baz}#{suffix}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Including Code Files
|
67
|
+
|
68
|
+
Sometimes large code blocks can make your chapter files too large and harder to manage. To help with this, you can include external code files by using the following syntax:
|
69
|
+
|
70
|
+
<pre>
|
71
|
+
```<language>
|
72
|
+
includes::<path_to_include_file>
|
73
|
+
```
|
74
|
+
</pre>
|
75
|
+
|
76
|
+
The `path_to_include_file` above should be replaced with a path to a file relative to the _assets/includes_ directory. For example, to include _assets/includes/ruby/chapter2_fig1.rb_ you would use the following:
|
77
|
+
|
78
|
+
<pre>
|
79
|
+
```ruby
|
80
|
+
includes::ruby/chapter2_fig1.rb
|
81
|
+
```
|
82
|
+
</pre>
|
data/docs/project.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Project Layout/Structure
|
2
|
+
|
3
|
+
Each _book_ is represented a project containing:
|
4
|
+
|
5
|
+
* assets
|
6
|
+
* one or more books (one per language)
|
7
|
+
* configuration
|
8
|
+
|
9
|
+
## Directory Structure
|
10
|
+
|
11
|
+
Using the default template will result in a project with the following directory structure:
|
12
|
+
|
13
|
+
```
|
14
|
+
[project]
|
15
|
+
assets
|
16
|
+
css
|
17
|
+
[CSS files]
|
18
|
+
includes
|
19
|
+
templates
|
20
|
+
template.html.erb
|
21
|
+
style.css
|
22
|
+
book
|
23
|
+
en
|
24
|
+
001-first-chapter
|
25
|
+
01-chapter-file.md
|
26
|
+
config.yml
|
27
|
+
Gemfile
|
28
|
+
```
|
29
|
+
|
30
|
+
### Assets
|
31
|
+
|
32
|
+
The assets folder contains static files that are used by your book. These files can include templates, stylesheets, images, code files or anything else you like.
|
33
|
+
|
34
|
+
### Book
|
35
|
+
|
36
|
+
In the book directory, you will find a directory for each language you wish to support. By default, you will have an _en_ directory. If you wish to have another language, simply create a new folder under this directory with the abbreviated language code.
|
37
|
+
|
38
|
+
For example, to create a Spanish version of your book, create a directory called _es_.
|
39
|
+
|
40
|
+
Under each language directory, markdown files (_*.md_) contain the content of your book. For better organization (I told you this project was opinionated), each language directory is expected to follow something like this:
|
41
|
+
|
42
|
+
```
|
43
|
+
[lang]
|
44
|
+
[chapter]
|
45
|
+
[one or more md files]
|
46
|
+
```
|
47
|
+
|
48
|
+
During publishing, chapters (sub directories) will be combined in alphabetical order. Each of them combining their files in alphabetical order.
|
49
|
+
|
50
|
+
_I suggest following a naming convention to make this easy. I use `001-<chapter_name>` and `01-<filename>.md` for each file within a chapter._
|
51
|
+
|
52
|
+
For information on editing, check out the [editing docs](editing.md).
|
53
|
+
|
54
|
+
### Configuration
|
55
|
+
|
56
|
+
The _config.yml_ file contains configuration information for your book. A typical file might look like this:
|
57
|
+
|
58
|
+
```yaml
|
59
|
+
---
|
60
|
+
book:
|
61
|
+
title: My Book
|
62
|
+
authors:
|
63
|
+
- Your Name
|
64
|
+
- Your Co-Author's Name
|
65
|
+
editors:
|
66
|
+
- Your Editor's Name
|
67
|
+
- Other Editor's Names
|
68
|
+
template: assets/templates/template.html.erb
|
69
|
+
```
|
70
|
+
|
71
|
+
You can override values on a per language basis. You can also specify special configuration options for the publishing process.
|
72
|
+
|
73
|
+
For more details, see the [documentation for configuration](config.md).
|
74
|
+
|
75
|
+
### The Gemfile
|
76
|
+
|
77
|
+
This is a file used by ruby/bundler. For the most part you can ignore this file.
|
data/lib/bookery.rb
CHANGED
@@ -1,9 +1,32 @@
|
|
1
|
-
require '
|
1
|
+
require 'thor'
|
2
|
+
require 'yaml'
|
3
|
+
require 'kramdown'
|
4
|
+
require 'erb'
|
5
|
+
|
2
6
|
require 'bookery/version'
|
3
|
-
require 'bookery/
|
7
|
+
require 'bookery/config'
|
8
|
+
require 'bookery/factories/chapter_factory'
|
4
9
|
require 'bookery/book'
|
10
|
+
require 'bookery/factories/publisher_factory'
|
11
|
+
require 'bookery/project'
|
5
12
|
require 'bookery/cli'
|
6
13
|
|
7
|
-
|
8
|
-
|
14
|
+
require 'bookery/processors/include_processor'
|
15
|
+
|
16
|
+
class Hash
|
17
|
+
# Adapted from http://devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
|
18
|
+
def symbolize_keys
|
19
|
+
self.inject({}) do |result, (key, value)|
|
20
|
+
new_key = case key
|
21
|
+
when String then key.to_sym
|
22
|
+
else key
|
23
|
+
end
|
24
|
+
new_value = case value
|
25
|
+
when Hash then value.symbolize_keys
|
26
|
+
else value
|
27
|
+
end
|
28
|
+
result[new_key] = new_value
|
29
|
+
result
|
30
|
+
end
|
31
|
+
end
|
9
32
|
end
|