author 1.0.1.alpha → 1.1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjc1MjM1Yzk0NjhhZmQ2MzRlNTBlZmQ5Mzc0NDVjZGZiOTIyZDgyYQ==
4
+ MTBlMzUwOWE0ZjQ3MWNjYmJmYmU2Y2JlNmQ0YmZhOWVkODJmZTA2NA==
5
5
  data.tar.gz: !binary |-
6
- Mzk2ZjY2YzdlMDM4Y2I5MGM4YmZiOWZjZGM5MmNjZDlmYjk3YTg3Yw==
6
+ ZmRiMDRjZDlmMjdjZTUzM2Q1ZDhhZmY5ODg1YWE1NjU5YzQzZGQ1NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTA1ZWE2ZDE1M2U0ZWFhMDkzYzJiZDZhMmU2YjE2NDQwNjM2ZjA5OGZiOGJh
10
- NzAwYWU5YzljZmJmN2I5MWFiZjM4MzE2NzZhYzg2NmNiYTI5ZjE0NDMyOGE4
11
- YTFlOTI4MTAwZTdlMTQxZTY1NWMwMTFlOTljNmM2YThkZDNlZGQ=
9
+ OWVkNjRiNDhmYWNkMjBlNTNhMGZhMGRkNjAyNzhiMDEwZmVjMzY5YWRmMmIw
10
+ MmIxMWY3N2RkMmJiOGIzOWM0NzY2MDcwNTc4NWU0MGNhNDgyOTMxMjA4NmUz
11
+ YTczY2UzNjYwMTJiOGRjYWViZTQwZDA3MTE2NWVmYzI3OWVhYTE=
12
12
  data.tar.gz: !binary |-
13
- NDFmZGVhZWVhZDQ2YzMwOGUwNWRiMDM4MzYzYzhlYzRmYjIwZTNjNzRhZjI4
14
- MzM4MjNkY2NjYmQ5MjRkNzdlOGE0MjUwYjQyMmY2NTRiYWNhNTU1OWUyYzlh
15
- YWU0YWEyZmVkNGFkNTk2OTM0MmQyMzhmYTI4MDc1MjFjYjg1MGY=
13
+ ODgwZDBlYzhlOWE4YzQ5OTFkN2QyNDNkNTNiYzQxY2Q2ODYxZmViOWRjZTk4
14
+ ZTBkNzlhOWVjMDg5MzUwYzg2NjA5NDBhYTVlMzRiYjVlMTRhOWNhNDU1NzEy
15
+ NjZjYmMzODk3NDVjZTZhYjhiODA0YTg2MDI2MDJmZDE3ZGY0ZGQ=
data/README.md CHANGED
@@ -1,21 +1,23 @@
1
- # Author
1
+ # Author [![GitHub version](https://badge.fury.io/gh/tschmidt%2Fauthor.svg)](http://badge.fury.io/gh/tschmidt%2Fauthor)
2
2
 
