author 1.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +10 -0
- data/author.gemspec +29 -0
- data/bin/author +8 -0
- data/lib/author/commands/check.rb +27 -0
- data/lib/author/commands/cli.rb +18 -0
- data/lib/author/commands/generator.rb +44 -0
- data/lib/author/commands/version.rb +13 -0
- data/lib/author/plugins/awesome_codeblock.rb +140 -0
- data/lib/author/templates/Gemfile +6 -0
- data/lib/author/templates/config.yml +4 -0
- data/lib/author/templates/sample.md +3 -0
- data/lib/author/version.rb +3 -0
- data/lib/author.rb +22 -0
- data/test/commands/check_test.rb +18 -0
- data/test/commands/cli_test.rb +22 -0
- data/test/commands/generator_test.rb +39 -0
- data/test/commands/version_test.rb +11 -0
- data/test/helper.rb +62 -0
- data/test/liquids/highlight_lines.md +3 -0
- data/test/liquids/language_set.md +3 -0
- data/test/liquids/no_options.md +3 -0
- data/test/liquids/show_line_numbers.md +3 -0
- data/test/liquids/starting_line_number.md +3 -0
- data/test/liquids/title_as_filename.md +3 -0
- data/test/liquids/title_as_filepath.md +3 -0
- data/test/liquids/title_as_string.md +3 -0
- data/test/plugins/awesome_codeblock_test.rb +81 -0
- data/test/utils/assertions.rb +14 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmViMWM2MzJjNTc0NmE0Mzg1ZWIyZTIwMjc3NjU5NWZmYzg1OWRmZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2NkZDEyNDU1OTE4MjA4Y2Y1MDI1OGM5MmNhYWNiZGE4ZjUzYjVmNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Nzk2NGM2ODcwZjEwZDhkN2VhYTI1YzZjNWU0YWE4YTQ2M2U4MTE2OGMyZTZh
|
10
|
+
ODBiNmY4N2FlOTg1MjYwZDI3MzU1ZjE4ZDc0MzI3Zjc2ZWU3YjZkNGViMDQy
|
11
|
+
MDhhMTZiNmU2YzhjMWUyMGI5YmJjZGRiYjVmZTcyNTgwMGM0YzU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDk1ZTIzZDFhZGM5YzQwOGE1OGE2OWRlYTVmOGJmMDg2YWQwZjdiMzBiY2Mx
|
14
|
+
ZTI4NWE5MTBjNTcyOTlhYjU4MjA3MjVhNjA2NjdkMDc1NzgwZGU4M2FmMzI0
|
15
|
+
ZDIyZDNkMDFhMmQzMWM0ODYxM2E3YWYxYzYyYjZkMzQxNmRjNjI=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Terry Schmidt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Author
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tschmidt/author.svg?branch=master)](https://travis-ci.org/tschmidt/author)
|
4
|
+
|
5
|
+
**ATTN:** This is still **very** alpha. Not everything is working. Use at your own risk.
|
6
|
+
|
7
|
+
A simple tool to help you write your next ebook.
|
8
|
+
|
9
|
+
I had a major itch and this is what I used to scratch it. I wanted to write an ebook, but
|
10
|
+
just could not find a toolset that had everything I wanted. Leanpub was too limited on the
|
11
|
+
styling of the book. Kitabu drove me nuts with the hoops I had to jump through with
|
12
|
+
nokogiri. Wordsmith didn't do it for me either.
|
13
|
+
|
14
|
+
What was I looking for?
|
15
|
+
|
16
|
+
- Simple way to write my chapters in Markdown
|
17
|
+
- Generate PDFs and ePubs that were pretty to look at
|
18
|
+
- Have better looking codeblocks
|
19
|
+
- Not have to do a ton of configuration!!!!
|
20
|
+
|
21
|
+
Thus, Author was born.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'author'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself with:
|
34
|
+
|
35
|
+
$ gem install author
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
$ author new mybook
|
40
|
+
$ cd mybook
|
41
|
+
|
42
|
+
Add your chapters to the `chapters/` folder. Name them whatever you want. Then, in the
|
43
|
+
`outline.txt` file, simply list the chapters in the order you want them to appear in the
|
44
|
+
finished book:
|
45
|
+
|
46
|
+
preface.md
|
47
|
+
about-the-author.md
|
48
|
+
who-is-this-for.md
|
49
|
+
chapter-1.md
|
50
|
+
|
51
|
+
Once you've done that, just run one of the following commands:
|
52
|
+
|
53
|
+
author build xhtml # Generates the finalized XHTML site used for the other commands
|
54
|
+
author build pdf # Generates a PDF of your book
|
55
|
+
author build epub # Generates a fixed layout ePub that your eyeballs will love
|
56
|
+
author build all # Builds everything in one go
|
57
|
+
|
58
|
+
That's it!
|
59
|
+
|
60
|
+
Okay, there are a few other things you can do, like add a book cover image and include
|
61
|
+
images in your book. But, for the most part, that is all there is to it.
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/author.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'author/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "author"
|
8
|
+
spec.version = Author::VERSION
|
9
|
+
spec.authors = ["Terry Schmidt"]
|
10
|
+
spec.email = ["terry.m.schmidt@gmail.com"]
|
11
|
+
spec.summary = %q{Quickly create ebooks using Markdown}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "http://github.com/tschmidt/aughor"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "minitest-spec-expect"
|
25
|
+
|
26
|
+
spec.add_dependency "thor"
|
27
|
+
spec.add_dependency "liquid"
|
28
|
+
spec.add_dependency "coderay"
|
29
|
+
end
|
data/bin/author
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Author
|
4
|
+
module Commands
|
5
|
+
class Check < Thor::Group
|
6
|
+
|
7
|
+
def check_for_prince
|
8
|
+
check_for "Prince"
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_for_kindlegen
|
12
|
+
check_for "KindleGen"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def check_for(dependency)
|
18
|
+
command = dependency.downcase
|
19
|
+
installed = (`which #{command}` && $?.success?)
|
20
|
+
color = installed ? :green : :red
|
21
|
+
say "Checking for #{dependency}"
|
22
|
+
say "#{dependency} is#{' not' unless installed} installed\n\n", color
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative 'version'
|
3
|
+
require_relative 'check'
|
4
|
+
require_relative 'generator'
|
5
|
+
|
6
|
+
module Author
|
7
|
+
module Commands
|
8
|
+
class Cli < Thor
|
9
|
+
|
10
|
+
register Author::Commands::Version, 'version', 'version', 'Display current version'
|
11
|
+
map %w[-v --version] => :version
|
12
|
+
|
13
|
+
register Author::Commands::Check, 'check', 'check', 'Check that all dependencies are installed'
|
14
|
+
register Author::Commands::Generator, 'new', 'new <book-name>', 'Create a new book project'
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Author
|
4
|
+
module Commands
|
5
|
+
class Generator < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
argument :name
|
9
|
+
|
10
|
+
def set_destination_root
|
11
|
+
self.destination_root = File.join(self.destination_root, name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_project_structure
|
15
|
+
say "Creating directories for your new book, #{name}"
|
16
|
+
empty_directory "chapters"
|
17
|
+
empty_directory "export"
|
18
|
+
empty_directory "templates"
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_files
|
22
|
+
say "Copying files"
|
23
|
+
template 'config.yml', 'config.yml'
|
24
|
+
copy_file 'Gemfile', 'Gemfile'
|
25
|
+
create_file 'outline.txt'
|
26
|
+
template 'sample.md', 'chapters/sample.md'
|
27
|
+
end
|
28
|
+
|
29
|
+
def bundle_gems
|
30
|
+
inside destination_root do
|
31
|
+
say "Bundling gems"
|
32
|
+
run "bundle install", capture: true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.source_root
|
39
|
+
File.join(File.dirname(__FILE__), '..', 'templates')
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# = AwesomeCodeblock
|
2
|
+
#
|
3
|
+
# This is a CodeRay plugin that allows you to output more awesome codeblocks.
|
4
|
+
# It was inspired by the code_ray_block plugin by git@codebykat.
|
5
|
+
#
|
6
|
+
# == Usage
|
7
|
+
#
|
8
|
+
# The most basic usage is just calling the code block. This will not do much more than
|
9
|
+
# the standard codeblock wrapper.
|
10
|
+
#
|
11
|
+
# {% awesome_codeblock %}
|
12
|
+
# code goes here
|
13
|
+
# {% endawesome_codeblock %}
|
14
|
+
#
|
15
|
+
# You can choose to have a title added to the code block. This is great if you want to
|
16
|
+
# display the filename or filepath for the code snippet.
|
17
|
+
#
|
18
|
+
# {% awesome_codeblock title:"path/to/file.rb" %}
|
19
|
+
# code goes here
|
20
|
+
# {% endawesome_codeblock %}
|
21
|
+
#
|
22
|
+
# You can set the language of the code block. The default is `:text` but you can specify
|
23
|
+
# any of the code formats that CodeRay supports.
|
24
|
+
#
|
25
|
+
# {% awesome_codeblock lang:"ruby" %}
|
26
|
+
# code goes here
|
27
|
+
# {% endawesome_codeblock %}
|
28
|
+
#
|
29
|
+
# You can choose to add line numbers as well. Refer to the documentation for
|
30
|
+
# CodeRay::Encoder::HTML for values that can be passed in.
|
31
|
+
#
|
32
|
+
# {% awesome_codeblock line_number_format:"inline" %}
|
33
|
+
# code goes here
|
34
|
+
# {% endawesome_codeblock %}
|
35
|
+
#
|
36
|
+
# You can choose to highlight specific lines within your code block as well. Just supply
|
37
|
+
# a comma separated list of line numbers.
|
38
|
+
#
|
39
|
+
# {% awesome_codeblock lines_to_highlight:"2,3,4,7" %}
|
40
|
+
# code goes here
|
41
|
+
# ...
|
42
|
+
# {% endawesome_codeblock %}
|
43
|
+
#
|
44
|
+
# Author: Terry Schmidt
|
45
|
+
# Date: 21 May 2014
|
46
|
+
# License: [WTFPL](http://www.wtfpl.net/about/)
|
47
|
+
#
|
48
|
+
require 'liquid'
|
49
|
+
require 'coderay'
|
50
|
+
|
51
|
+
module Author
|
52
|
+
module Plugins
|
53
|
+
class AwesomeCodeblock < Liquid::Block
|
54
|
+
|
55
|
+
attr_accessor :title, :language, :markup, :options, :code
|
56
|
+
|
57
|
+
def initialize(tag_name, markup, tokens)
|
58
|
+
@markup = markup
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
def render(context)
|
63
|
+
@code = super
|
64
|
+
output = ''
|
65
|
+
output += header
|
66
|
+
output += tableized_code(code)
|
67
|
+
output += footer
|
68
|
+
output
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def header
|
74
|
+
%Q[<figure class="#{css_classes.join(' ')}">#{wrapped_title}<div class="CodeRay"><table class="code">]
|
75
|
+
end
|
76
|
+
|
77
|
+
def wrapped_title
|
78
|
+
return '' unless title
|
79
|
+
%Q[<figcaption class="code-header"><span>#{title}</span></figcaption>]
|
80
|
+
end
|
81
|
+
|
82
|
+
def title
|
83
|
+
@title = (markup =~ /\s*title:"([^"]+)"/i) ? $1 : nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def footer
|
87
|
+
%q[</table></div></figure>]
|
88
|
+
end
|
89
|
+
|
90
|
+
def tableized_code(code)
|
91
|
+
lines = ''
|
92
|
+
wrapped_code = ''
|
93
|
+
code.strip.split("\n").each_with_index do |line, index|
|
94
|
+
index += starting_line_number
|
95
|
+
line = " " if line.empty?
|
96
|
+
lines += %Q[<div class="line-number#{' highlight' if lines_to_highlight && lines_to_highlight.include?(index)}">#{index}</div>]
|
97
|
+
wrapped_code += %Q[<div class="code-part#{' highlight' if lines_to_highlight && lines_to_highlight.include?(index)}">#{line}</div>]
|
98
|
+
end
|
99
|
+
tr_str do
|
100
|
+
''.tap do |str|
|
101
|
+
str << %Q[<td class="gutter">#{lines}</td>] if show_line_numbers?
|
102
|
+
str << %Q[<td class="lines-of-code"><pre>#{wrapped_code}</pre></td>]
|
103
|
+
str
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def tr_str
|
109
|
+
%Q[<tbody><tr>#{yield}</tr></tbody>]
|
110
|
+
end
|
111
|
+
|
112
|
+
def language
|
113
|
+
@language = (markup =~ /\s*lang(?:uage)?:['"]?([^"'\s]+)*['"]?/i) ? $1 : 'text'
|
114
|
+
end
|
115
|
+
|
116
|
+
def css_classes
|
117
|
+
['code', language].compact
|
118
|
+
end
|
119
|
+
|
120
|
+
def show_line_numbers?
|
121
|
+
show_line_numbers || lines_to_highlight || starting_line_number > 1
|
122
|
+
end
|
123
|
+
|
124
|
+
def show_line_numbers
|
125
|
+
(markup =~ /\s*show_line_numbers:['"]?([^"'\s]+)['"]?/i) ? true : false
|
126
|
+
end
|
127
|
+
|
128
|
+
def lines_to_highlight
|
129
|
+
(markup =~ /\s*highlight:['"]?([^"'\s]+)*['"]?/i) ? $1.split(/, ?/).map(&:to_i) : false
|
130
|
+
end
|
131
|
+
|
132
|
+
def starting_line_number
|
133
|
+
(markup =~ /\s*start_at:['"]?([^"'\s]+)['"]?/i) ? $1.to_i : 1
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
Liquid::Template.register_tag('awesome_codeblock', Author::Plugins::AwesomeCodeblock)
|
data/lib/author.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) # For use/testing when author gem is not installed
|
2
|
+
|
3
|
+
# Convenience method that will require all files in the given path
|
4
|
+
def require_all(path)
|
5
|
+
glob = File.join(File.dirname(__FILE__), path, '*.rb')
|
6
|
+
Dir[glob].each do |file|
|
7
|
+
require file
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# stdlib
|
12
|
+
|
13
|
+
# 3rd party
|
14
|
+
|
15
|
+
# internals
|
16
|
+
require 'author/version'
|
17
|
+
require_all 'author/commands'
|
18
|
+
require_all 'author/plugins'
|
19
|
+
|
20
|
+
module Author
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'author/commands/check'
|
3
|
+
|
4
|
+
describe Author::Commands::Check do
|
5
|
+
|
6
|
+
let(:output) { capture { Author::Commands::Check.start } }
|
7
|
+
|
8
|
+
it "should check to see if Prince XML is installed" do
|
9
|
+
expect(output).to_include "Checking for Prince"
|
10
|
+
expect(output).to_match /^Prince is( not)? installed/
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should check to see if KindleGen is installed" do
|
14
|
+
expect(output).to_include "Checking for KindleGen"
|
15
|
+
expect(output).to_match /^KindleGen is( not)? installed/
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'author/commands/cli'
|
3
|
+
|
4
|
+
describe Author::Commands::Cli do
|
5
|
+
|
6
|
+
let(:output) do
|
7
|
+
capture(:stdout) { Author::Commands::Cli.start }
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to version" do
|
11
|
+
expect(output).to_include "version"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should respond to check" do
|
15
|
+
expect(output).to_include "check"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should respond to new" do
|
19
|
+
expect(output).to_include "new"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'author/commands/generator'
|
3
|
+
|
4
|
+
describe Author::Commands::Generator do
|
5
|
+
|
6
|
+
it "should require a name" do
|
7
|
+
output = capture(:stderr) { Author::Commands::Generator.start }
|
8
|
+
expect(output).to_include "No value provided for required arguments 'name'"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create project structure" do
|
12
|
+
play_in_sandbox do
|
13
|
+
capture(:stdout) { Author::Commands::Generator.start ['abook'] }
|
14
|
+
|
15
|
+
'abook'.must_be_a_directory
|
16
|
+
'abook/chapters'.must_be_a_directory
|
17
|
+
'abook/export'.must_be_a_directory
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create project files" do
|
22
|
+
play_in_sandbox do
|
23
|
+
capture { Author::Commands::Generator.start ['ihazfiles']}
|
24
|
+
|
25
|
+
'ihazfiles/config.yml'.must_be_a_file
|
26
|
+
'ihazfiles/Gemfile'.must_be_a_file
|
27
|
+
'ihazfiles/outline.txt'.must_be_a_file
|
28
|
+
'ihazfiles/chapters/sample.md'.must_be_a_file
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should run bundler for the new project" do
|
33
|
+
play_in_sandbox do
|
34
|
+
output = capture(:stdout) { Author::Commands::Generator.start ['bundled'] }
|
35
|
+
expect(output).to_include "Bundling gems"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../helper.rb'
|
2
|
+
require 'author/commands/version'
|
3
|
+
|
4
|
+
describe Author::Commands::Version do
|
5
|
+
|
6
|
+
it "should return Author version" do
|
7
|
+
output = capture(:stdout) { Author::Commands::Version.start }
|
8
|
+
expect(output.chomp).to_equal "Author version #{Author::VERSION}"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'minitest'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/spec/expect'
|
4
|
+
require 'minitest/pride'
|
5
|
+
require_relative 'utils/assertions'
|
6
|
+
|
7
|
+
module AuthorHelpers
|
8
|
+
include FileUtils
|
9
|
+
|
10
|
+
def capture(stream = :stdout)
|
11
|
+
begin
|
12
|
+
strm = stream.to_s
|
13
|
+
eval "$#{strm} = StringIO.new"
|
14
|
+
yield
|
15
|
+
result = eval("$#{strm}").string
|
16
|
+
ensure
|
17
|
+
eval("$#{strm} = #{strm.upcase}")
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def sandbox_path
|
23
|
+
File.join(File.dirname(__FILE__), 'sandbox')
|
24
|
+
end
|
25
|
+
|
26
|
+
def play_in_sandbox
|
27
|
+
ensure_sandbox_is_clean
|
28
|
+
cd(sandbox_path) do
|
29
|
+
yield
|
30
|
+
end
|
31
|
+
empty_sandbox
|
32
|
+
end
|
33
|
+
|
34
|
+
def ensure_sandbox_is_clean
|
35
|
+
rm_rf(sandbox_path)
|
36
|
+
mkdir_p(sandbox_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty_sandbox
|
40
|
+
rm_rf(sandbox_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def liquid_templates_path
|
44
|
+
File.join(File.dirname(__FILE__), 'liquids')
|
45
|
+
end
|
46
|
+
|
47
|
+
def using_liquid_templates
|
48
|
+
cd(liquid_templates_path) do
|
49
|
+
yield
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
MiniTest::Test.send :include, AuthorHelpers
|
55
|
+
|
56
|
+
module MiniTest
|
57
|
+
class Spec
|
58
|
+
class << self
|
59
|
+
alias_method :context, :describe
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'liquid'
|
3
|
+
require 'author/plugins/awesome_codeblock'
|
4
|
+
|
5
|
+
describe Author::Plugins::AwesomeCodeblock do
|
6
|
+
|
7
|
+
let(:liquid) { Liquid::Template }
|
8
|
+
|
9
|
+
context "no options given" do
|
10
|
+
it "should process the block into pretty code" do
|
11
|
+
using_liquid_templates do
|
12
|
+
rendered = liquid.parse(IO.read('no_options.md')).render
|
13
|
+
expect(rendered).to_include %q[puts "I'm awesome!"]
|
14
|
+
expect(rendered).to_include %Q[<figure class="code text"><div class="CodeRay"><table class="code">]
|
15
|
+
expect(rendered).to_not_include %q[<figcaption class='code-header'><span>]
|
16
|
+
expect(rendered).to_not_include %q[<div class="line-number">]
|
17
|
+
expect(rendered).to_not_include %q[<div class="line-number highlight">]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with title set" do
|
23
|
+
it "should set the title when string" do
|
24
|
+
using_liquid_templates do
|
25
|
+
rendered = liquid.parse(IO.read('title_as_string.md')).render
|
26
|
+
expect(rendered).to_include %q[<figcaption class="code-header"><span>The Title</span></figcaption]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should set the title when file name" do
|
31
|
+
using_liquid_templates do
|
32
|
+
rendered = liquid.parse(IO.read('title_as_filename.md')).render
|
33
|
+
expect(rendered).to_include %q[<figcaption class="code-header"><span>index.html</span></figcaption>]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set the title when file path" do
|
38
|
+
using_liquid_templates do
|
39
|
+
rendered = liquid.parse(IO.read('title_as_filepath.md')).render
|
40
|
+
expect(rendered).to_include %q[<figcaption class="code-header"><span>path/to/file/index.html</span></figcaption>]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with language set" do
|
46
|
+
it "should set the language" do
|
47
|
+
using_liquid_templates do
|
48
|
+
rendered = liquid.parse(IO.read('language_set.md')).render
|
49
|
+
expect(rendered).to_include %Q[<figure class="code ruby">]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with show line numbers set" do
|
55
|
+
it "should include line numbers" do
|
56
|
+
using_liquid_templates do
|
57
|
+
rendered = liquid.parse(IO.read('show_line_numbers.md')).render
|
58
|
+
expect(rendered).to_include %q[<td class="gutter"><div class="line-number">1</div></td>]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with lines set to be highlighted" do
|
64
|
+
it "should highlight the line" do
|
65
|
+
using_liquid_templates do
|
66
|
+
rendered = liquid.parse(IO.read('highlight_lines.md')).render
|
67
|
+
expect(rendered).to_include %q[<td class="gutter"><div class="line-number highlight">1</div></td>]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "with starting line number set" do
|
73
|
+
it "should start the line count at the number given" do
|
74
|
+
using_liquid_templates do
|
75
|
+
rendered = liquid.parse(IO.read('starting_line_number.md')).render
|
76
|
+
expect(rendered).to_include %q[<td class="gutter"><div class="line-number">15</div></td>]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MiniTest::Assertions
|
2
|
+
def assert_directory_exists(*args)
|
3
|
+
dirname = args.compact.first
|
4
|
+
assert Dir.exist?(dirname), "Expected '#{File.expand_path dirname}/' to exist but it does not"
|
5
|
+
end
|
6
|
+
|
7
|
+
def assert_file_exists(*args)
|
8
|
+
filename = args.compact.first
|
9
|
+
assert File.file?(filename), "Expected '#{File.expand_path filename}' to exist but it does not"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
String.infect_an_assertion :assert_directory_exists, :must_be_a_directory
|
14
|
+
String.infect_an_assertion :assert_file_exists, :must_be_a_file
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: author
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Terry Schmidt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-spec-expect
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: thor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: liquid
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coderay
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Quickly create ebooks using Markdown
|
112
|
+
email:
|
113
|
+
- terry.m.schmidt@gmail.com
|
114
|
+
executables:
|
115
|
+
- author
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .travis.yml
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- author.gemspec
|
126
|
+
- bin/author
|
127
|
+
- lib/author.rb
|
128
|
+
- lib/author/commands/check.rb
|
129
|
+
- lib/author/commands/cli.rb
|
130
|
+
- lib/author/commands/generator.rb
|
131
|
+
- lib/author/commands/version.rb
|
132
|
+
- lib/author/plugins/awesome_codeblock.rb
|
133
|
+
- lib/author/templates/Gemfile
|
134
|
+
- lib/author/templates/config.yml
|
135
|
+
- lib/author/templates/sample.md
|
136
|
+
- lib/author/version.rb
|
137
|
+
- test/commands/check_test.rb
|
138
|
+
- test/commands/cli_test.rb
|
139
|
+
- test/commands/generator_test.rb
|
140
|
+
- test/commands/version_test.rb
|
141
|
+
- test/helper.rb
|
142
|
+
- test/liquids/highlight_lines.md
|
143
|
+
- test/liquids/language_set.md
|
144
|
+
- test/liquids/no_options.md
|
145
|
+
- test/liquids/show_line_numbers.md
|
146
|
+
- test/liquids/starting_line_number.md
|
147
|
+
- test/liquids/title_as_filename.md
|
148
|
+
- test/liquids/title_as_filepath.md
|
149
|
+
- test/liquids/title_as_string.md
|
150
|
+
- test/plugins/awesome_codeblock_test.rb
|
151
|
+
- test/utils/assertions.rb
|
152
|
+
homepage: http://github.com/tschmidt/aughor
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ! '>'
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: 1.3.1
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.2.2
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Quickly create ebooks using Markdown
|
176
|
+
test_files:
|
177
|
+
- test/commands/check_test.rb
|
178
|
+
- test/commands/cli_test.rb
|
179
|
+
- test/commands/generator_test.rb
|
180
|
+
- test/commands/version_test.rb
|
181
|
+
- test/helper.rb
|
182
|
+
- test/liquids/highlight_lines.md
|
183
|
+
- test/liquids/language_set.md
|
184
|
+
- test/liquids/no_options.md
|
185
|
+
- test/liquids/show_line_numbers.md
|
186
|
+
- test/liquids/starting_line_number.md
|
187
|
+
- test/liquids/title_as_filename.md
|
188
|
+
- test/liquids/title_as_filepath.md
|
189
|
+
- test/liquids/title_as_string.md
|
190
|
+
- test/plugins/awesome_codeblock_test.rb
|
191
|
+
- test/utils/assertions.rb
|