softcover 0.9.5 → 0.9.6

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1aa02aca75e2ee2079f25f083b1698393b24329f
4
- data.tar.gz: 176640a59c9930125f6ea00849757b73e5a595a6
3
+ metadata.gz: d4dfd43d360ce2e5fb73f9ef560fddcb1e52fe0d
4
+ data.tar.gz: 9cc10d4ad3b1e58ec96037e9e23dd048cc76721a
5
5
  SHA512:
6
- metadata.gz: e4c9ecc94a6f73cbbc6edd868685c5ca32eb4ca6c3c62c9d6c552301c9f390e833b1b508f6439aab209c6cb85d43cd6bf9e3298cf238f00fd5f227a0bfdfc2f7
7
- data.tar.gz: 049bb3787159465ad794862f31a9a7cdbb57e9eb692cdcd8a1abe9ac6b3b398a52abca4cdadd52cb5f64c9c7754f82e4e2b08b5003c27e4ac56218b24052f978
6
+ metadata.gz: 53275a23f95789f065d67e84805bce54e0122663dfb1de8939261daffa638044a6aea2e06c1d586f4b782e432adfbac94c8fe1f96c9902cd171cce5fdb1c3fa0
7
+ data.tar.gz: 5d7cf763ed7fac74e4847c33b30dd0aeb68c22938f355fb4058907b47911d3fccb5fc49968eb1f685e7fabcdb2cd58bca131ea5b75f1ab888930f0d91be3d2c5
@@ -3,6 +3,8 @@ require 'ostruct'
3
3
  class Softcover::BookManifest < OpenStruct
4
4
  include Softcover::Utils
5
5
 
6
+ attr_accessor :book_file
7
+
6
8
  class Softcover::MarketingManifest < Softcover::BookManifest
7
9
 
8
10
  YAML_PATH = File.join(Softcover::Directories::CONFIG, 'marketing.yml')
@@ -74,12 +76,14 @@ class Softcover::BookManifest < OpenStruct
74
76
  class Section < OpenStruct
75
77
  end
76
78
 
77
- TXT_PATH = 'Book.txt'
79
+ TXT_PATH = 'Book.txt'
80
+ PREVIEW_PATH = 'Preview.txt'
78
81
  YAML_PATH = File.join(Softcover::Directories::CONFIG, 'book.yml')
79
82
 
80
83
  def initialize(options = {})
81
84
  @source = options[:source] || :polytex
82
85
  @origin = options[:origin]
86
+ @book_file = options[:preview] ? PREVIEW_PATH : TXT_PATH
83
87
 
84
88
  ensure_template_files
85
89
 
@@ -148,7 +152,8 @@ class Softcover::BookManifest < OpenStruct
148
152
  path('latex_styles/custom_pdf.sty'),
149
153
  path('config/preamble.tex'),
150
154
  path('config/lang.yml'),
151
- path('epub/OEBPS/styles/custom_epub.css')
155
+ path('epub/OEBPS/styles/custom_epub.css'),
156
+ path('Preview.txt')
152
157
  ]
153
158
  files.each do |file|
154
159
  unless File.exist?(file)
@@ -309,7 +314,7 @@ class Softcover::BookManifest < OpenStruct
309
314
  def source_files
310
315
  self.class.find_book_root!
311
316
  md_tex = /.*(?:\.md|\.tex)/
312
- book_txt_lines.select { |path| path =~ md_tex }.map(&:strip)
317
+ book_file_lines(self).select { |path| path =~ md_tex }.map(&:strip)
313
318
  end
314
319
 
315
320
  def basenames
@@ -327,7 +332,7 @@ class Softcover::BookManifest < OpenStruct
327
332
  end
328
333
 
329
334
  def read_from_md
330
- { chapters: chapter_objects, filename: TXT_PATH }
335
+ { chapters: chapter_objects, filename: book_file }
331
336
  end
332
337
 
333
338
 
@@ -7,8 +7,8 @@ module Softcover
7
7
  @preview = options[:preview]
8
8
  Softcover::Builders::Html.new.build!
