Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixes #4
- Loading branch information
Showing
5 changed files
with
201 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ module XML | |
class Node | ||
def class?(*classes) | ||
present = false | ||
if self.attribute('class') | ||
if attribute('class') | ||
present = true | ||
classes.each do |klass| | ||
present &&= self['class'].include? klass | ||
|
@@ -32,26 +32,26 @@ def format_match(format, format_to_match) | |
[:all, format_to_match].include? format | ||
end | ||
|
||
def gen_epub(name, _format) | ||
if format_match(_format, :epub) | ||
begin | ||
require "paru/pandoc" | ||
Paru::Pandoc.new do | ||
from "html" | ||
to "epub" | ||
epub_metadata "metadata/#{name}.xml" | ||
epub_cover_image "covers/#{name}.jpg" | ||
output "books/#{name}.epub" | ||
end.convert File.read("books/#{name}.html") | ||
puts '[epub] Generated EPUB file' | ||
rescue LoadError | ||
puts "[error] Can't generate EPUB without paru" | ||
end | ||
def gen_epub(name, format) | ||
return unless format_match(format, :epub) | ||
begin | ||
require 'paru/pandoc' | ||
Paru::Pandoc.new do | ||
from 'html' | ||
to 'epub' | ||
epub_metadata "metadata/#{name}.xml" | ||
epub_cover_image "covers/#{name}.jpg" | ||
epub_stylesheet "style.css" | ||
output "books/#{name}.epub" | ||
end.convert File.read("books/#{name}.html") | ||
puts '[epub] Generated EPUB file' | ||
rescue LoadError | ||
puts "[error] Can't generate EPUB without paru" | ||
end | ||
end | ||
|
||
def gen_mobi(name, _format) | ||
if command?('ebook-convert') && format_match(_format, :mobi) | ||
def gen_mobi(name, format) | ||
if command?('ebook-convert') && format_match(format, :mobi) | ||
# Convert epub to a mobi | ||
`ebook-convert books/#{name}.epub books/#{name}.mobi` | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
captn3m0
Author
Owner
|
||
puts '[mobi] Generated MOBI file' | ||
|
@@ -60,8 +60,8 @@ def gen_mobi(name, _format) | |
end | ||
end | ||
|
||
def gen_pdf(name, _format) | ||
if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(_format, :pdf) | ||
def gen_pdf(name, format) | ||
if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(format, :pdf) | ||
# Generate PDF as well | ||
# First, lets make a better css version of the html | ||
`pandoc books/#{name}.html -s -c ../style.css -o books/#{name}_pdf.html` | ||
|
@@ -79,8 +79,8 @@ def gen_pdf(name, _format) | |
end | ||
end | ||
|
||
def generate(name, _format = :all) | ||
gen_epub(name, _format) | ||
gen_mobi(name, _format) | ||
gen_pdf(name, _format) | ||
def generate(name, format = :all) | ||
gen_epub(name, format) | ||
gen_mobi(name, format) | ||
gen_pdf(name, format) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Does this mean mobi depends on epub? so enabling ":mobi" format only would either fail, or continually convert an older/outdated epub file ?