author 1.1.4.alpha → 1.1.5.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTU2OWU2NjFkNmU1YWRlYmUyMDQ0NDFkYjUwOWY3NzBkZmYyZTdiYw==
4
+ ZDE0ODkwNmFhODlhNDE2Njk1Mjc2Njk5NmZmMGM4ZTZjMjlkYWY3OA==
5
5
  data.tar.gz: !binary |-
6
- NjE3MTA2NjVjOGI5OTZmODI0YTA1NjUxZmYxNTYyZWU3Njc3MTMxMA==
6
+ NTM4MzIyYTY5ZDI0ODk4ZWY5MmI0N2I3NDgzMTljZGM5Mjc2YWY2Yw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTY2Zjc1NTQ4YmRmYmJjZjk1M2ZhMmQxZGVmNzIxYjkwZjRiNzRiNzhiNmI1
10
- NGUxNzdkYjI3NzdiYmRhYzk4ODIxMjU4MzUzNmU2MGJlMWI5Mjg3MzQwNGU5
11
- MjUyZGE0N2E4ZjdjODM3MTc5YzVjNzA4ZWIwM2Y4YjViZGFiOTY=
9
+ YmQ2MWY1OGQzMjczMmE0ODY0ZmI1YjFhNTVlNGZkYmE4NzUxODliZjk2Y2I4
10
+ MmYyMjIzMWFiMGFlNTA3YWIxMzgzZWVlNTk1ZWRhYTM3M2UzYzMxMjI3ZDhm
11
+ MTRiZjliZmUwNTRhZjk1YTBhZTIzN2Q3Y2YyNzdmMjAzZDRjNTY=
12
12
  data.tar.gz: !binary |-
13
- MTEzZGMwNGRkZDMxMzI5ZGI1ZDZhZTAyNjY5YmRjMTYzYWQ4ZWIwZWQwNzZl
14
- NTkzMmE4MzE1Y2Q0YmI2YTM2MDNkOTY4MDNiNDgxMjMzNWYzMzg2YzE2NTg2
15
- MTFmZDY0ZWUzYTgwZTFiOWZhZDkyMWYwNDFkOWNhMzFhNTc0YTg=
13
+ YjAwODA1YzUxNGRmNjVhMzEzOTdiZGRkMjQzMzViMmRkNzQyMGUyMTgxZDA1
14
+ MmM0OGNhOWYyN2Y3MTgwOWMwMWNmODc5NTQyY2RkOTk5ZmFjZTQyM2U1ZWFh
15
+ Y2FhMDI3YWQ5Nzc3N2Q5ZTEzYzBjODYwY2E3MTc5MmVhYmM0MDk=
data/author.gemspec CHANGED
@@ -27,4 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency "liquid"
28
28
  spec.add_dependency "coderay"
29
29
  spec.add_dependency "kramdown"
30
+ spec.add_dependency "safe_yaml"
31
+ spec.add_dependency "eeepub"
32
+ spec.add_dependency "rubyzip"
33
+ spec.add_dependency "zip-zip"
30
34
  end
data/lib/author.rb CHANGED
@@ -15,13 +15,24 @@ require 'liquid'
15
15
  require 'coderay'
16
16
  require 'thor'
17
17
  require 'kramdown'
18
+ require 'safe_yaml'
18
19
 
19
20
  # internals
20
21
  require 'author/version'
22
+ require 'author/utils'
23
+ require 'author/configuration'
21
24
  require_all 'author/commands'
22
25
  require_all 'author/plugins'
23
26
  require_all 'author/exporters'
24
27
 
25
28
  module Author
26
29
 
30
+ def self.configuration(override = nil)
31
+ config = Configuration[Configuration::DEFAULTS]
32
+ override = Configuration[override || config.load_override_file || {}].stringify_keys
33
+ config = Utils.deep_merge_hashes(config, override).stringify_keys
34
+
35
+ config
36
+ end
37
+
27
38
  end
@@ -26,6 +26,14 @@ module Author
26
26
  Author::Exporters::Mobi.export
27
27
  end
