git-scribe 0.0.8 → 0.0.9

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/TODO.txt CHANGED
@@ -1,18 +1,18 @@
1
1
  To-Do List
2
2
  =============
3
3
 
4
+ * git-init after git scribe init
5
+
4
6
  * custom site layouts
5
7
  * custom/alternate themes (stylesheets)
6
8
  * cover page for site (author, about, etc)
7
9
  * book cover (w/template)
8
- * github pages publishing
9
- * checking for proper tools
10
+ * generate hashes for generated assets and do not regenerate them unneccesarily
11
+
10
12
  * book search
11
13
  * math formula
12
14
  * generate different languages from branches/tags (site, epub, mobi)
13
15
 
14
- * use options library
15
-
16
16
  * workflow
17
17
  - review / copy editing
18
18
  - translation
@@ -1,4 +1,5 @@
1
1
  $LOAD_PATH.unshift 'lib'
2
+ require 'git-scribe/version'
2
3
 
3
4
  files = `git ls-files`.
4
5
  split("\n").
@@ -9,7 +10,7 @@ puts files
9
10
  # piece file back together and write...
10
11
  Gem::Specification.new do |s|
11
12
  s.name = "git-scribe"
12
- s.version = "0.0.8"
13
+ s.version = GitScribe::VERSION
13
14
  s.date = Time.now.strftime('%Y-%m-%d')
14
15
  s.summary = "git-scribe is an authors toolkit for writing and publishing books"
15
16
  s.homepage = "http://github.com/schacon/git-scribe"
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'nokogiri'
3
3
  require 'liquid'
4
+ require 'yaml'
4
5
 
5
6
  require 'git-scribe/generate'
6
7
  require 'git-scribe/check'
@@ -19,13 +20,14 @@ class GitScribe
19
20
  attr_reader :info
20
21
 
21
22
  BOOK_FILE = 'book.asc'
22
- OUTPUT_TYPES = ['pdf', 'epub', 'mobi', 'html', 'site']
23
+ OUTPUT_TYPES = ['docbook', 'html', 'pdf', 'epub', 'mobi', 'site']
23
24
  SCRIBE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
24
25
 
25
26
  def initialize
26
27
  @subcommand = nil
27
28
  @args = []
28
29
  @options = {}
30
+ @config = YAML::parse(File.open(local('.gitscribe'))).transform rescue {}
29
31
  end
30
32
 
31
33
  ## COMMANDS ##
@@ -7,28 +7,28 @@ class GitScribe
7
7
  # check for asciidoc
8
8
  if !check_can_run('asciidoc')
9
9
  info "asciidoc is not present, please install it for anything to work"
10
- status[:asciidoc] = true
10
+ status[:asciidoc] = false
11
11
  else
12
12
  info "asciidoc - ok"
13
- status[:asciidoc] = false
13
+ status[:asciidoc] = true
14
14
  end
15
15
 
16
16
  # check for xsltproc
17
17
  if !check_can_run('xsltproc --version')
18
18
  info "xsltproc is not present, please install it for html generation"
19
- status[:xsltproc] = true
19
+ status[:xsltproc] = false
20
20
  else
21
21
  info "xsltproc - ok"
22
- status[:xsltproc] = false
22
+ status[:xsltproc] = true
23
23
  end
24
24
 
25
25
  # check for a2x - should be installed with asciidoc, but you never know
26
26
  if !check_can_run('a2x')
27
27
  info "a2x is not present, please install it for epub generation"
28
- status[:a2x] = true
28
+ status[:a2x] = false
29
29
  else
30
30
  info "a2x - ok"
31
- status[:a2x] = false
31
+ status[:a2x] = true
32
32
  end
33
33
 
34
34
  # check for source-highlight
@@ -44,19 +44,19 @@ class GitScribe
44
44
  # check for fop
45
45
  if !check_can_run('fop -version')
46
46
  info "fop is not present, please install for PDF generation"
47
- status[:fop] = true
47
+ status[:fop] = false
48
48
  else
49
49
  info "fop - ok"
50
- status[:fop] = false
50
+ status[:fop] = true
51
51
  end
52
52
 
53
- # check for calibre
54
- if !check_can_run('ebook-convert --version')
55
- info "calibre is not present, please install for mobi generation"
56
- status[:calibre] = true
53
+ # check for kindlegen
54
+ if !check_can_run('kindlegen')
55
+ info "kindlegen is not present, please install for mobi generation"
56
+ status[:mobi] = false
57
57
  else
58
- info "calibre - ok"
59
- status[:calibre] = false
58
+ info "kindlegen - ok"
59
+ status[:mobi] = true
60
60
  end
61
61
 
62
62
 
@@ -45,10 +45,19 @@ class GitScribe
45
45
  a2x(type) + " --stylesheet=stylesheets/handbookish.css"
46
46
  end
47
47
 
48
+ def do_docbook
49
+ return true if @done['docbook']
50
+ info "GENERATING DOCBOOK"
51
+ if ex("asciidoc -b docbook #{BOOK_FILE}")
52
+ @done['docbook'] = true
53
+ 'book.xml'
54
+ end
55
+ end
56
+
48
57
  def do_pdf
