prophecy 0.1.3 → 0.2.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.
data/lib/prophecy/book.rb CHANGED
@@ -240,7 +240,9 @@ module Prophecy
240
240
  File.join(self.assets_dir, 'stylesheets')
241
241
  ]
242
242
  when 'latex'
243
- inc = []
243
+ inc = [
244
+ File.join(self.assets_dir, 'fonts'),
245
+ ]
244
246
  end
245
247
 
246
248
  if config_include.nil?
@@ -77,8 +77,21 @@ module Prophecy
77
77
  unless @src.nil?
78
78
  @render_ext = ext_for_output[book.output_format]
79
79
 
80
- @path = File.expand_path(File.join(
81
- book.format_dir(@src), @src))
80
+ path = nil
81
+ try_folders = [ book.format_dir(@src), 'manuscript' ].uniq
82
+ try_folders.each do |dir|
83
+ path = File.join(dir, @src)
84
+ if File.exists?(path)
85
+ @path = path
86
+ break
87
+ end
88
+ end
89
+
90
+ unless @path
91
+ puts "Error. Cannot find #{@src} in folders #{try_folders.join(', ')}"
92
+ exit 2
93
+ end
94
+
82
95
  @render_name = File.basename(@path).sub(/\.erb$/, '').sub(/\.[^\.]+$/, @render_ext)