28
28
 
29
+ desc "epub", "Build ePub format"
30
+ def epub
31
+ say "Building the XHTML site"
32
+ Author::Exporters::XHTML.export
33
+ say "Building the epub file"
34
+ Author::Exporters::Epub.export
35
+ end
36
+
29
37
  end
30
38
  end
31
39
  end
@@ -5,14 +5,14 @@ module Author
5
5
  class Generator < Thor::Group
6
6
  include Thor::Actions
7
7
 
8
- argument :name
8
+ argument :title
9
9
 
10
10
  def set_destination_root
11
- self.destination_root = File.join(self.destination_root, name)
11
+ self.destination_root = File.join(self.destination_root, title)
12
12
  end
13
13
 
14
14
  def create_project_structure
15
- say "Creating directories for your new book, #{name}"
15
+ say "Creating directories for your new book, #{title}"
16
16
  empty_directory "chapters"
17
17
  empty_directory "export"
18
18
  empty_directory "templates"
@@ -44,6 +44,11 @@ module Author
44
44
  File.join(File.dirname(__FILE__), '..', 'templates')
45
45
  end
46
46
 
47
+ def creator
48
+ creator = `finger $USER 2> /dev/null | grep Login | colrm 1 46 2> /dev/null`.chomp
49
+ !creator.empty? ? creator : "John Doe"
50
+ end
51
+
47
52
  end
48
53
  end
49
54
  end
@@ -0,0 +1,33 @@
1
+ require 'safe_yaml/load'
2
+
3
+ module Author
4
+ class Configuration < Hash
5
+
6
+ DEFAULTS = {
7
+ 'eeepub' => {
8
+ 'title' => nil,
9
+ 'creator' => nil,
10
+ 'publisher' => nil,
11
+ 'date' => nil,
12
+ 'identifier' => nil,
13
+ 'uid' => nil,
14
+ 'files' => [],
15
+ 'nav' => []
16
+ }
17
+ }
18
+
19
+ def stringify_keys
20
+ reduce({}) { |hsh, (k,v)| hsh.merge(k.to_s => v) }
21
+ end
22
+
23
+ def override_config_path
24
+ filepath = File.join(Dir.pwd, 'config.yml')
25
+ File.file?(filepath) ? filepath : nil
26
+ end
27
+
28
+ def load_override_file
29
+ SafeYAML.load_file(override_config_path) if override_config_path
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ require 'eeepub'
2
+
3
+ module Author
4
+ module Exporters
5
+ class Epub < Base
6
+ # 1. check that xhtml file exists
7
+ # 2. check that css file exists
8
+ # 3. create epub
9
+
10
+ def self.export
11
+ exporter = new
12
+ exporter.xhtml_exists?
13
+ exporter.css_exists?
14
+ exporter.export
15
+ end
16
+
17
+ def xhtml_exists?
18
+ raise "No book.xhtml file found" unless File.file?(output_path)
19
+ end
20
+
21
+ def css_exists?
22
+ raise "No book.css file found" unless File.file?(theme_path)
23
+ end
24
+
25
+ def export
26
+ c = config
27
+ f = [output_path, theme_path]
28
+ epub = EeePub.make do
29
+ title c['title']
30
+ creator c['creator']
31
+ publisher c['publisher']
32
+ date c['date']
33
+ identifier c['identifier'], :scheme => 'URL'
34
+ uid c['uid']
35
+ files f
36
+ end
37
+ epub.save(File.join(export_path, 'book.epub'))
38
+ end
39
+
40
+ def config
41
+ Author.configuration.fetch('eeepub')
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -3,7 +3,7 @@ module Author
3
3
  class Mobi < Base
4
4
  # 1. check that kindlegen is installed
5
5
  # 2. check that xhtml file exists
6
- # 4. run kindlegen command
6
+ # 3. run kindlegen command
7
7
 
8
8
  def self.export
9
9
  exporter = new
@@ -1,6 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # gem 'author' # Uncomment this once the gem is published.
4
- gem 'kramdown'
5
- gem 'coderay'
6
- gem 'eeepub'
3
+ gem 'author'
@@ -1,4 +1,8 @@
1
1
  ---
