Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add mobi generation with calibre and checking

  • Loading branch information...
commit 8b13df89ddfd858fba9a4979917b480798cc45e1 1 parent 3cb60cf
@schacon schacon authored
View
1  .gitignore
@@ -1 +1,2 @@
example/output
+output
View
1  TODO.txt
@@ -3,7 +3,6 @@ To-Do List
* custom site layouts
* custom/alternate themes (stylesheets)
-* mobi generation
* cover page for site (author, about, etc)
* book cover (w/template)
* github pages publishing
View
10 lib/git-scribe/check.rb
@@ -50,6 +50,16 @@ def check(args = [])
status[:fop] = false
end
+ # check for calibre
+ if !check_can_run('ebook-convert --version')
+ info "calibre is not present, please install for mobi generation"
+ status[:calibre] = true
+ else
+ info "calibre - ok"
+ status[:calibre] = false
+ end
+
+
status
end
View
18 lib/git-scribe/generate.rb
@@ -2,6 +2,8 @@ class GitScribe
module Generate
# generate the new media
def gen(args = [])
+ @done = {} # what we've generated already
+
type = first_arg(args) || 'all'
prepare_output_dir
@@ -72,17 +74,29 @@ def do_epub
end
def do_mobi
+ do_html
info "GENERATING MOBI"
+ # --cover 'cover.png'
+ # --authors 'Author Name'
+ # --comments "licensed under CC"
+ # --language 'en'
+ cmd = "ebook-convert book.html book.mobi --level1-toc '//h:h1' --level2-toc '//h:h2' --level3-toc '//h:h3'"
+ if ex(cmd)
+ 'book.mobi'
+ end
end
def do_html
+ return true if @done['html']
info "GENERATING HTML"
# TODO: look for custom stylesheets
#puts `#{a2x_wss('xhtml')} -v #{BOOK_FILE}`
styledir = local('stylesheets')
cmd = "asciidoc -a stylesdir=#{styledir} -a theme=handbookish #{BOOK_FILE}"
- ex(cmd)
- 'book.html'
+ if ex(cmd)
+ @done['html'] == true
+ 'book.html'
+ end
end
def do_site
View
4 site/default/index.html
@@ -6,8 +6,8 @@
<title>{{book_title}}</title>
</head>
<body>
- Mobi (Kindle) |
<a href="book.epub">Epub (iBooks)</a> |
+ <a href="book.mobi">Mobi (Kindle)</a> |
<a href="book.html">Single Page</a> |
<a href="book.pdf">PDF</a>
<hr/>
@@ -35,8 +35,8 @@
</div>
</div>
<hr/>
- Mobi (Kindle) |
<a href="book.epub">Epub (iBooks)</a> |
+ <a href="book.mobi">Mobi (Kindle)</a> |
<a href="book.html">Single Page</a> |
<a href="book.pdf">PDF</a>
</body>
View
2  test/check_test.rb
@@ -7,6 +7,6 @@
test "scribe can check for programs it needs" do
status = @scribe.check
- assert_equal status.size, 5
+ assert_equal status.size, 6
end
end
View
13 test/gen_test.rb
@@ -64,10 +64,19 @@
end
end
- xtest "scribe can generate docbook" do
+ test "scribe can generate a mobi" do
+ in_temp_dir do
+ @scribe.init('t')
+ Dir.chdir('t') do
+ data = @scribe.gen('mobi')
+ assert_equal data, 'book.mobi'
+ out = Dir.glob('output/**/*')
+ assert out.include? 'output/book.mobi'
+ end
+ end
end
- xtest "scribe can generate a mobi" do
+ xtest "scribe can generate docbook" do
end
xtest "scribe can generate all" do
Please sign in to comment.
Something went wrong with that request. Please try again.