Module: GitScribe::Generate

Included in:
GitScribe
Defined in:
lib/git-scribe/generate.rb

Instance Method Summary collapse

Instance Method Details

#do_docbookObject



30
31
32
33
34
35
36
37
38
# File 'lib/git-scribe/generate.rb', line 30

def do_docbook
  return true if @done['docbook']
  info "GENERATING DOCBOOK"

  if ex("asciidoc -b docbook --doctype book -v #{BOOK_FILE}")
    @done['docbook'] = true
    'book.xml'
  end
end

#do_ebookObject



108
109
110
111
112
113
# File 'lib/git-scribe/generate.rb', line 108

def do_ebook
  do_pdf
  do_epub
  do_mobi
  zip_ebook
end

#do_epubObject



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/git-scribe/generate.rb', line 75

def do_epub
  return true if @done['epub']

  info "GENERATING EPUB"

  generate_docinfo
  # TODO: look for custom stylesheets
  cmd = "#{a2x_wss('epub')} -a docinfo -k --icons -r images/icons/note.png -r images/icons/caution.png -r images/icons/important.png -r images/icons/tip.png -r images/icons/warning.png -v #{BOOK_FILE}"
  return false unless ex(cmd)

  @done['epub'] = true
end

#do_htmlObject



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/git-scribe/generate.rb', line 115

def do_html
  return true if @done['html']
  info "GENERATING HTML"

  # TODO: look for custom stylesheets
  stylesheet = local('stylesheets') + '/scribe.css'
  cmd = "asciidoc -a stylesheet=#{stylesheet} #{BOOK_FILE}"
  if ex(cmd)
    @done['html'] == true
    'book.html'
  end
end

#do_mobiObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/git-scribe/generate.rb', line 88

def do_mobi
  return true if @done['mobi']

  do_epub

  info "GENERATING MOBI"

  decorate_epub_for_mobi

  cmd = "kindlegen -verbose book_for_mobi.epub -o book.mobi"
  return false unless ex(cmd)

  cmd = @wd +  '/scripts/post-mobi.sh'
  if File.exists?(cmd) && File.executable?(cmd)
    return false unless ex(cmd)
  end

  @done['mobi'] = true
end

#do_pdfObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/git-scribe/generate.rb', line 40

def do_pdf
  return true if @done['pdf']

  info "GENERATING PDF"
  do_docbook

  @decorate.docbook

  # TODO: start chapters on the recto page
  # (initial.page.number=auto-odd? break.before=page-even?)
  strparams = {
    'callout.graphics' => 1,
    'navig.graphics' => 1,
    'admon.textlabel' => 1,
    'admon.graphics' => 1,
    'page.width' => '7.5in',
    'page.height' => '9in',
    'body.font.family' => "'URW Bookman L'",
    'title.font.family' => "'URW Bookman L'",
    'monospace.font.family' => "'LiberationMono'"
    # 'monospace.font.family' => "'DroidSansMono'"
  }
  param = strparams.map { |k, v| "--stringparam #{k} #{v}" }.join(' ')
  cmd = "xsltproc  --nonet #{param} --output #{local('book.fo')} #{base('docbook-xsl/fo.xsl')} #{local('book.xml')}"
  ex(cmd)

  @decorate.fop

  cmd = "fop -c #{base('docbook-xsl/fop.xconf')} -fo #{local('book.fo')} -pdf #{local('book.pdf')}"
  ex(cmd)

  return false unless $?.exitstatus == 0
  @done['pdf'] = true
end

#do_siteObject



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/git-scribe/generate.rb', line 128

def do_site
  info "GENERATING SITE"

  prepare_output_dir("site")
  Dir.chdir("site") do
    ex("asciidoc -b docbook #{BOOK_FILE}")
    xsldir = base('docbook-xsl/xhtml')
    ex("xsltproc --stringparam html.stylesheet stylesheets/scribe.css --nonet #{xsldir}/chunk.xsl book.xml")

    clean_site
  end
end

#gen(args = []) ⇒ Object

generate the new media



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/git-scribe/generate.rb', line 4

def gen(args = [])
  @done = {}  # what we've generated already
  @remove_when_done = []
  @wd = Dir.getwd

  type = first_arg(args) || 'all'
  prepare_output_dir

  types = type == 'all' ? OUTPUT_TYPES : [type]

  ret = false
  output = []
  Dir.chdir("output") do
    types.each do |out_type|
      call = 'do_' + out_type
      if self.respond_to? call
        ret = self.send call
      else
        die "NOT A THING: #{call}"
      end
    end
    clean_up
    ret
  end
end