softcover 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 429fc241bb03481db6354913c6dd45c503080cd9
4
- data.tar.gz: a3f3efe10906b2b0baf85d0c8198eedb5894fb58
3
+ metadata.gz: d3c3f7ec1c29b0d9916d06aaab5a587d197d2a5a
4
+ data.tar.gz: db1916e845252bcd7816dc6dbfd68ae71b1c3f8d
5
5
  SHA512:
6
- metadata.gz: c1f4cfa61f2a5b90cbaf511ae24164eaa0f39d27fa96d42ab319edf4c07971f341ebf63c5701756f3d9f8bf55c3a79ccee8265f6b3a9fc2268fa58f45c776090
7
- data.tar.gz: b83b64907e873f7d88715f205ffa5a3a1c2e228b3c1f3502fd8de8202a262ee6a9e944bfd13a540818c702db41b39f14215fc1cc12a7586977bfbc0e2f962b61
6
+ metadata.gz: 6621e690252b6d378e5b2d5850b705ad6ac5464cbf2065e228148488eae1c885a827198033de49ca76bc238f537962e432d3d290c4e8fbdd235a257a92c569ad
7
+ data.tar.gz: b109970ac67eac9ff43c696c9da122bb3adce718cce79bd7c6dcb407c302c8dc6fb1d4db56cab5e91251ed01bed1e7a1f61d4df65301b24b01a20653eeb3213c
File without changes
@@ -36,6 +36,19 @@ class Softcover::BookManifest < OpenStruct
36
36
  def to_hash
37
37
  marshal_dump.merge({ menu_heading: menu_heading })
38
38
  end
39
+
40
+ def source
41
+ case extension
42
+ when '.md'
43
+ :markdown
44
+ when '.tex'
45
+ :polytex
46
+ end
47
+ end
48
+
49
+ def full_name
50
+ "#{slug}#{extension}"
51
+ end
39
52
  end
40
53
 
41
54
  class Section < OpenStruct
@@ -153,11 +166,13 @@ class Softcover::BookManifest < OpenStruct
153
166
  def chapter_file_paths
154
167
  pdf_chapter_names.map do |name|
155
168
  file_path = case
156
- when markdown? || @origin == :markdown
157
- File.join("chapters", "#{name}.md")
158
- when polytex?
159
- File.join("chapters", "#{name}.tex")
160
- end
169
+ when markdown? || @origin == :markdown
170
+ chapter = chapters.find { |chapter| chapter.slug == name }
171
+ extension = chapter.nil? ? '.md' : chapter.extension
172
+ File.join("chapters", "#{name}#{extension}")
173
+ when polytex?
174
+ File.join("chapters", "#{name}.tex")
175
+ end
161
176
 
162
177
  yield file_path if block_given?
163
178
 
@@ -166,8 +181,6 @@ class Softcover::BookManifest < OpenStruct
166
181
  end
167
182
 
168
183
  # Returns chapters for the PDF.
169
- # The frontmatter pseudo-chapter exists for the sake of HTML/EPUB/MOBI, so
170
- # it's not returned as part of the chapters.
171
184
  def pdf_chapter_names
172
185
  chaps = chapters.reject { |chapter| chapter.slug.match(/frontmatter/) }.
173
186
  collect(&:slug)
@@ -227,6 +240,33 @@ class Softcover::BookManifest < OpenStruct
227
240
  raise NotFound
228
241
  end
229
242
 
243
+ # Returns the source files specified by Book.txt.
244
+ # Allows a mixture of Markdown and PolyTeX files.
245
+ def source_files
246
+ self.class.find_book_root!
247
+ md_tex = /.*(?:\.md|\.tex)/
248
+ File.readlines(MD_PATH).select { |path| path =~ md_tex }.map(&:strip)
249
+ end
250
+
251
+ def basenames
252
+ source_files.map { |file| File.basename(file, '.*') }
253
+ end
254
+
255
+ def extensions
256
+ source_files.map { |file| File.extname(file) }
257
+ end
258
+
259
+ def chapter_objects
260
+ basenames.zip(extensions).map do |name, extension|
261
+ Chapter.new(slug: name, extension: extension)
262
+ end
263
+ end
264
+
265
+ def read_from_md
266
+ { chapters: chapter_objects, filename: MD_PATH }
267
+ end
268
+
269
+
230
270
  private
231
271
 
232
272
  def read_from_yml
@@ -236,18 +276,9 @@ class Softcover::BookManifest < OpenStruct
236
276
  YAML.load_file(YAML_PATH)
237
277
  end