2
- title: <%= name %>
3
- markdown: kramdown
4
- highlighter: coderay
2
+ eeepub:
3
+ title: <%= title %>
4
+ creator: <%= creator %>
5
+ publisher: <%= creator %>
6
+ date: <%= Time.now %>
7
+ identifier: Fill me in
8
+ uid: Fill me in
@@ -2,7 +2,7 @@
2
2
  <html xmlns="http://www.w3.org/1999/xhtml">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
- <title><%= name %></title>
5
+ <title><%= title %></title>
6
6
  <link rel="stylesheet" href="book.css" type="text/css" media="all" title="Default ebook theme" charset="utf-8" />
7
7
  </head>
8
8
  <body>
@@ -1,3 +1,3 @@
1
- # <%= name %>
1
+ # <%= title %>
2
2
 
3
3
  Congratulations! You just created a new ebook project. Now all you need to do is write your book.
@@ -0,0 +1,29 @@
1
+ module Author
2
+ class Utils
3
+
4
+ # Merges a master hash with another hash, recursively.
5
+ #
6
+ # master_hash - the "parent" hash whose values will be overridden
7
+ # other_hash - the other hash whose values will be persisted after the merge
8
+ #
9
+ # This code was lovingly stolen from some random gem:
10
+ # http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html
11
+ #
12
+ # Thanks to whoever made it.
13
+ def self.deep_merge_hashes(master_hash, other_hash)
14
+ target = master_hash.dup
15
+
16
+ other_hash.keys.each do |key|
17
+ if other_hash[key].is_a? Hash and target[key].is_a? Hash
18
+ target[key] = Utils.deep_merge_hashes(target[key], other_hash[key])
19
+ next
20
+ end
21
+
22
+ target[key] = other_hash[key]
23
+ end
24
+
25
+ target
26
+ end
27
+
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Author
2
- VERSION = "1.1.4.alpha"
2
+ VERSION = "1.1.5.alpha"
3
3
  end
@@ -18,4 +18,8 @@ describe Author::Commands::Builder do
18
18
  expect(output).to_include "mobi"
19
19
  end
20
20
 
21
+ it "should respond to epub" do
22
+ expect(output).to_include "epub"
23
+ end
24
+
21
25
  end
@@ -5,7 +5,7 @@ describe Author::Commands::Generator do
5
5
 
6
6
  it "should require a name" do
7
7
  output = capture(:stderr) { Author::Commands::Generator.start }
8
- expect(output).to_include "No value provided for required arguments 'name'"
8
+ expect(output).to_include "No value provided for required arguments 'title'"
9
9
  end
10
10
 
11
11
  it "should create project structure" do
@@ -0,0 +1,37 @@
1
+ require_relative '../helper'
2
+ require 'author/exporters/base'
3
+ require 'author/exporters/epub'
4
+
5
+ describe Author::Exporters::Epub do
6
+
7
+ let(:exporter) { Author::Exporters::Epub }
8
+
9
+ it "should respond to #export" do
10
+ expect(exporter).to_respond_to :export
11
+ end
12
+
13
+ it "should raise error if no book.xhtml file exists" do
14
+ expect { exporter.export }.to_raise RuntimeError
15
+ end
16
+
17
+ it "should raise error if no book.css file exists" do
18
+ expect { exporter.export }.to_raise RuntimeError
19
+ end
20
+
21
+ context "an instance" do
22
+ let(:exporter) { Author::Exporters::Epub.new }
23
+
24
+ it "should respond to #xhtml_exists?" do
25
+ expect(exporter).to_respond_to :xhtml_exists?
26
+ end
27
+
28
+ it "should respond to #css_exists?" do
29
+ expect(exporter).to_respond_to :css_exists?
30
+ end
31
+
32
+ it "should respond to #export" do
33
+ expect(exporter).to_respond_to :export
34
+ end
35
+ end
36
+
37
+ end
@@ -1,4 +1,5 @@
1
1
  ---