9
9
  if manifest.markdown?
10
- self.manifest = Softcover::BookManifest.new(source: :polytex,
11
- origin: :markdown)
10
+ opts = options.merge({ source: :polytex, origin: :markdown })
11
+ self.manifest = Softcover::BookManifest.new(opts)
12
12
  end
13
13
  remove_html
14
14
  create_directories
@@ -61,9 +61,9 @@ module Softcover
61
61
  File.write(path('epub/OEBPS/content.opf'), content_opf)
62
62
  end
63
63
 
64
- # Returns the chapters to write (accounting for previews).
64
+ # Returns the chapters to write.
65
65
  def chapters
66
- preview? ? manifest.preview_chapters : manifest.chapters
66
+ manifest.chapters
67
67
  end
68
68
 
69
69
  # Writes the HTML for the EPUB.
@@ -367,9 +367,7 @@ module Softcover
367
367
  def toc_ncx
368
368
  title = manifest.title
369
369
  chapter_nav = []
370
- offset = preview? ? manifest.preview_chapter_range.first : 0
371
- chapters.each_with_index do |chapter, i|
372
- n = i + offset
370
+ chapters.each_with_index do |chapter, n|
373
371
  chapter_nav << %(<navPoint id="#{chapter.slug}" playOrder="#{n+1}">)