49
58
  info "GENERATING PDF"
59
+ do_docbook
50
60
  # TODO: syntax highlighting (fop?)
51
- ex("asciidoc -b docbook #{BOOK_FILE}")
52
61
  strparams = {'callout.graphics' => 0,
53
62
  'navig.graphics' => 0,
54
63
  'admon.textlabel' => 1,
@@ -58,7 +67,6 @@ class GitScribe
58
67
  ex(cmd)
59
68
  cmd = "fop -fo #{local('book.fo')} -pdf #{local('book.pdf')}"
60
69
  ex(cmd)
61
- #puts `#{a2x('pdf')} -v --fop #{BOOK_FILE}`
62
70
  if $?.exitstatus == 0
63
71
  'book.pdf'
64
72
  end
@@ -76,11 +84,9 @@ class GitScribe
76
84
  def do_mobi
77
85
  do_html
78
86
  info "GENERATING MOBI"
79
- # --cover 'cover.png'
80
- # --authors 'Author Name'
81
- # --comments "licensed under CC"
82
- # --language 'en'
83
- cmd = "ebook-convert book.html book.mobi --level1-toc '//h:h1' --level2-toc '//h:h2' --level3-toc '//h:h3'"
87
+ generate_toc_files
88
+ # generate book.opf
89
+ cmd = "kindlegen -verbose book.opf -o book.mobi"
84
90
  if ex(cmd)
85
91
  'book.mobi'
86
92
  end
@@ -90,7 +96,6 @@ class GitScribe
90
96
  return true if @done['html']
91
97
  info "GENERATING HTML"
92
98
  # TODO: look for custom stylesheets
93
- #puts `#{a2x_wss('xhtml')} -v #{BOOK_FILE}`
94
99
  styledir = local('stylesheets')
95
100
  cmd = "asciidoc -a stylesdir=#{styledir} -a theme=handbookish #{BOOK_FILE}"
96
101
  if ex(cmd)
@@ -156,9 +161,8 @@ class GitScribe
156
161
  files = Dir.glob(template_dir + '/*')
157
162
  FileUtils.cp_r files, '.'
158
163
 
159
- Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_dir)
160
- index_template = Liquid::Template.parse(File.read(File.join(template_dir, 'index.html')))
161
- page_template = Liquid::Template.parse(File.read(File.join(template_dir, 'page.html')))
164
+ index_template = liquid_template('index.html')
165
+ page_template = liquid_template('page.html')
162
166
 
163
167
  # write the index page