3
- [![Build Status](https://travis-ci.org/tschmidt/author.svg?branch=master)](https://travis-ci.org/tschmidt/author)
3
+ [![Build Status](https://travis-ci.org/tschmidt/author.svg?branch=master)](https://travis-ci.org/tschmidt/author) [![Dependency Status](https://gemnasium.com/tschmidt/author.svg)](https://gemnasium.com/tschmidt/author)
4
4
 
5
5
  **ATTN:** This is still **very** alpha. Not everything is working. Use at your own risk.
6
6
 
7
+ *[imho]: In my humble opinion
8
+
7
9
  A simple tool to help you write your next ebook.
8
10
 
9
11
  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
12
+ couldn't find a toolset that had everything I wanted. Leanpub was too limited on the
11
13
  styling of the book. Kitabu drove me nuts with the hoops I had to jump through with
12
14
  nokogiri. Wordsmith didn't do it for me either.
13
15
 
14
16
  What was I looking for?
15
17
 
16
- - Simple way to write my chapters in Markdown
18
+ - A simple way to write my chapters in Markdown
17
19
  - Generate PDFs and ePubs that were pretty to look at
18
- - Have better looking codeblocks
20
+ - Have better looking code blocks
19
21
  - Not have to do a ton of configuration!!!!
20
22
 
21
23
  Thus, Author was born.
@@ -34,7 +36,7 @@ Or install it yourself with:
34
36
 
35
37
  $ gem install author
36
38
 
37
- ## Usage
39
+ ## Quick Start Guide
38
40
 
39
41
  $ author new mybook
40
42
  $ cd mybook
@@ -50,15 +52,26 @@ finished book:
50
52
 
51
53
  Once you've done that, just run one of the following commands:
52
54
 
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
55
+ author build xhtml
56
+ author build pdf
57
+ author build epub
58
+ author build mobi
56
59
  author build all # Builds everything in one go
57
60
 
58
61
  That's it!
59
62
 
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.
63
+ ## Full Tutorial
64
+
65
+ Coming soon.
66
+
67
+ ## Dependencies
68
+
69
+ There are a couple of executables that Author requires to do its job.
70
+
71
+ - [Prince XML](http://www.princexml.com): This is the tool used to create PDFs of your book. The free version of Prince XML is fully functional and adds a small icon to the first page of your PDF. I've looked at other solutions and this - imho - is the best one.
72
+ - [KindleGen](http://www.amazon.com/gp/feature.html?docId=1000765211): This is a tool from Amazon that will generate a `.mobi` file.
73
+
74
+ You can run `author check` to find out if you have these dependencies installed on your system.
62
75
 
63
76
  ## Contributing
64
77
 
data/author.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "thor"
27
27
  spec.add_dependency "liquid"
28
28
  spec.add_dependency "coderay"
29
+ spec.add_dependency "kramdown"
29
30
  end
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+
3
+ module Author
4
+ module Commands
5
+ class Builder < Thor
6
+
7
+ desc "xhtml", "Build the XHTML site"
8
+ def xhtml
9
+ say "Building the XHTML site"
10
+ Author::Exporters::XHTML.export
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -13,6 +13,8 @@ module Author
13
13
  register Author::Commands::Check, 'check', 'check', 'Check that all dependencies are installed'
14
14
  register Author::Commands::Generator, 'new', 'new <book-name>', 'Create a new book project'
15
15
 
16
+ register Author::Commands::Builder, 'build', 'build', 'Build the specified format'
17
+
16
18
  end
17
19
  end
18
20
  end
@@ -24,6 +24,9 @@ module Author
24
24
  copy_file 'Gemfile', 'Gemfile'
25
25
  create_file 'outline.txt'
26
26
  template 'sample.md', 'chapters/sample.md'
27
+ template 'layout.xhtml', 'templates/layout.xhtml'
28
+
29
+ gsub_file 'templates/layout.xhtml', '<!-- insert @body -->', '<%= @body %>'
27
30
  end
28
31
 
29
32
  def bundle_gems
@@ -0,0 +1,92 @@
1
+ require 'liquid'
2
+ require 'kramdown'
3
+ require 'author/plugins/awesome_codeblock'
4
+
5
+ module Author
6
+ module Exporters
7
+ class XHTML
8
+ # step 1: get file names from the outline.txt file
9
+ # step 2: create a new file called all.md
10
+ # step 3: concatenate all files and output to all.md
11
+ # step 4: run all.md through liquid
12
+ # step 5: run all.md through kramdown with template specified in config
13
+ # step 6: output result of step 5 to `export/book.xhtml`
14
+ # step 7: handle css and images
15
+
16
+ def self.export
17
+ exporter = new
18
+ exporter.combine_all_files
19
+ exporter.liquify
20
+ exporter.kramdownify
21
+ end
22
+
23
+ def root_dir
24
+ Dir.pwd
25
+ end
26
+
27
+ def source_dir
28
+ File.join(root_dir, 'chapters')
29
+ end
30
+
31
+ def outline_path
32
+ filepath = File.join(root_dir, 'outline.txt')
33
+ raise "No outline.txt file found. Make sure you are in an author project." unless File.file?(filepath)
34
+ filepath
35
+ end
36
+
37
+ def file_names
38
+ [].tap do |array|
39
+ File.readlines(outline_path).each do |line|
40
+ array << line.gsub(/\n/, '')
41
+ end
42
+ end
43
+ end
44
+
45
+ def combined_file_path
46
+ File.join(source_dir, 'all.md')
47
+ end
48
+
49
+ def output_path
50
+ File.join(source_dir, '..', 'export', 'book.xhtml')
51
+ end
52
+
53
+ def layout_path
54
+ File.join(source_dir, '..', 'templates', 'layout.xhtml')
55
+ end
56
+
57
+ def combine_all_files
58
+ File.open(combined_file_path, 'w') do |file|
59
+ file.puts concatenate_files
60
+ end
61
+ end
62
+
63
+ def concatenate_files
64
+ ''.tap do |output|
65
+ file_names.each do |file_name|
66
+ filepath = File.join(source_dir, file_name)
67
+ next unless File.file?(filepath)
68
+ output += IO.read(filepath)
69
+ output += "\n\n" unless file_name == file_names.last
70
+ end
71
+ return output
72
+ end
73
+ end
74
+
75
+ def liquify(assigns = {})
76
+ @assigns = assigns
77
+ liquified_output = Liquid::Template.parse(IO.read(combined_file_path)).render(@assigns)
78
+ File.open(combined_file_path, 'w') do |file|
79
+ file.puts liquified_output
80
+ end
81
+ end
82
+
83
+ def kramdownify
84
+ kramified_output = Kramdown::Document.new(IO.read(combined_file_path), template: layout_path).to_html
85
+ File.open(output_path, 'w') do |file|
86
+ file.puts kramified_output
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= name %></title>
6
+ </head>
7
+ <body>
8
+ <div id="contents">
9
+ <!-- insert @body -->
10
+ </div>
11
+ </body>
12
+ </html>
@@ -1,3 +1,3 @@
1
1
  module Author
2
- VERSION = "1.0.1.alpha"
2
+ VERSION = "1.1.0.alpha"
3
3
  end
data/lib/author.rb CHANGED
@@ -11,11 +11,16 @@ end
11
11
  # stdlib
12
12
 
13
13
  # 3rd party
14
+ require 'liquid'
15
+ require 'coderay'
16
+ require 'thor'
17
+ require 'kramdown'
14
18
 
15
19
  # internals
16
20
  require 'author/version'
17
21
  require_all 'author/commands'
18
22
  require_all 'author/plugins'
23
+ require_all 'author/exporters'
19
24
 
20
25
  module Author
21
26
 
@@ -0,0 +1,13 @@
1
+ require_relative '../helper'
2
+ require 'author/commands/builder'
3
+
4
+ describe Author::Commands::Builder do
5
+
6
+ let(:builder) { Author::Commands::Builder }
7
+
8
+ it "should respond to xhtml" do
9
+ output = capture { builder.start }
10
+ expect(output).to_include "xhtml"
11
+ end
12
+
13
+ end
@@ -18,5 +18,9 @@ describe Author::Commands::Cli do
18
18
  it "should respond to new" do
19
19
  expect(output).to_include "new"
20
20
  end
21
+
22
+ it "should respond to build" do
23
+ expect(output).to_include "build"
24
+ end
21
25
 
22
26
  end
@@ -15,6 +15,7 @@ describe Author::Commands::Generator do
15
15
  'abook'.must_be_a_directory
16
16
  'abook/chapters'.must_be_a_directory
17
17
  'abook/export'.must_be_a_directory
18
+ 'abook/templates'.must_be_a_directory
18
19
  end
19
20
  end
20
21
 
@@ -26,6 +27,7 @@ describe Author::Commands::Generator do
26
27
  'ihazfiles/Gemfile'.must_be_a_file
27
28
  'ihazfiles/outline.txt'.must_be_a_file
28
29
  'ihazfiles/chapters/sample.md'.must_be_a_file
30
+ 'ihazfiles/templates/layout.xhtml'.must_be_a_file
29
31
  end
30
32
  end
31
33
 
@@ -0,0 +1,58 @@
1
+ require_relative '../helper'
2
+ require 'author/exporters/xhtml'
3
+
4
+ describe Author::Exporters::XHTML do
5
+
6
+ let(:exporter) { Author::Exporters::XHTML.new }
7
+
8
+ it "should return a list of files" do
9
+ inside_sample_book do
10
+ expect(exporter.file_names).to_equal ['one.md', 'two.md', 'three.md']
11
+ end
12
+ end
13
+
14
+ it "should combine the files" do
15
+ inside_sample_book do
16
+ expect(exporter.concatenate_files).to_include %q[## This is chapter one]
17
+ expect(exporter.concatenate_files).to_include %q[## This is chapter two]
18
+ expect(exporter.concatenate_files).to_include %q[## This is chapter three]
19
+ end
20
+ end
21
+
22
+ it "should create a file called all.md" do
23
+ inside_sample_book do
24
+ exporter.combine_all_files
25
+ 'chapters/all.md'.must_be_a_file
26
+ output = IO.read('chapters/all.md')
27
+ expect(exporter.concatenate_files).to_include %q[## This is chapter one]
28
+ expect(exporter.concatenate_files).to_include %q[## This is chapter two]
29
+ expect(exporter.concatenate_files).to_include %q[## This is chapter three]
30
+ end
31
+ end
32
+
33
+ it "should parse liquid" do
34
+ inside_sample_book do
35
+ exporter.combine_all_files
36
+ exporter.liquify({"foo" => "foo output"})
37
+ output = IO.read('chapters/all.md')
38
+ expect(output).to_include "Liquid test foo output"
39
+ end
40
+ end
41
+
42
+ it "should parse kramdown" do
43
+ inside_sample_book do
44
+ exporter.combine_all_files
45
+ exporter.kramdownify
46
+ output = IO.read('export/book.xhtml')
47
+ expect(output).to_include %q[<h2 id="this-is-chapter-one">This is chapter one</h2>]
48
+ end
49
+ end
50
+
51
+ it "should create book.xhtml" do
52
+ inside_sample_book do
53
+ Author::Exporters::XHTML.export
54
+ 'export/book.xhtml'.must_be_a_file
55
+ end
56
+ end
57
+
58
+ end
data/test/helper.rb CHANGED
@@ -50,6 +50,23 @@ module AuthorHelpers
50
50
  end
51
51
  end
52
52
 
53
+ def sample_book_path
54
+ File.join(File.dirname(__FILE__), 'sample_book')
55
+ end
56
+
57
+ def ensure_clean_book
58
+ rm_f File.join(sample_book_path, 'chapters', 'all.md')
59
+ rm_f File.join(sample_book_path, 'export', 'book.xhtml')
60
+ end
61
+
62
+ def inside_sample_book
63
+ ensure_clean_book
64
+ cd(sample_book_path) do
65
+ yield
66
+ end
67
+ ensure_clean_book
68
+ end
69
+
53
70
  end
54
71
  MiniTest::Test.send :include, AuthorHelpers
55
72
 
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # gem 'author' # Uncomment this once the gem is published.
4
+ gem 'kramdown'
5
+ gem 'coderay'
6
+ gem 'eeepub'
@@ -0,0 +1,3 @@
1
+ ## This is chapter one
2
+
3
+ Liquid test {{ foo }}
@@ -0,0 +1 @@
1
+ ## This is chapter three
@@ -0,0 +1 @@
1
+ ## This is chapter two
@@ -0,0 +1,4 @@
1
+ ---
2
+ title: test/sample_book
3
+ markdown: kramdown
4
+ highlighter: coderay
@@ -0,0 +1,3 @@
1
+ one.md
2
+ two.md
3
+ three.md
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Sample Book</title>
6
+ </head>
7
+ <body>
8
+ <div id="contents">
9
+ <%= @body %>
10
+ </div>
11
+ </body>
12
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: author
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.alpha
4
+ version: 1.1.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terry Schmidt
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: kramdown
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Quickly create ebooks using Markdown
112
126
  email:
113
127
  - terry.m.schmidt@gmail.com
@@ -125,19 +139,24 @@ files:
125
139
  - author.gemspec
126
140
  - bin/author
127
141
  - lib/author.rb
142
+ - lib/author/commands/builder.rb
128
143
  - lib/author/commands/check.rb
129
144
  - lib/author/commands/cli.rb
130
145
  - lib/author/commands/generator.rb
131
146
  - lib/author/commands/version.rb
147
+ - lib/author/exporters/xhtml.rb
132
148
  - lib/author/plugins/awesome_codeblock.rb
133
149
  - lib/author/templates/Gemfile
134
150
  - lib/author/templates/config.yml
151
+ - lib/author/templates/layout.xhtml
135
152
  - lib/author/templates/sample.md
136
153
  - lib/author/version.rb
154
+ - test/commands/builder_test.rb
137
155
  - test/commands/check_test.rb
138
156
  - test/commands/cli_test.rb
139
157
  - test/commands/generator_test.rb
140
158
  - test/commands/version_test.rb
159
+ - test/exporters/xhtml_test.rb
141
160
  - test/helper.rb
142
161
  - test/liquids/highlight_lines.md
143
162
  - test/liquids/language_set.md
@@ -148,6 +167,13 @@ files:
148
167
  - test/liquids/title_as_filepath.md
149
168
  - test/liquids/title_as_string.md
150
169
  - test/plugins/awesome_codeblock_test.rb
170
+ - test/sample_book/Gemfile
171
+ - test/sample_book/chapters/one.md
172
+ - test/sample_book/chapters/three.md
173
+ - test/sample_book/chapters/two.md
174
+ - test/sample_book/config.yml
175
+ - test/sample_book/outline.txt
176
+ - test/sample_book/templates/layout.xhtml
151
177
  - test/utils/assertions.rb
152
178
  homepage: http://github.com/tschmidt/author
153
179
  licenses:
@@ -174,10 +200,12 @@ signing_key:
174
200
  specification_version: 4
175
201
  summary: Quickly create ebooks using Markdown
176
202
  test_files:
203
+ - test/commands/builder_test.rb
177
204
  - test/commands/check_test.rb
178
205
  - test/commands/cli_test.rb
179
206
  - test/commands/generator_test.rb
180
207
  - test/commands/version_test.rb
208
+ - test/exporters/xhtml_test.rb
181
209
  - test/helper.rb
182
210
  - test/liquids/highlight_lines.md
183
211
  - test/liquids/language_set.md
@@ -188,4 +216,11 @@ test_files:
188
216
  - test/liquids/title_as_filepath.md
189
217
  - test/liquids/title_as_string.md
190
218
  - test/plugins/awesome_codeblock_test.rb
219
+ - test/sample_book/Gemfile
220
+ - test/sample_book/chapters/one.md
221
+ - test/sample_book/chapters/three.md
222
+ - test/sample_book/chapters/two.md
223
+ - test/sample_book/config.yml
224
+ - test/sample_book/outline.txt
225
+ - test/sample_book/templates/layout.xhtml
191
226
  - test/utils/assertions.rb