374
372
  chapter_nav << %( <navLabel><text>#{chapter_name(n)}</text></navLabel>)
375
373
  chapter_nav << %( <content src="#{chapter.fragment_name}"/>)
@@ -11,8 +11,8 @@ module Softcover
11
11
  # then update the manifest to reduce PDF generation
12
12
  # to a previously solved problem.
13
13
  Softcover::Builders::Html.new.build!
14
- self.manifest = Softcover::BookManifest.new(source: :polytex,
15
- origin: :markdown)
14
+ opts = options.merge({ source: :polytex, origin: :markdown})
15
+ self.manifest = Softcover::BookManifest.new(opts)
16
16
  end
17
17
 
18
18
  write_master_latex_file(manifest)
@@ -60,7 +60,7 @@ module Softcover
60
60
  elsif options[:'find-overfull']
61
61
  silence_stream(STDERR) { execute(cmd) }
62
62
  else
63
- options[:preview] ? system(cmd) : execute(cmd)
63
+ execute(cmd)
64
64
  end
65
65
  end
66
66
 
@@ -126,7 +126,8 @@ module Softcover
126
126
  # While we're at it, we move it to the standard ebooks/ directory.
127
127
  def rename_pdf(basename, options={})
128
128
  tmp_pdf = basename + '.tmp.pdf'
129
- pdf = basename + '.pdf'
129
+ name = options[:preview] ? basename + '-preview' : basename
130
+ pdf = name + '.pdf'
130
131
  mkdir('ebooks')
131
132
  # Remove the intermediate tmp files unless only running once.
132
133
  rm_tmp = keep_tmp_files?(options) ? "" : "&& rm -f *.tmp.*"
@@ -6,27 +6,8 @@ module Softcover
6
6
  # Recall that MOBI generation makes an EPUB as a side-effect.
7
7
  Softcover::Builders::Mobi.new.build!(preview: true)
8
8
  Softcover::Builders::Pdf.new.build!(preview: true)
9
- extract_pdf_pages
10
9
  end
11
10
 
12
- private
13
-
14
- # Extracts pages from the PDF using GhostScript.
15
- # The page range is set by the `pdf_preview_page_range` parameter
16
- # in book.yml so that authors can override the default range.
17
- def extract_pdf_pages
18
- input = File.join('ebooks', manifest.filename + '.pdf')
19
- output = input.sub('.pdf', '-preview.pdf')
20
- range = manifest.pdf_preview_page_range.split('..').map(&:to_i)
21
- cmd = %(yes | #{ghostscript} -dBATCH -sOutputFile="#{output}")
22
- cmd += %( -dFirstPage=#{range.first} -dLastPage=#{range.last})
23
- cmd += %( -sDEVICE=pdfwrite "#{input}" > /dev/null)
24
- execute cmd
25
- end
26
-
27
- def ghostscript
28
- @ghostscript ||= executable(dependency_filename(:ghostscript))
29
- end
30
11
  end
31
12
  end
32
13
  end
@@ -32,7 +32,6 @@ module Softcover
32
32
 
33
33
  def dependencies
34
34
  [[:latex, 'LaTeX'],
35
- [:ghostscript, 'GhostScript'],
36
35
  [:convert, 'ImageMagick'],
37
36
  [:node, 'Node.js'],
38
37
  [:phantomjs, 'PhantomJS'],
@@ -74,8 +73,6 @@ module Softcover
74
73
  when :java
75
74
  url = 'http://www.java.com/en/download/help/index_installing.xml'
76
75
  "Java (#{url})"
77
- when :ghostscript
78
- "GhostScript (should come with LaTeX)"
79
76
  when :epubcheck
80
77
  url = 'https://github.com/IDPF/epubcheck/releases/'
81
78
  url += 'download/v3.0/epubcheck-3.0.zip'
@@ -0,0 +1,7 @@
1
+ cover
2
+ frontmatter:
3
+ maketitle
4
+ tableofcontents
5
+ preface.md
6
+ mainmatter:
7
+ a_chapter.md
@@ -7,5 +7,3 @@ description: Change me.
7
7
  author: Author Name
8
8
  copyright: <%= Time.new.year %>
9
9
  uuid: <%= SecureRandom.uuid %>
10
- pdf_preview_page_range: 1..30
11
- epub_mobi_preview_chapter_range: 0..1
@@ -128,8 +128,7 @@
128
128
 
129
129
  % Additional commands
130
130
  \newcommand{\heading}[1]{\textbf{#1}}
131
- \newcommand{\kodesize}{\smaller[0.75]}
132
- \newcommand{\kode}[1]{\textcolor{darkgreen}{\textbf{\texttt{\kodesize #1}}}}
131
+ \newcommand{\kode}[1]{\textcolor{darkgreen}{\textbf{\texttt{#1}}}}
133
132
 
134
133
  % Subtitle command
135
134
  \usepackage{titling}
@@ -64,7 +64,7 @@ module Softcover::Utils
64
64
  # We skip this step if Book.txt doesn't exist, as that means the user
65
65
  # is writing raw LaTeX.
66
66
  def write_master_latex_file(manifest)
67
- if File.exist?(Softcover::BookManifest::TXT_PATH)
67
+ if File.exist?(manifest.book_file)
68
68
  File.write(master_filename(manifest), master_content(manifest))
69
69
  end
70
70
  end
@@ -74,15 +74,20 @@ module Softcover::Utils
74
74
  "#{manifest.filename}.tex"
75
75
  end
76
76
 
77
- # Returns the lines of Book.txt as an array, removing any commented-out lines.
78
- def book_txt_lines
77
+ # Returns the lines of book file as an array, removing commented-out lines.
78
+ def book_file_lines(manifest)
79
+ non_comment_lines(raw_lines(manifest))
80
+ end
81
+
82
+ # Returns only non-comment lines.
83
+ def non_comment_lines(lines)
79
84
  comment = /^\s*#.*$/
80
- raw_lines.reject { |line| line.match(comment) }
85
+ lines.reject { |line| line.match(comment) }
81
86
  end
82
87
 
83
88
  # Returns all the lines in Book.txt.
84
- def raw_lines
85
- File.readlines(Softcover::BookManifest::TXT_PATH)
89
+ def raw_lines(manifest)
90
+ File.readlines(manifest.book_file)
86
91
  end
87
92
 
88
93
  # Returns the content for the master LaTeX file.
@@ -91,7 +96,7 @@ module Softcover::Utils
91
96
  source_file = /(.*)(?:\.md|\.tex)\s*$/
92
97
 
93
98
  tex_file = [master_latex_header(manifest)]
94
- book_txt_lines.each do |line|
99
+ book_file_lines(manifest).each do |line|
95
100
  if line.match(source_file)
96
101
  tex_file << "\\include{#{manifest.polytex_dir}/#{$1}}"
97
102
  elsif line.match(front_or_mainmatter) # frontmatter or mainmatter
@@ -245,8 +250,6 @@ module Softcover::Utils
245
250
  `which java`.chomp
246
251
  when :calibre
247
252
  `which ebook-convert`.chomp
248
- when :ghostscript
249
- `which gs`.chomp
250
253
  when :epubcheck
251
254
  File.join(Dir.home, 'epubcheck-3.0', 'epubcheck-3.0.jar')
252
255
  when :inkscape
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
@@ -155,7 +155,7 @@ describe Softcover::Builders::Html do
155
155
  describe "commented-out lines of Book.txt" do
156
156
  let(:lines) { ['foo.md', '# bar.md'] }
157
157
  let(:content) { builder.master_content(builder.manifest) }
158
- before { builder.stub(:book_txt_lines).and_return(lines) }
158
+ before { builder.stub(:book_file_lines).and_return(lines) }
159
159
  it "should be ignored" do
160
160
  expect(content).to include 'generated_polytex/foo'
161
161
  expect(content).not_to include 'generated_polytex/bar'
@@ -24,17 +24,6 @@ describe Softcover::Builders::Preview do
24
24
  it "should build an EPUB" do
25
25
  expect('ebooks/book-preview.mobi').to exist
26
26
  end
27
-
28
- it "should include the right chapters" do
29
- @builder.manifest.preview_chapters.each do |ch|
30
- expect(File.join('epub', 'OEBPS', ch.fragment_name)).to exist
31
- end
32
- nonpreview_chapters = @builder.manifest.chapters -
33
- @builder.manifest.preview_chapters
34
- nonpreview_chapters.each do |ch|
35
- expect(File.join('epub', 'OEBPS', ch.fragment_name)).not_to exist
36
- end
37
- end
38
27
  end
39
28
  end
40
29
  end
@@ -38,7 +38,6 @@ describe Softcover::Commands::Check do
38
38
  it { should match /Checking for KindleGen.*Missing/ }
39
39
  it { should match /Checking for Java.*Missing/ }
40
40
  it { should match /Checking for EpubCheck.*Missing/ }
41
- it { should match /Checking for GhostScript.*Missing/ }
42
41
  it { should match /Checking for ImageMagick.*Missing/ }
43
42
  it { should match /Checking for Node\.js.*Missing/ }
44
43
 
@@ -50,7 +49,6 @@ describe Softcover::Commands::Check do
50
49
  it { should match /KindleGen/ }
51
50
  it { should match /Java/ }
52
51
  it { should match /EpubCheck/ }
53
- it { should match /GhostScript/ }
54
52
  it { should match /ImageMagick/ }
55
53
  it { should match /Node\.js/ }
56
54
  end
data/spec/utils_spec.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Softcover::Utils do
4
- context "book_txt_lines" do
5
- before do
6
- Softcover::Utils.stub(:raw_lines).and_return(['foo.md', '# bar.tex'])
7
- end
8
- subject { Softcover::Utils.book_txt_lines }
4
+ context "book_file_lines" do
5
+ let(:raw_lines) { ['foo.md', '# bar.tex'] }
6
+ subject { Softcover::Utils.non_comment_lines(raw_lines) }
9
7
  it { should include 'foo.md' }
10
8
  it { should_not include 'bar.tex' }
11
9
  end
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.9.5
4
+ version: 0.9.6
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: 2014-02-25 00:00:00.000000000 Z
12
+ date: 2014-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polytexnic
@@ -430,6 +430,7 @@ files:
430
430
  - lib/softcover/template/.softcover-build
431
431
  - lib/softcover/template/.softcover-deploy
432
432
  - lib/softcover/template/Book.txt
433
+ - lib/softcover/template/Preview.txt
433
434
  - lib/softcover/template/README.md
434
435
  - lib/softcover/template/chapters/a_chapter.md
435
436
  - lib/softcover/template/chapters/a_chapter.tex