2
- title: test/sample_book
3
- markdown: kramdown
4
- highlighter: coderay
2
+ eeepub:
3
+ title: <%= title %>
4
+ creator: <%= creator %>
5
+ publisher: <%= creator %>
@@ -0,0 +1,40 @@
1
+ require_relative '../helper'
2
+ require 'author/configuration'
3
+
4
+ describe Author::Configuration do
5
+
6
+ let(:config) { Author::Configuration }
7
+
8
+ let(:mixed_keys) do
9
+ config[{
10
+ 'foo' => 'bar',
11
+ :source => './'
12
+ }]
13
+ end
14
+
15
+ let(:string_keys) do
16
+ config[{
17
+ 'foo' => 'bar',
18
+ 'source' => './'
19
+ }]
20
+ end
21
+
22
+ it "should stringify keys" do
23
+ expect(mixed_keys.stringify_keys).to_equal string_keys
24
+ end
25
+
26
+ it "should not mess with keys that are already strings" do
27
+ expect(string_keys.stringify_keys).to_equal string_keys
28
+ end
29
+
30
+ it "should know about override config path" do
31
+ expect(string_keys).to_respond_to :override_config_path
32
+ end
33
+
34
+ it "should load config file" do
35
+ inside_sample_book do
36
+ expect(string_keys.load_override_file).to_include "eeepub"
37
+ end
38
+ end
39
+
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: author
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4.alpha
4
+ version: 1.1.5.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terry Schmidt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-25 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,62 @@ dependencies:
122
122
  - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: safe_yaml
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: eeepub
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubyzip
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: zip-zip
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
125
181
  description: Quickly create ebooks using Markdown
126
182
  email:
127
183
  - terry.m.schmidt@gmail.com
@@ -144,7 +200,9 @@ files:
144
200
  - lib/author/commands/cli.rb
145
201
  - lib/author/commands/generator.rb
146
202
  - lib/author/commands/version.rb
203
+ - lib/author/configuration.rb
147
204
  - lib/author/exporters/base.rb
205
+ - lib/author/exporters/epub.rb
148
206
  - lib/author/exporters/mobi.rb
149
207
  - lib/author/exporters/pdf.rb
150
208
  - lib/author/exporters/xhtml.rb
@@ -154,12 +212,14 @@ files:
154
212
  - lib/author/templates/config.yml
155
213
  - lib/author/templates/layout.xhtml
156
214
  - lib/author/templates/sample.md
215
+ - lib/author/utils.rb
157
216
  - lib/author/version.rb
158
217
  - test/commands/builder_test.rb
159
218
  - test/commands/check_test.rb
160
219
  - test/commands/cli_test.rb
161
220
  - test/commands/generator_test.rb
162
221
  - test/commands/version_test.rb
222
+ - test/exporters/epub_test.rb
163
223
  - test/exporters/mobi_test.rb
164
224
  - test/exporters/pdf_test.rb
165
225
  - test/exporters/xhtml_test.rb
@@ -181,6 +241,7 @@ files:
181
241
  - test/sample_book/export/book.xhtml
182
242
  - test/sample_book/outline.txt
183
243
  - test/sample_book/templates/layout.xhtml
244
+ - test/units/configuration_test.rb
184
245
  - test/utils/assertions.rb
185
246
  homepage: http://github.com/tschmidt/author
186
247
  licenses:
@@ -212,6 +273,7 @@ test_files:
212
273
  - test/commands/cli_test.rb
213
274
  - test/commands/generator_test.rb
214
275
  - test/commands/version_test.rb
276
+ - test/exporters/epub_test.rb
215
277
  - test/exporters/mobi_test.rb
216
278
  - test/exporters/pdf_test.rb
217
279
  - test/exporters/xhtml_test.rb
@@ -233,4 +295,5 @@ test_files:
233
295
  - test/sample_book/export/book.xhtml
234
296
  - test/sample_book/outline.txt
235
297
  - test/sample_book/templates/layout.xhtml
298
+ - test/units/configuration_test.rb
236
299
  - test/utils/assertions.rb