164
168
  main_data = {
@@ -224,6 +228,105 @@ class GitScribe
224
228
  sections
225
229
  end
226
230
 
231
+ def generate_toc_files
232
+ # read book table of contents
233
+ toc = []
234
+ source = File.read("book.html")
235
+
236
+ # get the book title
237
+ book_title = 'Title'
238
+ if t = /\<title>(.*?)<\/title\>/.match(source)
239
+ book_title = t[0]
240
+ end
241
+
242
+ source.scan(/\<h([2|3]) id=\"(.*?)\"\>(.*?)\<\/h[2|3]\>/).each do |header|
243
+ sec = {'id' => header[1], 'name' => header[2]}
244
+ if header[0] == '2'
245
+ toc << {'section' => sec, 'subsections' => []}
246
+ else
247
+ toc[toc.size - 1]['subsections'] << sec
248
+ end
249
+ end
250
+
251
+ # write ncx table of contents
252
+ ncx = File.open('book.ncx', 'w+')
253
+ ncx.puts('<?xml version="1.0" encoding="UTF-8"?>
254
+ <!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
255
+ "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
256
+
257
+ <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en-US">
258
+ <head>
259
+ <meta name="dtb:depth" content="2"/>
260
+ <meta name="dtb:totalPageCount" content="0"/>
261
+ <meta name="dtb:maxPageNumber" content="0"/>
262
+ </head>
263
+ <docTitle><text>Title</text></docTitle>
264
+ <docAuthor><text>Author</text></docAuthor>
265
+ <navMap>
266
+ <navPoint class="toc" id="toc" playOrder="1">
267
+ <navLabel>
268
+ <text>Table of Contents</text>
269
+ </navLabel>
270
+ <content src="toc.html"/>
271
+ </navPoint>')
272
+
273
+ chapters = 0
274
+ toc.each do |section|
275
+ chapters += 1
276
+ ch = section['section']
277
+ ncx.puts('<navPoint class="chapter" id="chapter_' + chapters.to_s + '" playOrder="' + (chapters + 1).to_s + '">')
278
+ ncx.puts('<navLabel><text>' + ch['name'].to_s + '</text></navLabel>')
279
+ ncx.puts('<content src="book.html#' + ch['id'].to_s + '"/>')
280
+ ncx.puts('</navPoint>')
281
+ end
282
+ ncx.puts('</navMap></ncx>')
283
+ ncx.close
284
+
285
+ # build html toc
286
+ # write ncx table of contents
287
+ html = File.open('toc.html', 'w+')
288
+ html.puts('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
289
+ <html xmlns="http://www.w3.org/1999/xhtml">
290
+ <head><title>Table of Contents</title></head><body>
291
+ <div><h1><b>TABLE OF CONTENTS</b></h1><br/>')
292
+
293
+ chapters = 0
294
+ toc.each do |section|
295
+ chapters += 1
296
+ ch = section['section']
297
+
298
+ html.puts('<h3><b>Chapter ' + chapters.to_s + '<br/>')
299
+ html.puts('<a href="book.html#' + ch['id'] + '">' + ch['name'] + '</a></b></h3><br/>')
300
+
301
+ section['subsections'].each do |sub|
302
+ html.puts('<a href="book.html#' + sub['id'] + '"><b>' + sub['name'] + '</b></a><br/>')
303
+ end
304
+ end
305
+ html.puts('<h1 class="centered">* * *</h1></div></body></html>')
306
+ html.close
307
+
308
+ # build book.opf file
309
+ opf_template = liquid_template('book.opf')
310
+ File.open('book.opf', 'w+') do |f|
311
+ lang = @config['language'] || 'en'
312
+ author = @config['author'] || 'Author'
313
+ cover = @config['cover'] || 'image/cover.jpg'
314
+ data = {'title' => book_title,
315
+ 'language' => lang,
316
+ 'author' => author,
317
+ 'pubdate' => Time.now.strftime("%Y-%m-%d"),
318
+ 'cover_image' => cover}
319
+ f.puts opf_template.render( data )
320
+ end
321
+ end
322
+
323
+
324
+ def liquid_template(file)
325
+ template_dir = File.join(SCRIBE_ROOT, 'site', 'default')
326
+ Liquid::Template.parse(File.read(File.join(template_dir, file)))
327
+ end
328
+
329
+
227
330
  # create a new file by concatenating all the ones we find
228
331
  def gather_and_process
229
332
  files = Dir.glob("book/*")
@@ -1,3 +1,3 @@
1
1
  class GitScribe
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -0,0 +1,30 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <package xmlns="http://www.idpf.org/2007/opf" version="2.0">
3
+
4
+ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
5
+ <dc:title>{{title}}</dc:title>
6
+ <dc:language>en</dc:language>
7
+ <dc:creator>{{author}}</dc:creator>
8
+ <dc:date>{{pubdate}}</dc:date>
9
+ <dc:publisher>GitHub.com</dc:publisher>
10
+ <meta name="cover" content="cover"/>
11
+ </metadata>
12
+
13
+ <manifest>
14
+ <item id="book" media-type="application/xhtml+xml" href="book.html"></item>
15
+ <item id="toc_file" media-type="application/xhtml+xml" href="toc.html"></item>
16
+ <item id="toc" media-type="application/x-dtbncx+xml" href="book.ncx"/>
17
+ <item id="cover" media-type="image/jpeg" href="{{cover_image}}"/>
18
+ </manifest>
19
+
20
+ <spine toc="toc">
21
+ <itemref idref="book"/>
22
+ </spine>
23
+
24
+ <guide>
25
+ <reference type="toc" title="Table of Contents" href="toc.html"></reference>
26
+ <reference type="text" title="Contents" href="book.html"></reference>
27
+ </guide>
28
+
29
+ </package>
30
+
@@ -32,9 +32,7 @@ p, ul, ol, dl {
32
32
  margin:10px 0
33
33
  }
34
34
 
35
- dl {
36
- margin-left:40px
37
- }
35
+ dl { }
38
36
 
39
37
  dt {
40
38
  font-weight:normal;
@@ -3,3 +3,5 @@ publish: true
3
3
  edition: 0.1
4
4
  language: en
5
5
  version: 1.0
6
+ author: Your Name
7
+ cover: image/cover.jpg
@@ -76,7 +76,16 @@ context "scribe gen tests" do
76
76
  end
77
77
  end
78
78
 
79
- xtest "scribe can generate docbook" do
79
+ test "scribe can generate docbook" do
80
+ in_temp_dir do
81
+ @scribe.init('t')
82
+ Dir.chdir('t') do
83
+ data = @scribe.gen('docbook')
84
+ assert_equal data, 'book.xml'
85
+ out = Dir.glob('output/**/*')
86
+ assert out.include? 'output/book.xml'
87
+ end
88
+ end
80
89
  end
81
90
 
82
91
  xtest "scribe can generate all" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-scribe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Chacon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-22 00:00:00 -08:00
18
+ date: 2011-02-28 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -1183,6 +1183,7 @@ files:
1183
1183
  - lib/git-scribe/init.rb
1184
1184
  - lib/git-scribe/version.rb
1185
1185
  - lib/subcommand.rb
1186
+ - site/default/book.opf
1186
1187
  - site/default/index.html
1187
1188
  - site/default/master.css
1188
1189
  - site/default/page.html
@@ -1194,6 +1195,7 @@ files:
1194
1195
  - template/README.asciidoc
1195
1196
  - template/book/book.asc
1196
1197
  - template/book/chapter2.asc
1198
+ - template/book/image/cover.jpg
1197
1199
  - template/book/image/octocat_professor.png
1198
1200
  - template/book/include/hello.c
1199
1201
  - test/check_test.rb