238
278
 
239
- def read_from_md
240
- self.class.find_book_root!
241
- chapters = File.readlines(MD_PATH).select do |path|
242
- path =~ /(.*)\.md/
243
- end.map do |file|
244
- Chapter.new(slug: File.basename(file.strip, '.md'))
245
- end
246
- { chapters: chapters, filename: MD_PATH }
247
- end
248
279
 
249
280
  def verify_paths!
250
- chapter_file_paths do |chapter_path, i|
281
+ chapter_file_paths do |chapter_path|
251
282
  next if chapter_path =~ /frontmatter/
252
283
  unless File.exist?(chapter_path)
253
284
  raise "Chapter file in manifest not found in #{chapter_path}"
@@ -28,7 +28,7 @@ module Softcover
28
28
  rewrite_master_latex_file
29
29
  # Reset the manifest to use PolyTeX.
30
30
  self.manifest = Softcover::BookManifest.new(source: :polytex,
31
- verify_paths: true,
31
+ verify_paths: false,
32
32
  origin: :markdown)
33
33
  end
34
34
 
@@ -54,12 +54,16 @@ module Softcover
54
54
 
55
55
  # Writes the LaTeX files for a given Markdown chapter.
56
56
  def write_latex_files(chapter, options = {})
57
- path = File.join('chapters', chapter.slug + '.md')
58
- cc = Softcover.custom_styles
59
- md = Polytexnic::Pipeline.new(File.read(path), source: :md,
60
- custom_commands: cc)
61
57
  filename = path("#{manifest.polytex_dir}/#{chapter.slug}.tex")
62
- File.write(filename, md.polytex)
58
+ if chapter.source == :polytex
59
+ FileUtils.cp path("chapters/#{chapter.full_name}"), filename
60
+ else
61
+ path = File.join('chapters', chapter.full_name)
62
+ cc = Softcover.custom_styles
63
+ md = Polytexnic::Pipeline.new(File.read(path), source: :markdown,
64
+ custom_commands: cc)
65
+ File.write(filename, md.polytex)
66
+ end
63
67
  end
64
68
 
65
69
  # Rewrites the master LaTeX file <name>.tex to use chapters from Book.txt.
@@ -68,7 +72,7 @@ module Softcover
68
72
  lines = File.readlines('Book.txt')
69
73
  tex_file = []
70
74
  lines.each do |line|
71
- if line =~ /(.*)\.md\s*$/
75
+ if line =~ /(.*)(?:\.md|\.tex)\s*$/
72
76
  tex_file << "\\include{#{manifest.polytex_dir}/#{$1}}"
73
77
  elsif line =~ /(.*):\s*$/ # frontmatter or mainmatter
74
78
  tex_file << "\\#{$1}"
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "0.6.5"
2
+ VERSION = "0.6.6"
3
3
  end
@@ -48,6 +48,28 @@ describe Softcover::BookManifest do
48
48
  its(:title) { should eq "book" }
49
49
  end
50
50
  end
51
+
52
+
53
+ context "with mixed Markdown & PolyTeX files" do
54
+ before do
55
+ manifest.stub(:source_files).and_return(['foo.md', 'bar.tex'])
56
+ end
57
+
58
+ it "should have the right basenames" do
59
+ expect(manifest.basenames).to eq ['foo', 'bar']
60
+ end
61
+
62
+ it "should have the right extensions" do
63
+ expect(manifest.extensions).to eq ['.md', '.tex']
64
+ end
65
+
66
+ it "should have the right chapter objects" do
67
+ expect(manifest.chapter_objects[0].slug). to eq 'foo'
68
+ expect(manifest.chapter_objects[0].extension).to eq '.md'
69
+ expect(manifest.chapter_objects[1].slug). to eq 'bar'
70
+ expect(manifest.chapter_objects[1].extension).to eq '.tex'
71
+ end
72
+ end
51
73
  end
52
74
 
53
75
  context "in an invalid book directory" do
@@ -55,4 +77,4 @@ describe Softcover::BookManifest do
55
77
  expect{ subject }.to raise_error(Softcover::BookManifest::NotFound)
56
78
  end
57
79
  end
58
- end
80
+ 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.6.5
4
+ version: 0.6.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: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polytexnic
@@ -365,6 +365,7 @@ files:
365
365
  - .pull_requests/1384468478
366
366
  - .pull_requests/1384801823
367
367
  - .pull_requests/1385070261
368
+ - .pull_requests/1385518404
368
369
  - .rspec
369
370
  - .ruby-gemset
370
371
  - .ruby-version