83
96
  @render_path = File.expand_path(
84
97
  File.join(
@@ -200,6 +213,11 @@ module Prophecy
200
213
  when '.md', '.mkd', '.markdown'
201
214
  ret = Kramdown::Document.new(text).to_html
202
215
  when '.tex'
216
+ # Is Pandoc installed?
217
+ unless system("pandoc --version > /dev/null 2>&1")
218
+ puts "Error. Pandoc not found, I'll need that for TeX to HTML conversion."
219
+ exit 2
220
+ end
203
221
  File.open('./temp-chapter.tex', 'w'){|f| f << text }
204
222
  r = system 'pandoc --smart --normalize --from=latex --to=html -o ./temp-chapter.xhtml ./temp-chapter.tex'
205
223
  warn "WARNING: pandoc returned non-zero for #{self.to_s}" unless r
@@ -234,11 +252,16 @@ module Prophecy
234
252
 
235
253
  case format
236
254
  when '.html', '.xhtml'
255
+ # Is Pandoc installed?
256
+ unless system("pandoc --version > /dev/null 2>&1")
257
+ puts "Error. Pandoc not found, I'll need that for HTML to TeX conversion."
258
+ exit 2
259
+ end
237
260
  File.open('./temp-chapter.html', 'w'){|f| f << text }
238
261
  system 'pandoc --smart --normalize --chapters --from=html --to=latex -o ./temp-chapter.tex ./temp-chapter.html'
239
262
  ret = IO.read('./temp-chapter.tex')
240
263
  FileUtils.rm(['./temp-chapter.tex', './temp-chapter.html'])
241
- when '.md'
264
+ when '.md', '.mkd', '.markdown'
242
265
  ret = Kramdown::Document.new(text, options = {:latex_headers => %w{chapter section subsection subsubsection paragraph subparagraph}}).to_latex
243
266
  when '.tex'
244
267
  ret = text
data/lib/prophecy/cli.rb CHANGED
@@ -18,14 +18,30 @@ module Prophecy
18
18
  Prophecy::Generators::Assets.start
19
19
  end
20
20
 
21
- desc "epub", "generate EPUB"
21
+ desc "epub", "Generate new EPUB from sources. This calls assets_compile, epub_clean_dir, epub_build, epub_compile."
22
22
  def epub
23
- @config = YAML::load(IO.read('book.yml'))
24
- # Local assets dir in book project folder
25
- compile_assets if Dir.exists?('./assets') && @assets_dir == File.join('.', 'assets')
26
- @book = epub_init_book
27
- clean_dir(@book.build_dir)
23
+ epub_init
24
+ assets_compile
25
+ epub_clean_dir
26
+ epub_build
27
+ epub_compile
28
+ end
29
+
30
+ desc "epub_clean_dir", "Delete everything in the EPUB build dir"
31
+ def epub_clean_dir
32
+ epub_init
33
+ clean_dir
34
+ end
35
+
36
+ desc "epub_build", "Generate EPUB build files from the templates and manuscript"
37
+ def epub_build
38
+ epub_init
28
39
  @book.generate_build
40
+ end
41
+
42
+ desc "epub_compile", "Compile EPUB file from the build dir"
43
+ def epub_compile
44
+ epub_init
29
45
 
30
46
  # Compile Epub with Zip
31
47
  print "Compiling Epub with Zip... "
@@ -54,14 +70,30 @@ module Prophecy
54
70
  #cmd = system("epubcheck builds/epub/book.epub")
55
71
  end
56
72
 
57
- desc "mobi", "generate MOBI with Kindlegen"
73
+ desc "mobi", "Generate new MOBI with Kindlegen from sources. This calls assets_compile, mobi_clean_dir, mobi_build, mobi_compile."
58
74
  def mobi
59
- @config = YAML::load(IO.read('book.yml'))
60
- # Local assets dir in book project folder
61
- compile_assets if Dir.exists?('./assets') && @assets_dir == File.join('.', 'assets')
62
- @book = mobi_init_book
63
- clean_dir(@book.build_dir)
75
+ mobi_init
76
+ assets_compile
77
+ mobi_clean_dir
78
+ mobi_build
79
+ mobi_compile
80
+ end
81
+
82
+ desc "mobi_clean_dir", "Delete everything in the MOBI build dir"
83
+ def mobi_clean_dir
84
+ mobi_init
85
+ clean_dir
86
+ end
87
+
88
+ desc "mobi_build", "Generate MOBI build files from the templates and manuscript"
89
+ def mobi_build
90
+ mobi_init
64
91
  @book.generate_build
92
+ end
93
+
94
+ desc "mobi_compile", "Compile MOBI file from the build dir"
95
+ def mobi_compile
96
+ mobi_init
65
97
 
66
98
  # Compile Epub with Zip for conversion with kindlegen
67
99
  print "Compiling Epub (for Mobi) with Zip... "
@@ -114,40 +146,91 @@ module Prophecy
114
146
  puts "Error. See kindlestrip.log"
115
147
  exit 2
116
148
  end
149
+ end
117
150
 
151
+ desc "latex", "Generate new PDF with LaTeX from sources. This calls latex_clean_dir, latex_build, latex_compile"
152
+ def latex
153
+ latex_init
154
+ latex_clean_dir
155
+ latex_build
156
+ latex_compile
118
157
  end
119
158
 
120
- desc "pdf", "generate PDF with LaTeX"
121
- def pdf
122
- @config = YAML::load(IO.read('book.yml'))
123
- @book = latex_init_book
124
- clean_dir(@book.build_dir)
159
+ desc "latex_clean_dir", "Delete everything in the LaTeX build dir"
160
+ def latex_clean_dir
161
+ latex_init
162
+ clean_dir
163
+ end
164
+
165
+ desc "latex_build", "Generate LaTeX build files from the templates and manuscript"
166
+ def latex_build
167
+ latex_init
125
168
  @book.generate_build
126
- system "cd #{@book.build_dir} && make"
127
- end
128
-
129
- desc "to_markdown", "convert .tex files to markdown"
130
- def to_markdown
131
- @book = latex_init_book
132
-
133
- Dir[File.join(@book.tex_dir, '*.tex')].each do |f|
134
- dest = File.expand_path(File.join(@book.markdown_dir, File.basename(f).sub(/\.tex$/, '.md')))
135
- if File.exist?(dest)
136
- print "WARNING: destination exists: #{dest}\nOverwrite? [yN] "
137
- a = STDIN.gets.chomp()
138
- if a.downcase != 'y'
139
- puts "OK, skipping file"
140
- next
141
- end
142
- end
143
- r = system "/bin/bash #{File.join(@book.assets_dir, 'helpers/tex2md.sh')} '#{File.expand_path(f)}' '#{dest}'"
144
- warn "WARNING: tex2md.sh returned non-zero for #{f}" unless r
169
+ end
170
+
171
+ desc "latex_compile", "Compile PDF file from the LaTeX build dir"
172
+ def latex_compile
173
+ latex_init
174
+
175
+ # Is LuaLatex installed?
176
+ unless system("lualatex --version > /dev/null 2>&1")
177
+ puts "Error. LuaLaTeX not found."
178
+ exit 2
179
+ end
180
+
181
+ print "Running 'make' in #{@book.build_dir} ... "
182
+
183
+ cmd = "{ cd #{@book.build_dir}"
184
+ cmd += " && make"
185
+ cmd += " && cp book_main.pdf ../../publish/pdf/; } > lualatex.log 2>&1"
186
+
187
+ if system(cmd)
188
+ puts "OK"
189
+ puts "Find book_main.pdf in ./build/latex/ and ./publish/pdf"
190
+ else
191
+ puts "Error. See lualatex.log and ./build/latex/book_main.log"
192
+ exit 2
193
+ end
194
+ end
195
+
196
+ # desc "to_markdown", "convert .tex files to markdown"
197
+ # def to_markdown
198
+ # @book = latex_init_book
199
+ #
200
+ # Dir[File.join(@book.tex_dir, '*.tex')].each do |f|
201
+ # dest = File.expand_path(File.join(@book.markdown_dir, File.basename(f).sub(/\.tex$/, '.md')))
202
+ # if File.exist?(dest)
203
+ # print "WARNING: destination exists: #{dest}\nOverwrite? [yN] "
204
+ # a = STDIN.gets.chomp()
205
+ # if a.downcase != 'y'
206
+ # puts "OK, skipping file"
207
+ # next
208
+ # end
209
+ # end
210
+ # r = system "/bin/bash #{File.join(@book.assets_dir, 'helpers/tex2md.sh')} '#{File.expand_path(f)}' '#{dest}'"
211
+ # warn "WARNING: tex2md.sh returned non-zero for #{f}" unless r
212
+ # end
213
+ # end
214
+
215
+ desc "assets_compile", "Compile assets (run compass, etc.) if there is a local assets folder"
216
+ def assets_compile
217
+ unless Dir.exists?('./assets')
218
+ return
219
+ end
220
+ puts "Running 'compass compile' ..."
221
+ if system 'cd assets && compass compile'
222
+ puts "OK"
223
+ else
224
+ puts "Error"
225
+ exit 2
145
226
  end
146
227
  end
147
228
 
148
229
  private
149
230
 
150
- def epub_init_book
231
+ def epub_init
232
+ @config ||= YAML::load(IO.read('book.yml'))
233
+
151
234
  [ './epub_mobi.yml',
152
235
  './epub.yml' ].each do |c|
153
236
  next if !File.exists?(c)
@@ -156,10 +239,12 @@ module Prophecy
156
239
  end
157
240
 
158
241
  @config['output_format'] ||= 'epub'
159
- Prophecy::Book.new(@config)
242
+ @book ||= Prophecy::Book.new(@config)
160
243
  end
161
244
 
162
- def mobi_init_book
245
+ def mobi_init
246
+ @config ||= YAML::load(IO.read('book.yml'))
247
+
163
248
  [ './epub_mobi.yml',
164
249
  './mobi.yml' ].each do |c|
165
250
  next if !File.exists?(c)
@@ -168,10 +253,12 @@ module Prophecy
168
253
  end
169
254
 
170
255
  @config['output_format'] ||= 'mobi'
171
- Prophecy::Book.new(@config)
256
+ @book ||= Prophecy::Book.new(@config)
172
257
  end
173
258
 
174
- def latex_init_book
259
+ def latex_init
260
+ @config ||= YAML::load(IO.read('book.yml'))
261
+
175
262
  [ './latex.yml', ].each do |c|
176
263
  next if !File.exists?(c)
177
264
  h = YAML::load(IO.read(c))
@@ -179,14 +266,12 @@ module Prophecy
179
266
  end
180
267
 
181
268
  @config['output_format'] ||= 'latex'
182
- @book = Prophecy::Book.new(@config)
183
- end
184
-
185
- def compile_assets
186
- system 'cd assets && compass compile'
269
+ @book ||= Prophecy::Book.new(@config)
187
270
  end
188
271
 
189
- def clean_dir(dir)
272
+ def clean_dir
273
+ dir = @book.build_dir
274
+ puts "Cleaning #{dir} ..."
190
275
  if Dir[File.join(dir, '*')].empty?
191
276
  puts "#{dir} is empty."
192
277
  return
@@ -25,17 +25,24 @@ date: <%= Time.now.strftime("%Y-%m-%d") %>
25
25
 
26
26
  toc:
27
27
  - { the_matter: frontmatter }
28
+ - { insert: "\\frontmatter*\n\\chapterstyle{frontmatter}", target: latex }
28
29
  - { title: "Cover", src: 'cover.xhtml.erb', target: epub, layout: none, type: cover, linear: no }
29
30
  - { title: "Title Page", src: 'titlepage.xhtml.erb', target: epub, type: title-page }
30
31
  - { title: "Contents", src: 'toc.xhtml.erb', target: epub, type: toc }
32
+ - { insert: "\\cleartorecto\n\\tableofcontents", target: latex }
31
33
  - preface.md
32
34
  - { title: "Title Page", src: 'titlepage.xhtml.erb', target: mobi, type: text, class: title-page }
33
35
  - { title: "Contents", src: 'toc.xhtml.erb', target: mobi, type: toc }
34
36
  - { the_matter: mainmatter, section_number: 1 }
35
- - the-sway-of-reason.markdown
36
- - unhuman-massiveness.markdown
37
+ - { insert: "\\mainmatter*\n\\book{\\thetitle}\n\\setcounter{chapter}{0}\n\\chapterstyle{mainmatter}", target: latex }
38
+ - like-a-boat.md
37
39
  - nameless-labyrinth.markdown
40
+ - time-machine.markdown
41
+ - { insert: '\appendix', target: latex }
42
+ - { section_name: "Appendix", section_number: 1 }
43
+ - further-comments.markdown
38
44
  - { the_matter: backmatter }
45
+ - { insert: "\\backmatter\n\\bookmarksetup{startatroot}\n\\chapterstyle{backmatter}", target: latex }
39
46
  - glossary.md
40
47
 
41
48
  cover_image: "cover.jpg"
@@ -0,0 +1,5 @@
1
+
2
+ # Further Comments
3
+
4
+ All that could be said...
5
+
@@ -1,7 +1,12 @@
1
1
 
2
2
  # Glossary
3
3
 
4
- * word one
5
- * word two
6
- * how many words do you know?
4
+ * zero
5
+ * one
6
+ * one
7
+ * two
8
+ * three
9
+ * five
10
+ * eight
11
+ * thirteen
7
12
 
@@ -0,0 +1,12 @@
1
+
2
+ # Like a Boat
3
+
4
+ > Living in this world --\\
5
+ > to what shall I compare it?\\
6
+ > Its like a boat\\
7
+ > rowing out at break of day,\\
8
+ > leaving no trace behind.
9
+ >
10
+ > by Sami Mansei in the Man'yōshū, 759 AD
11
+ > {:.attribution}
12
+
@@ -1,34 +1,28 @@
1
1
 
2
- # Nameless Labyrinth
2
+ # The Nameless Labyrinth
3
3
 
4
- The nameless stone labyrinth consisted, for the most part, of walls from ten to
5
- one hundred and fifty feet in ice-clear height, and of a thickness varying from
6
- five to ten feet. It was composed mostly of prodigious blocks of dark
7
- primordial slate, schist, and sandstone—blocks in many cases as large as 4 x 6
8
- x 8 feet—though in several places it seemed to be carved out of a solid, uneven
9
- bed rock of pre-Cambrian slate. The buildings were far from equal in size,
10
- there being innumerable honeycomb arrangements of enormous extent as well as
11
- smaller separate structures. The general shape of these things tended to be
12
- conical, pyramidal, or terraced; though there were many perfect cylinders,
13
- perfect cubes, clusters of cubes, and other rectangular forms, and a peculiar
14
- sprinkling of angled edifices whose five-pointed ground plan roughly suggested
15
- modern fortifications. The builders had made constant and expert use of the
16
- principle of the arch, and domes had probably existed in the city's heyday.
4
+ > "I have seen the dark universe yawning\\
5
+ > Where the black planets roll without aim,\\
6
+ > Where they roll in their horror unheeded,\\
7
+ > without knowledge or lustre or name."
8
+ >
9
+ > Nemesis, 1917
10
+ > {:.attribution}
17
11
 
18
- The whole tangle was monstrously weathered, and the glacial surface from which
19
- the towers projected was strewn with fallen blocks and immemorial debris. Where
20
- the glaciation was transparent we could see the lower parts of the gigantic
21
- piles, and we noticed the ice-preserved stone bridges which connected the
22
- different towers at varying distances above the ground. On the exposed walls we
23
- could detect the scarred places where other and higher bridges of the same sort
24
- had existed. Closer inspection revealed countless largish windows; some of
25
- which were closed with shutters of a petrified material originally wood, though
26
- most gaped open in a sinister and menacing fashion. Many of the ruins, of
27
- course, were roofless, and with uneven though wind-rounded upper edges; whilst
28
- others, of a more sharply conical or pyramidal model or else protected by
29
- higher surrounding structures, preserved intact outlines despite the
30
- omnipresent crumbling and pitting. With the field glass we could barely make
31
- out what seemed to be sculptural decorations in horizontal bands—decorations
32
- including those curious groups of dots whose presence on the ancient soapstones
33
- now assumed a vastly larger significance.
12
+ Yet now the sway of reason seemed irrefutably shaken, for this
13
+ Cyclopean maze of squared, curved, and angled blocks had features
14
+ which cut off all comfortable refuge. It was, very clearly, the
15
+ blasphemous city of the mirage in stark, objective, and
16
+ ineluctable reality. That damnable portent had had a material
17
+ basis after all—there had been some horizontal stratum of ice
18
+ dust in the upper air, and this shocking stone survival had
19
+ projected its image across the mountains according to the simple
20
+ laws of reflection, Of course, the phantom had been twisted and
21
+ exaggerated, and had contained things which the real source did
22
+ not contain; yet now, as we saw that real source, we thought it
23
+ even more hideous and menacing than its distant image.
24
+
25
+ [At the Mountains of Madness][1] by *H.P. Lovecraft*, 1931
26
+
27
+ [1]: http://en.wikisource.org/wiki/At_the_Mountains_of_Madness/Chapter_5
34
28
 
@@ -0,0 +1,25 @@
1
+
2
+ # The Time Machine
3
+
4
+ The Time Traveller (for so it will be convenient to speak of him)
5
+ was expounding a recondite matter to us. His grey eyes shone and
6
+ twinkled, and his usually pale face was flushed and animated. The
7
+ fire burned brightly, and the soft radiance of the incandescent
8
+ lights in the lilies of silver caught the bubbles that flashed
9
+ and passed in our glasses. Our chairs, being his patents,
10
+ embraced and caressed us rather than submitted to be sat upon,
11
+ and there was that luxurious after-dinner atmosphere when thought
12
+ roams gracefully free of the trammels of precision. And he put it
13
+ to us in this way -- marking the points with a lean forefinger --
14
+ as we sat and lazily admired his earnestness over this new
15
+ paradox (as we thought it) and his fecundity.
16
+
17
+ 'You must follow me carefully. I shall have to controvert one or
18
+ two ideas that are almost universally accepted. The geometry, for
19
+ instance, they taught you at school is founded on a
20
+ misconception.'
21
+
22
+ [The Time Machine][1] by *H.G. Wells*, 1895
23
+
24
+ [1]: http://en.wikisource.org/wiki/The_Time_Machine_(Heinemann_text)/Chapter_I
25
+