softcover 0.6.10 → 0.7.0
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 +4 -4
- data/.gitignore +1 -0
- data/.pull_requests/1385834422 +0 -0
- data/.pull_requests/1385835007 +0 -0
- data/.pull_requests/1385862948 +0 -0
- data/.pull_requests/1386099285 +0 -0
- data/.pull_requests/1386115582 +0 -0
- data/lib/softcover/book_manifest.rb +9 -8
- data/lib/softcover/builders/html.rb +4 -25
- data/lib/softcover/builders/pdf.rb +14 -7
- data/lib/softcover/cli.rb +1 -8
- data/lib/softcover/commands/generator.rb +3 -13
- data/lib/softcover/commands/opener.rb +5 -1
- data/lib/softcover/commands/server.rb +4 -2
- data/lib/softcover/template/book.yml.erb +4 -3
- data/lib/softcover/template/softcover.sty +10 -0
- data/lib/softcover/utils.rb +64 -0
- data/lib/softcover/version.rb +1 -1
- data/softcover.gemspec +2 -2
- data/spec/app_spec.rb +0 -20
- data/spec/book_manifest_spec.rb +3 -3
- data/spec/builders/html_spec.rb +16 -1
- data/spec/builders/pdf_spec.rb +8 -0
- data/spec/cli_spec.rb +21 -1
- data/spec/commands/generator_spec.rb +5 -147
- data/spec/spec_helper.rb +1 -1
- data/spec/webmock_helpers.rb +0 -1
- metadata +12 -11
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/lib/softcover/template/book.tex +0 -21
- data/lib/softcover/template/simple_book.tex +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61bd49f3b8a3353e6ec2337fdbb106034190e783
|
4
|
+
data.tar.gz: fb0e6e1d6f0a088cbec3e16e2202fce24446aa5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7320553767b7915b937bc88d4cbec6c909d17d7aa99b4c874b8d07f6453a35bd682ffb07a4c52d0a228a38875fd3b5c6e1d4ecca86bf2b2e38f644d4ab0553e9
|
7
|
+
data.tar.gz: 221b381059780a02c6da6fcc7381c52e1baf8d209aba80eeab0a0aa4fdc4d17d87dfcf327e859280c3b44928d6d9f8199b7fe290c93c79ccfd604c2562de66f7
|
data/.gitignore
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -54,7 +54,7 @@ class Softcover::BookManifest < OpenStruct
|
|
54
54
|
class Section < OpenStruct
|
55
55
|
end
|
56
56
|
|
57
|
-
|
57
|
+
TXT_PATH = 'Book.txt'
|
58
58
|
YAML_PATH = "book.yml"
|
59
59
|
|
60
60
|
def initialize(options = {})
|
@@ -70,6 +70,8 @@ class Softcover::BookManifest < OpenStruct
|
|
70
70
|
|
71
71
|
marshal_load attrs
|
72
72
|
|
73
|
+
write_master_latex_file(self)
|
74
|
+
|
73
75
|
if polytex?
|
74
76
|
tex_filename = filename + '.tex'
|
75
77
|
self.chapters = []
|
@@ -88,18 +90,17 @@ class Softcover::BookManifest < OpenStruct
|
|
88
90
|
else
|
89
91
|
self.frontmatter = []
|
90
92
|
end
|
91
|
-
self.author = base_contents.scan(/^\s*\\author\{(.*?)\}/).flatten.first
|
92
93
|
chapter_includes(base_contents).each_with_index do |name, i|
|
93
94
|
slug = File.basename(name, '.*')
|
94
|
-
|
95
|
+
chapter_title_regex = /^\s*\\chapter{(.*)}/
|
95
96
|
content = File.read(File.join(polytex_dir, slug + '.tex'))
|
96
|
-
|
97
|
+
chapter_title = content[chapter_title_regex, 1]
|
97
98
|
j = 0
|
98
99
|
sections = content.scan(/^\s*\\section{(.*)}/).flatten.map do |name|
|
99
100
|
Section.new(name: name, section_number: j += 1)
|
100
101
|
end
|
101
102
|
chapters.push Chapter.new(slug: slug,
|
102
|
-
title:
|
103
|
+
title: chapter_title,
|
103
104
|
sections: sections,
|
104
105
|
chapter_number: i + 1)
|
105
106
|
end
|
@@ -224,7 +225,7 @@ class Softcover::BookManifest < OpenStruct
|
|
224
225
|
end
|
225
226
|
|
226
227
|
def self.valid_directory?
|
227
|
-
[YAML_PATH,
|
228
|
+
[YAML_PATH, TXT_PATH].any? { |f| File.exist?(f) }
|
228
229
|
end
|
229
230
|
|
230
231
|
# Changes the directory until in the book's root directory.
|
@@ -245,7 +246,7 @@ class Softcover::BookManifest < OpenStruct
|
|
245
246
|
def source_files
|
246
247
|
self.class.find_book_root!
|
247
248
|
md_tex = /.*(?:\.md|\.tex)/
|
248
|
-
File.readlines(
|
249
|
+
File.readlines(TXT_PATH).select { |path| path =~ md_tex }.map(&:strip)
|
249
250
|
end
|
250
251
|
|
251
252
|
def basenames
|
@@ -263,7 +264,7 @@ class Softcover::BookManifest < OpenStruct
|
|
263
264
|
end
|
264
265
|
|
265
266
|
def read_from_md
|
266
|
-
{ chapters: chapter_objects, filename:
|
267
|
+
{ chapters: chapter_objects, filename: TXT_PATH }
|
267
268
|
end
|
268
269
|
|
269
270
|
|
@@ -3,6 +3,7 @@ require 'fileutils'
|
|
3
3
|
module Softcover
|
4
4
|
module Builders
|
5
5
|
class Html < Builder
|
6
|
+
include Softcover::Utils
|
6
7
|
|
7
8
|
def setup
|
8
9
|
Dir.mkdir "html" unless File.directory?("html")
|
@@ -18,6 +19,8 @@ module Softcover
|
|
18
19
|
RubyProf.start
|
19
20
|
end
|
20
21
|
|
22
|
+
write_master_latex_file(manifest)
|
23
|
+
|
21
24
|
if manifest.markdown?
|
22
25
|
unless options[:'find-overfull']
|
23
26
|
FileUtils.rm(Dir.glob(path("#{manifest.polytex_dir}/*.tex")))
|
@@ -25,7 +28,7 @@ module Softcover
|
|
25
28
|
manifest.chapters.each do |chapter|
|
26
29
|
write_latex_files(chapter, options)
|
27
30
|
end
|
28
|
-
|
31
|
+
|
29
32
|
# Reset the manifest to use PolyTeX.
|
30
33
|
self.manifest = Softcover::BookManifest.new(source: :polytex,
|
31
34
|
verify_paths: false,
|
@@ -66,30 +69,6 @@ module Softcover
|
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
69
|
-
# Rewrites the master LaTeX file <name>.tex to use chapters from Book.txt.
|
70
|
-
def rewrite_master_latex_file
|
71
|
-
master_filename = Dir['*.tex'].reject { |f| f =~ /\.tmp/}.first
|
72
|
-
lines = File.readlines('Book.txt')
|
73
|
-
tex_file = []
|
74
|
-
lines.each do |line|
|
75
|
-
if line =~ /(.*)(?:\.md|\.tex)\s*$/
|
76
|
-
tex_file << "\\include{#{manifest.polytex_dir}/#{$1}}"
|
77
|
-
elsif line =~ /(.*):\s*$/ # frontmatter or mainmatter
|
78
|
-
tex_file << "\\#{$1}"
|
79
|
-
elsif line.strip == 'cover'
|
80
|
-
tex_file << '\\includepdf{images/cover.pdf}'
|
81
|
-
else # raw command, like 'maketitle' or 'tableofcontents'
|
82
|
-
tex_file << "\\#{line.strip}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
tex_file << '\end{document}'
|
86
|
-
content = File.read(master_filename)
|
87
|
-
content.gsub!(/(\\begin{document}\n)(.*)/m) do
|
88
|
-
$1 + tex_file.join("\n") + "\n"
|
89
|
-
end
|
90
|
-
File.write(master_filename, content)
|
91
|
-
end
|
92
|
-
|
93
72
|
# Returns the converted HTML.
|
94
73
|
def converted_html(basename)
|
95
74
|
polytex_filename = basename + '.tex'
|
@@ -2,6 +2,7 @@ module Softcover
|
|
2
2
|
module Builders
|
3
3
|
class Pdf < Builder
|
4
4
|
include Softcover::Output
|
5
|
+
include Softcover::Utils
|
5
6
|
|
6
7
|
def build!(options={})
|
7
8
|
if manifest.markdown?
|
@@ -12,6 +13,9 @@ module Softcover
|
|
12
13
|
self.manifest = Softcover::BookManifest.new(source: :polytex,
|
13
14
|
origin: :markdown)
|
14
15
|
end
|
16
|
+
|
17
|
+
write_master_latex_file(manifest)
|
18
|
+
|
15
19
|
# Build the PolyTeX filename so it accepts both 'foo' and 'foo.tex'.
|
16
20
|
basename = File.basename(manifest.filename, '.tex')
|
17
21
|
book_filename = basename + '.tex'
|
@@ -22,16 +26,17 @@ module Softcover
|
|
22
26
|
return # only gets called in test env
|
23
27
|
elsif options[:'find-overfull']
|
24
28
|
tmp_name = book_filename.sub('.tex', '.tmp.tex')
|
25
|
-
# The we do things, code listings show up as "Overfull", but
|
26
|
-
# actually fine, so filter them out.
|
29
|
+
# The way we do things, code listings show up as "Overfull", but
|
30
|
+
# they're actually fine, so filter them out.
|
27
31
|
filter_out_listings = "grep -v 3.22281pt"
|
28
|
-
#
|
32
|
+
# Because each chapter typically lives in a separate file, it's
|
33
|
+
# hard to correlate Overfull line numbers with lines in the source,
|
29
34
|
# so we use grep's -A flag to provide some context instead. Authors
|
30
|
-
# can then use their text editors to find the
|
31
|
-
# in the text.
|
35
|
+
# can then use their text editors' search function to find the
|
36
|
+
# corresponding place in the text.
|
32
37
|
show_context = 'grep -A 3 "Overfull \hbox"'
|
33
38
|
cmd = "xelatex #{tmp_name} | #{filter_out_listings} | #{show_context}"
|
34
|
-
execute cmd
|
39
|
+
silence_stream(STDERR) { execute cmd }
|
35
40
|
return
|
36
41
|
end
|
37
42
|
|
@@ -66,7 +71,9 @@ module Softcover
|
|
66
71
|
# Here we use `system` when making a preview because the preview command
|
67
72
|
# needs to run after the main PDF build.
|
68
73
|
if options[:quiet] || options[:silent]
|
69
|
-
|
74
|
+
silence_stream(STDERR) do
|
75
|
+
silence { options[:preview] ? system(cmd) : execute(cmd) }
|
76
|
+
end
|
70
77
|
else
|
71
78
|
options[:preview] ? system(cmd) : execute(cmd)
|
72
79
|
end
|
data/lib/softcover/cli.rb
CHANGED
@@ -144,9 +144,7 @@ module Softcover
|
|
144
144
|
require 'softcover/commands/publisher'
|
145
145
|
|
146
146
|
invoke :login unless logged_in?
|
147
|
-
|
148
|
-
slug = Softcover::BookManifest.new.slug
|
149
|
-
if ask("Type '#{slug}' to unpublish:") == slug
|
147
|
+
if ask("Type '#{unpublish_slug}' to unpublish:") == unpublish_slug
|
150
148
|
puts "Unpublishing..." unless options[:silent]
|
151
149
|
Softcover::Commands::Publisher.unpublish!
|
152
150
|
else
|
@@ -172,11 +170,6 @@ module Softcover
|
|
172
170
|
:default => false,
|
173
171
|
:aliases => "-p",
|
174
172
|
:desc => "Generate a PolyTeX book."
|
175
|
-
method_option :simple,
|
176
|
-
:type => :boolean,
|
177
|
-
:default => false,
|
178
|
-
:aliases => "-s",
|
179
|
-
:desc => "Generate a simple book."
|
180
173
|
def new(n)
|
181
174
|
Softcover::Commands::Generator.generate_file_tree(n, options)
|
182
175
|
end
|
@@ -9,7 +9,6 @@ module Softcover
|
|
9
9
|
def generate_file_tree(name, options = {})
|
10
10
|
@name = name
|
11
11
|
@markdown = !options[:polytex]
|
12
|
-
@simple = options[:simple]
|
13
12
|
|
14
13
|
thor = Thor::Shell::Basic.new
|
15
14
|
|
@@ -25,8 +24,6 @@ module Softcover
|
|
25
24
|
# file before the directory had been created, so we now create all
|
26
25
|
# the directories first.
|
27
26
|
directories.each do |path|
|
28
|
-
next if path =~ /\/simple_book/ && !@simple
|
29
|
-
next if path =~ /\/book/ && @simple
|
30
27
|
(cp_path = path.dup).slice! template_dir + "/"
|
31
28
|
unless File.exist?(cp_path)
|
32
29
|
puts "Creating #{cp_path}" unless cp_path =~ /MathJax/
|
@@ -87,16 +84,9 @@ module Softcover
|
|
87
84
|
File.expand_path File.join File.dirname(__FILE__), "../template"
|
88
85
|
end
|
89
86
|
|
90
|
-
# Returns true for a simple book (no frontmatter, etc.).
|
91
|
-
def simple?
|
92
|
-
@simple
|
93
|
-
end
|
94
|
-
|
95
87
|
# Returns a list of all the files and directories used to build the book.
|
96
88
|
def all_files_and_directories
|
97
|
-
|
98
|
-
simple? ? f.reject { |p| p =~ /\/book\.tex/ || p =~ /preface/ }
|
99
|
-
: f.reject { |p| p =~ /simple/ }
|
89
|
+
files_directories_maybe_markdown
|
100
90
|
end
|
101
91
|
|
102
92
|
# Returns the files and directories based on the input format.
|
@@ -106,8 +96,8 @@ module Softcover
|
|
106
96
|
# Skip the PolyTeX chapter files, which will be generated later.
|
107
97
|
fds.reject { |e| e =~ /\/chapters\/.*\.tex/ }
|
108
98
|
else
|
109
|
-
# Skip the Markdown files
|
110
|
-
fds.reject { |e| e =~ /
|
99
|
+
# Skip the Markdown files.
|
100
|
+
fds.reject { |e| e =~ /chapters\/.*\.md/ }
|
111
101
|
end
|
112
102
|
end
|
113
103
|
|
@@ -29,7 +29,9 @@ module Softcover::Commands::Server
|
|
29
29
|
ignores = ['generated_polytex', '\.tmp\.tex']
|
30
30
|
# Ignore <book>.tex, which gets overwritten each time PolyTeXnic runs,
|
31
31
|
# unless there's no Book.txt, which means the author is using raw LaTeX.
|
32
|
-
|
32
|
+
if File.exist?(Softcover::BookManifest::TXT_PATH)
|
33
|
+
ignores << Regexp.escape(Dir.glob('*.tex').first)
|
34
|
+
end
|
33
35
|
/(#{ignores.join('|')})/
|
34
36
|
end
|
35
37
|
|
@@ -51,13 +53,13 @@ module Softcover::Commands::Server
|
|
51
53
|
|
52
54
|
def start_server(port)
|
53
55
|
require 'softcover/server/app'
|
54
|
-
rebuild
|
55
56
|
puts "Running Softcover server on http://localhost:#{port}"
|
56
57
|
Softcover::App.set :port, port
|
57
58
|
Softcover::App.run!
|
58
59
|
end
|
59
60
|
|
60
61
|
def run(port)
|
62
|
+
rebuild
|
61
63
|
listen_for_changes
|
62
64
|
start_server port
|
63
65
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
---
|
2
|
-
title: <%= name %>
|
3
2
|
slug: <%= name %>
|
4
3
|
filename: <%= name %>
|
5
|
-
|
6
|
-
|
4
|
+
title: Title of the Book
|
5
|
+
subtitle: Change me
|
7
6
|
description: Change me.
|
7
|
+
author: Author Name
|
8
8
|
copyright: <%= Time.new.year %>
|
9
9
|
uuid: <%= SecureRandom.uuid %>
|
10
|
+
cover: images/cover.png
|
10
11
|
pdf_preview_page_range: 1..30
|
11
12
|
epub_mobi_preview_chapter_range: 0..1
|
@@ -130,5 +130,15 @@
|
|
130
130
|
\newcommand{\heading}[1]{\textbf{#1}}
|
131
131
|
\newcommand{\kode}[1]{\textcolor{darkgreen}{\textbf{\texttt{#1}}}}
|
132
132
|
|
133
|
+
% Subtitle command
|
134
|
+
\usepackage{titling}
|
135
|
+
\newcommand{\subtitle}[1]{%
|
136
|
+
\posttitle{%
|
137
|
+
\par\end{center}
|
138
|
+
\begin{center}\large#1\end{center}
|
139
|
+
\vskip0.5em}%
|
140
|
+
}
|
141
|
+
|
133
142
|
% Add custom commands
|
134
143
|
\usepackage{custom}
|
144
|
+
|
data/lib/softcover/utils.rb
CHANGED
@@ -13,6 +13,11 @@ module Softcover::Utils
|
|
13
13
|
Dir.glob(path('chapters/*.md')).empty? ? :polytex : :markdown
|
14
14
|
end
|
15
15
|
|
16
|
+
# Returns the slug to be unpublished.
|
17
|
+
def unpublish_slug
|
18
|
+
Softcover::BookManifest.new(origin: source).slug
|
19
|
+
end
|
20
|
+
|
16
21
|
def reset_current_book!
|
17
22
|
@@current_book = nil
|
18
23
|
end
|
@@ -54,6 +59,65 @@ module Softcover::Utils
|
|
54
59
|
"#{number.round} #{UNITS[ exponent ]}"
|
55
60
|
end
|
56
61
|
|
62
|
+
|
63
|
+
# Writes the master LaTeX file <name>.tex to use chapters from Book.txt.
|
64
|
+
# We skip this step if Book.txt doesn't exist, as that means the user
|
65
|
+
# is writing raw LaTeX.
|
66
|
+
def write_master_latex_file(manifest)
|
67
|
+
if File.exist?(Softcover::BookManifest::TXT_PATH)
|
68
|
+
File.write(master_filename(manifest), master_content(manifest))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns the name of the master LaTeX file.
|
73
|
+
def master_filename(manifest)
|
74
|
+
"#{manifest.filename}.tex"
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns the lines of Book.txt as an array.
|
78
|
+
def book_txt_lines
|
79
|
+
File.readlines(Softcover::BookManifest::TXT_PATH)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Returns the content for the master LaTeX file.
|
83
|
+
def master_content(manifest)
|
84
|
+
comment = /^\s*#.*$/
|
85
|
+
front_or_mainmatter = /(.*):\s*$/
|
86
|
+
source_file = /(.*)(?:\.md|\.tex)\s*$/
|
87
|
+
|
88
|
+
tex_file = [master_latex_header(manifest)]
|
89
|
+
book_txt_lines.each do |line|
|
90
|
+
if line.match(comment) # commented-out line
|
91
|
+
next
|
92
|
+
elsif line.match(source_file)
|
93
|
+
tex_file << "\\include{#{manifest.polytex_dir}/#{$1}}"
|
94
|
+
elsif line.match(front_or_mainmatter) # frontmatter or mainmatter
|
95
|
+
tex_file << "\\#{$1}"
|
96
|
+
elsif line.strip == 'cover'
|
97
|
+
tex_file << '\\includepdf{images/cover.pdf}'
|
98
|
+
else # raw command, like 'maketitle' or 'tableofcontents'
|
99
|
+
tex_file << "\\#{line.strip}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
tex_file << '\end{document}'
|
103
|
+
tex_file.join("\n")
|
104
|
+
end
|
105
|
+
|
106
|
+
def master_latex_header(manifest)
|
107
|
+
subtitle = manifest.subtitle.nil? ? "" : "\\subtitle{#{manifest.subtitle}}"
|
108
|
+
<<-EOS
|
109
|
+
\\documentclass[14pt]{extbook}
|
110
|
+
\\usepackage{softcover}
|
111
|
+
\\VerbatimFootnotes % Allows verbatim text in footnotes
|
112
|
+
\\title{#{manifest.title}}
|
113
|
+
#{subtitle}
|
114
|
+
\\author{#{manifest.author}}
|
115
|
+
\\date{#{manifest.date}}
|
116
|
+
|
117
|
+
\\begin{document}
|
118
|
+
EOS
|
119
|
+
end
|
120
|
+
|
57
121
|
# Returns the tmp version of a filename.
|
58
122
|
# E.g., tmpify('foo.tex') => 'foo.tmp.tex'
|
59
123
|
def tmpify(manifest, filename)
|
data/lib/softcover/version.rb
CHANGED
data/softcover.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_dependency 'polytexnic', '~> 0.
|
21
|
+
gem.add_dependency 'polytexnic', '~> 0.7.0'
|
22
22
|
gem.add_dependency 'msgpack', '~> 0.4.2'
|
23
|
-
gem.add_dependency 'nokogiri', '~> 1.
|
23
|
+
gem.add_dependency 'nokogiri', '~> 1.6.0'
|
24
24
|
gem.add_dependency 'thor'
|
25
25
|
gem.add_dependency 'activesupport'
|
26
26
|
gem.add_dependency 'rest-client'
|
data/spec/app_spec.rb
CHANGED
@@ -77,24 +77,4 @@ describe Softcover::App do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
81
|
-
context "simple book" do
|
82
|
-
before(:all) do
|
83
|
-
generate_book(simple: true)
|
84
|
-
Softcover::Builders::Html.new.build!
|
85
|
-
end
|
86
|
-
after(:all) { remove_book }
|
87
|
-
|
88
|
-
before { chdir_to_book }
|
89
|
-
|
90
|
-
let(:manifest) { Softcover::BookManifest.new }
|
91
|
-
let(:chapter) { manifest.chapters[0] }
|
92
|
-
|
93
|
-
it 'redirects / to first chapter' do
|
94
|
-
get '/'
|
95
|
-
expect(last_response).to be_redirect
|
96
|
-
expect(last_response.location).to match chapter.slug
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
80
|
end
|
data/spec/book_manifest_spec.rb
CHANGED
@@ -9,8 +9,8 @@ describe Softcover::BookManifest do
|
|
9
9
|
context "in valid book directory" do
|
10
10
|
|
11
11
|
describe "basic information" do
|
12
|
-
its(:title) { should eq "
|
13
|
-
its(:subtitle) { should eq "Change
|
12
|
+
its(:title) { should eq "Title of the Book" }
|
13
|
+
its(:subtitle) { should eq "Change me" }
|
14
14
|
its(:description) { should eq "Change me." }
|
15
15
|
its(:cover) { should eq "images/cover.png" }
|
16
16
|
its(:author) { should eq "Author Name" }
|
@@ -45,7 +45,7 @@ describe Softcover::BookManifest do
|
|
45
45
|
context "in a valid book subdirectory" do
|
46
46
|
before { Dir.chdir 'chapters' }
|
47
47
|
describe "finding the manifest in a higher directory" do
|
48
|
-
its(:
|
48
|
+
its(:slug) { should eq "book" }
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
data/spec/builders/html_spec.rb
CHANGED
@@ -124,14 +124,29 @@ describe Softcover::Builders::Html do
|
|
124
124
|
end
|
125
125
|
|
126
126
|
describe "master LaTeX file" do
|
127
|
-
let(:master_file) {
|
127
|
+
let(:master_file) { builder.master_filename(builder.manifest) }
|
128
128
|
subject { File.read(master_file) }
|
129
|
+
it { should include "\\title{#{builder.manifest.title}}" }
|
130
|
+
it { should include "\\subtitle{#{builder.manifest.subtitle}}" }
|
131
|
+
it { should include "\\author{#{builder.manifest.author}}" }
|
132
|
+
it { should include '\date{}' }
|
133
|
+
it { should include '\begin{document}' }
|
129
134
|
it { should include '\include{generated_polytex/preface}' }
|
130
135
|
it { should include '\include{generated_polytex/a_chapter}' }
|
131
136
|
it { should include '\include{generated_polytex/another_chapter}' }
|
132
137
|
it { should include '\include{generated_polytex/yet_another_chapter}' }
|
133
138
|
it { should include '\end{document}' }
|
134
139
|
end
|
140
|
+
|
141
|
+
describe "commented-out lines of Book.txt" do
|
142
|
+
let(:lines) { ['chapters/foo.md', '# chapters/bar.md'] }
|
143
|
+
let(:content) { builder.master_content(builder.manifest) }
|
144
|
+
before { builder.stub(:book_txt_lines).and_return(lines) }
|
145
|
+
it "should be ignored" do
|
146
|
+
expect(content).to include 'chapters/foo'
|
147
|
+
expect(content).not_to include 'chapters/bar'
|
148
|
+
end
|
149
|
+
end
|
135
150
|
end
|
136
151
|
end
|
137
152
|
end
|
data/spec/builders/pdf_spec.rb
CHANGED
@@ -43,6 +43,14 @@ describe Softcover::Builders::Pdf do
|
|
43
43
|
it "should write the correct PolyTeXnic commands file" do
|
44
44
|
expect(File.read('polytexnic_commands.sty')).to match /newcommand/
|
45
45
|
end
|
46
|
+
|
47
|
+
context "after removing Book.txt" do
|
48
|
+
before { FileUtils.rm Softcover::BookManifest::TXT_PATH }
|
49
|
+
it "should still build the book" do
|
50
|
+
expect(Softcover::BookManifest::TXT_PATH).not_to exist
|
51
|
+
expect { @builder.build! }.not_to raise_error
|
52
|
+
end
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
data/spec/cli_spec.rb
CHANGED
@@ -36,7 +36,6 @@ describe Softcover::CLI do
|
|
36
36
|
context "softcover new options" do
|
37
37
|
subject { `softcover help new` }
|
38
38
|
it { should include '-p, [--polytex]' }
|
39
|
-
it { should include '-s, [--simple]' }
|
40
39
|
end
|
41
40
|
|
42
41
|
context "softcover new" do
|
@@ -127,4 +126,25 @@ describe Softcover::CLI do
|
|
127
126
|
|
128
127
|
it_should_behave_like "book"
|
129
128
|
end
|
129
|
+
|
130
|
+
describe "stubbed commands" do
|
131
|
+
|
132
|
+
context "unpublish" do
|
133
|
+
before { Softcover::Utils.stub(:source).and_return(:markdown) }
|
134
|
+
it "should have the right slug" do
|
135
|
+
Softcover::BookManifest.should_receive(:new).with(origin: :markdown)
|
136
|
+
.and_return(OpenStruct.new(slug: ""))
|
137
|
+
Softcover::Utils.unpublish_slug
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
context "open" do
|
143
|
+
before { Softcover::Utils.stub(:source).and_return(:markdown) }
|
144
|
+
it "should have the right book" do
|
145
|
+
Softcover::Book.should_receive(:new).with(origin: :markdown)
|
146
|
+
Softcover::Commands::Opener::book
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
130
150
|
end
|
@@ -29,7 +29,7 @@ describe Softcover::Commands::Generator do
|
|
29
29
|
subject(:yml) { YAML.load_file(File.join name, 'book.yml') }
|
30
30
|
|
31
31
|
it "should have the right title" do
|
32
|
-
expect(yml['title']).to eq
|
32
|
+
expect(yml['title']).to eq "Title of the Book"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should have the right copyright year" do
|
@@ -49,19 +49,15 @@ describe Softcover::Commands::Generator do
|
|
49
49
|
expect { `softcover build` }.not_to raise_error
|
50
50
|
end
|
51
51
|
|
52
|
-
describe "base LaTeX file" do
|
53
|
-
subject(:base) { 'foo_bar.tex' }
|
54
|
-
it { should exist }
|
55
|
-
it "should use the 14-point extbook doctype" do
|
56
|
-
expect(File.read(base)).to match(/\[14pt\]\{extbook\}/)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
52
|
it "should have chapter files" do
|
61
53
|
expect('chapters/a_chapter.tex').to exist
|
62
54
|
expect('chapters/another_chapter.tex').to exist
|
63
55
|
end
|
64
56
|
|
57
|
+
it "should have Book.txt" do
|
58
|
+
expect(Softcover::BookManifest::TXT_PATH).to exist
|
59
|
+
end
|
60
|
+
|
65
61
|
it "should not have the markdown files" do
|
66
62
|
expect('chapters/a_chapter.md').not_to exist
|
67
63
|
end
|
@@ -108,20 +104,6 @@ describe Softcover::Commands::Generator do
|
|
108
104
|
it "should have a right style file" do
|
109
105
|
expect('softcover.sty').to exist
|
110
106
|
end
|
111
|
-
|
112
|
-
it "should include the right style file by default" do
|
113
|
-
book_base = File.read('foo_bar.tex')
|
114
|
-
expect(book_base).to match(/^\\usepackage{softcover}/)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "base LaTeX file" do
|
119
|
-
subject { File.read('foo_bar.tex') }
|
120
|
-
|
121
|
-
it { should match(/\\include{chapters\/a_chapter}/) }
|
122
|
-
it { should match(/\\include{chapters\/another_chapter}/) }
|
123
|
-
it { should match(/\\title{.*?}/) }
|
124
|
-
it { should match(/\\author{.*?}/) }
|
125
107
|
end
|
126
108
|
|
127
109
|
shared_examples "a chapter" do
|
@@ -140,128 +122,4 @@ describe Softcover::Commands::Generator do
|
|
140
122
|
end
|
141
123
|
end
|
142
124
|
end
|
143
|
-
|
144
|
-
context "generate simple book_base in non-book directory" do
|
145
|
-
|
146
|
-
before(:all) do
|
147
|
-
chdir_to_non_book
|
148
|
-
@name = 'foo_bar'
|
149
|
-
Softcover::Commands::Generator.generate_file_tree @name, simple: true,
|
150
|
-
polytex: true
|
151
|
-
end
|
152
|
-
|
153
|
-
let(:name) { @name }
|
154
|
-
|
155
|
-
before do
|
156
|
-
chdir_to_non_book
|
157
|
-
end
|
158
|
-
|
159
|
-
after(:all) do
|
160
|
-
chdir_to_non_book
|
161
|
-
FileUtils.rm_rf name
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should copy files" do
|
165
|
-
expect(Softcover::Commands::Generator.verify!).to be_true
|
166
|
-
end
|
167
|
-
|
168
|
-
context "generated contents from template" do
|
169
|
-
|
170
|
-
before { Dir.chdir(name) }
|
171
|
-
|
172
|
-
it "should build all formats without error" do
|
173
|
-
expect { `softcover build` }.not_to raise_error
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "base LaTeX file" do
|
177
|
-
subject(:base) { 'foo_bar.tex' }
|
178
|
-
it { should exist }
|
179
|
-
|
180
|
-
describe "contents" do
|
181
|
-
subject(:text) { File.read(base) }
|
182
|
-
it { should match /\[14pt\]\{extbook\}/ }
|
183
|
-
it { should_not match /frontmatter/ }
|
184
|
-
it { should_not match /mainmatter/ }
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
it "should have chapter files" do
|
189
|
-
expect('chapters/a_chapter.tex').to exist
|
190
|
-
expect('chapters/another_chapter.tex').to exist
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should not have preface file" do
|
194
|
-
expect('chapters/preface.tex').not_to exist
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
context "generate Markdown book in non-book directory" do
|
200
|
-
|
201
|
-
before(:all) do
|
202
|
-
chdir_to_non_book
|
203
|
-
@name = 'foo_bar'
|
204
|
-
Softcover::Commands::Generator.generate_file_tree @name
|
205
|
-
end
|
206
|
-
|
207
|
-
let(:name) { @name }
|
208
|
-
|
209
|
-
before do
|
210
|
-
chdir_to_non_book
|
211
|
-
end
|
212
|
-
|
213
|
-
after(:all) do
|
214
|
-
chdir_to_non_book
|
215
|
-
FileUtils.rm_rf name
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should copy files" do
|
219
|
-
expect(Softcover::Commands::Generator.verify!).to be_true
|
220
|
-
end
|
221
|
-
|
222
|
-
context "generated contents from template" do
|
223
|
-
|
224
|
-
before { Dir.chdir(name) }
|
225
|
-
|
226
|
-
it "should build all formats without error" do
|
227
|
-
expect { `softcover build` }.not_to raise_error
|
228
|
-
end
|
229
|
-
|
230
|
-
describe "base LaTeX file" do
|
231
|
-
subject(:base) { 'foo_bar.tex' }
|
232
|
-
it { should exist }
|
233
|
-
it "should use the 14-point extbook doctype" do
|
234
|
-
expect(File.read(base)).to match(/\[14pt\]\{extbook\}/)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should have the markdown files" do
|
239
|
-
expect('chapters/a_chapter.md').to exist
|
240
|
-
expect('chapters/another_chapter.md').to exist
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context "overwriting" do
|
246
|
-
let(:name) { 'bar' }
|
247
|
-
before do
|
248
|
-
chdir_to_non_book
|
249
|
-
$stdin.should_receive(:gets).and_return("a")
|
250
|
-
|
251
|
-
silence do
|
252
|
-
2.times do
|
253
|
-
Softcover::Commands::Generator.generate_file_tree name, polytex: true
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
after do
|
259
|
-
chdir_to_non_book
|
260
|
-
FileUtils.rm_rf name
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should overwrite files" do
|
264
|
-
expect(Softcover::Commands::Generator.verify!).to be_true
|
265
|
-
end
|
266
|
-
end
|
267
125
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/webmock_helpers.rb
CHANGED
@@ -160,7 +160,6 @@ module WebmockHelpers
|
|
160
160
|
Dir.chdir File.join File.dirname(__FILE__), "fixtures/"
|
161
161
|
flags = []
|
162
162
|
flags << '-p' unless options[:markdown]
|
163
|
-
flags << '-s' if options[:simple]
|
164
163
|
silence { system "softcover new #{name} #{flags.join(' ')}" }
|
165
164
|
chdir_to_book
|
166
165
|
File.mkdir 'html' unless File.exist?('html')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: softcover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hartl
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polytexnic
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.7.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.
|
27
|
+
version: 0.7.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: msgpack
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - ~>
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 1.
|
48
|
+
version: 1.6.0
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 1.6.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: thor
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -368,9 +368,12 @@ files:
|
|
368
368
|
- .pull_requests/1385518404
|
369
369
|
- .pull_requests/1385766008
|
370
370
|
- .pull_requests/1385778329
|
371
|
+
- .pull_requests/1385834422
|
372
|
+
- .pull_requests/1385835007
|
373
|
+
- .pull_requests/1385862948
|
374
|
+
- .pull_requests/1386099285
|
375
|
+
- .pull_requests/1386115582
|
371
376
|
- .rspec
|
372
|
-
- .ruby-gemset
|
373
|
-
- .ruby-version
|
374
377
|
- Gemfile
|
375
378
|
- LICENSE.txt
|
376
379
|
- README.md
|
@@ -415,7 +418,6 @@ files:
|
|
415
418
|
- lib/softcover/template/.softcover-deploy
|
416
419
|
- lib/softcover/template/Book.txt
|
417
420
|
- lib/softcover/template/README.md
|
418
|
-
- lib/softcover/template/book.tex
|
419
421
|
- lib/softcover/template/book.yml.erb
|
420
422
|
- lib/softcover/template/chapters/a_chapter.md
|
421
423
|
- lib/softcover/template/chapters/a_chapter.tex
|
@@ -977,7 +979,6 @@ files:
|
|
977
979
|
- lib/softcover/template/images/cover.png
|
978
980
|
- lib/softcover/template/images/figures/.gitkeep
|
979
981
|
- lib/softcover/template/polytexnic_commands.sty
|
980
|
-
- lib/softcover/template/simple_book.tex
|
981
982
|
- lib/softcover/template/softcover.sty
|
982
983
|
- lib/softcover/template/upquote.sty
|
983
984
|
- lib/softcover/uploader.rb
|
@@ -1028,7 +1029,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1028
1029
|
version: '0'
|
1029
1030
|
requirements: []
|
1030
1031
|
rubyforge_project:
|
1031
|
-
rubygems_version: 2.0.
|
1032
|
+
rubygems_version: 2.0.14
|
1032
1033
|
signing_key:
|
1033
1034
|
specification_version: 4
|
1034
1035
|
summary: A typesetting system for technical authors
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
polytexnic
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.0-p247
|
@@ -1,21 +0,0 @@
|
|
1
|
-
\documentclass[14pt]{extbook}
|
2
|
-
\usepackage{softcover}
|
3
|
-
\VerbatimFootnotes % Allows verbatim text in footnotes
|
4
|
-
|
5
|
-
\title{Title of the Book}
|
6
|
-
\author{Author Name}
|
7
|
-
\date{} % Leave blank, enter a date, or remove to use today's date.
|
8
|
-
|
9
|
-
\begin{document}
|
10
|
-
\includepdf{images/cover.pdf}
|
11
|
-
\frontmatter
|
12
|
-
\maketitle
|
13
|
-
\tableofcontents
|
14
|
-
% List frontmatter sections here (preface, foreword, etc.).
|
15
|
-
\include{chapters/preface}
|
16
|
-
\mainmatter
|
17
|
-
% List chapters here in the order they should appear in the book.
|
18
|
-
\include{chapters/a_chapter}
|
19
|
-
\include{chapters/another_chapter}
|
20
|
-
\include{chapters/yet_another_chapter}
|
21
|
-
\end{document}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
\documentclass[14pt]{extbook}
|
2
|
-
\usepackage{softcover}
|
3
|
-
\VerbatimFootnotes % Allows verbatim text in footnotes
|
4
|
-
|
5
|
-
\title{Title of the Book}
|
6
|
-
\author{Author Name}
|
7
|
-
\date{} % Leave blank, enter a date, or remove to use today's date
|
8
|
-
|
9
|
-
\begin{document}
|
10
|
-
\maketitle
|
11
|
-
% List chapters here in the order they should appear in the book.
|
12
|
-
\include{chapters/a_chapter}
|
13
|
-
\include{chapters/another_chapter}
|
14
|
-
\end{document}
|