Sha256: c4a98c76f6dd95f2e09accb7c30a5deeab9f74bcec18d642d2cfdc2a939d83f9
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
module Bookshelf class Exporter def self.run(book_dir, options) exporter = new(book_dir, options) exporter.export! end attr_accessor :book_dir attr_accessor :options def initialize(book_dir, options) @book_dir = book_dir @options = options end def ui @ui ||= Thor::Base.shell.new end def export! helper = Bookshelf.root_dir.join("config/helper.rb") load(helper) if helper.exist? export_pdf = [nil, "pdf"].include?(options[:only]) export_epub = [nil, "mobi", "epub"].include?(options[:only]) export_mobi = [nil, "mobi"].include?(options[:only]) export_txt = [nil, "txt"].include?(options[:only]) exported = [] exported << Parser::HTML.parse(book_dir) exported << Parser::PDF.parse(book_dir) if export_pdf && Dependency.prince? exported << Parser::Epub.parse(book_dir) if export_epub exported << Parser::Mobi.parse(book_dir) if export_mobi && Dependency.kindlegen? exported << Parser::Txt.parse(book_dir) if export_txt && Dependency.html2text? if exported.all? color = :green message = options[:auto] ? "exported!" : "** e-book has been exported" Notifier.notify( :image => Bookshelf::ROOT.join("templates/ebook.png"), :title => "Bookshelf", :message => "Your \"#{config[:title]}\" e-book has been exported!" ) else color = :red message = options[:auto] ? "could not be exported!" : "** e-book couldn't be exported" end ui.say message, color end def config Bookshelf.config end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bookshelf-1.1.0 | lib/bookshelf/exporter.rb |