Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
314 additions
and
251 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This configuration was generated by | ||
# `rubocop --auto-gen-config` | ||
# on 2017-09-17 09:34:31 +0530 using RuboCop version 0.50.0. | ||
# The point is for the user to remove these configuration records | ||
# one by one as the offenses are removed from the code base. | ||
# Note that changes in the inspected code, or installation of new | ||
# versions of RuboCop, may require this file to be generated again. | ||
|
||
# Offense count: 1 | ||
Metrics/AbcSize: | ||
Max: 16 | ||
|
||
# Offense count: 8 | ||
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. | ||
# URISchemes: http, https | ||
Metrics/LineLength: | ||
Max: 80 | ||
AllowHeredoc: true | ||
AllowURI: true | ||
URISchemes: | ||
- https | ||
- http | ||
IgnoredPatterns: | ||
- \` | ||
|
||
# Offense count: 1 | ||
# Configuration parameters: CountComments. | ||
Metrics/MethodLength: | ||
Max: 22 | ||
|
||
# Offense count: 1 | ||
Metrics/PerceivedComplexity: | ||
Max: 10 | ||
|
||
# Offense count: 2 | ||
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. | ||
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS | ||
Naming/FileName: | ||
Exclude: | ||
- 'wok-reread.rb' | ||
- 'wor-reread.rb' | ||
|
||
# Offense count: 5 | ||
# Configuration parameters: EnforcedStyle, SupportedStyles. | ||
# SupportedStyles: for, each | ||
Style/For: | ||
Exclude: | ||
- 'oathbringer.rb' | ||
- 'wok-reread.rb' | ||
- 'wor-reread.rb' |
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 |
---|---|---|
@@ -1,50 +1,78 @@ | ||
module Nokogiri | ||
module XML | ||
# Patch to add class? | ||
class Node | ||
def class?(*classes) | ||
present = false | ||
if self.attribute('class') | ||
present = true | ||
classes.each do |klass| | ||
present &&= self['class'].include? klass | ||
end | ||
end | ||
present | ||
end | ||
end | ||
end | ||
end | ||
|
||
# https://stackoverflow.com/a/42533209/368328 | ||
def command?(name) | ||
[name, | ||
*ENV['PATH'].split(File::PATH_SEPARATOR).map {|p| File.join(p, name)} | ||
].find {|f| File.executable?(f)} | ||
*ENV['PATH'].split(File::PATH_SEPARATOR) | ||
.map { |p| File.join(p, name) }] | ||
.find { |f| File.executable?(f) } | ||
end | ||
|
||
def commands?(commands) | ||
commands.map {|c| command? c} | ||
commands.map { |c| command? c } | ||
end | ||
|
||
def format_match(format) | ||
[:all, format].include? format | ||
end | ||
|
||
|
||
def generate(name, format=:all) | ||
if command? 'pandoc' and format_match(:epub) | ||
def gen_epub(name, _format) | ||
if command?('pandoc') && format_match(:epub) | ||
# Convert it to epub | ||
`pandoc -S -o books/#{name}.epub --epub-metadata=metadata/#{name}.xml --epub-cover-image=covers/#{name}.jpg books/#{name}.html` | ||
puts "[epub] Generated EPUB file" | ||
puts '[epub] Generated EPUB file' | ||
else | ||
puts "[error] Can't generate EPUB without pandoc" | ||
end | ||
end | ||
|
||
if command? 'ebook-convert' and format_match(:mobi) | ||
def gen_mobi(name, _format) | ||
if command?('ebook-convert') && format_match(:mobi) | ||
# Convert epub to a mobi | ||
`ebook-convert books/#{name}.epub books/#{name}.mobi` | ||
puts "[mobi] Generated MOBI file" | ||
puts '[mobi] Generated MOBI file' | ||
else | ||
puts "[error] Can't generate MOBI without ebook-convert" | ||
end | ||
end | ||
|
||
if commands? ['pandoc', 'convert', 'wkhtmltopdf', 'pdftk'] and format_match(:pdf) | ||
def gen_pdf(name, _format) | ||
if commands?(%w[pandoc convert wkhtmltopdf pdftk]) && format_match(: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` | ||
puts "[pdf] Generated html for pdf" | ||
`pandoc books/#{name}.html -s -c ../style.css -o books/#{name}_pdf.html` | ||
puts '[pdf] Generated html for pdf' | ||
|
||
# Print the pdf_html file to pdf | ||
`wkhtmltopdf #{name}_pdf.html books/#{name}-nocover.pdf` | ||
puts "[pdf] Generated PDF without cover" | ||
`wkhtmltopdf books/#{name}_pdf.html books/#{name}-nocover.pdf` | ||
puts '[pdf] Generated PDF without cover' | ||
|
||
# Join the cover and pdf together | ||
`pdftk covers/#{name}.pdf books/#{name}-nocover.pdf cat output books/#{name}.pdf` | ||
puts "[pdf] Generated PDF file" | ||
puts '[pdf] Generated PDF file' | ||
else | ||
puts "[error] Please check README for PDF dependencies" | ||
puts '[error] Please check README for PDF dependencies' | ||
end | ||
end | ||
|
||
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.