Class: Bookshelf::Exporter
- Inherits:
-
Object
- Object
- Bookshelf::Exporter
- Defined in:
- lib/bookshelf/exporter.rb
Instance Attribute Summary collapse
-
#book_dir ⇒ Object
Returns the value of attribute book_dir.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #export! ⇒ Object
- #export_assets ⇒ Object
-
#initialize(book_dir, options) ⇒ Exporter
constructor
A new instance of Exporter.
- #ui ⇒ Object
Constructor Details
#initialize(book_dir, options) ⇒ Exporter
Returns a new instance of Exporter.
11 12 13 14 |
# File 'lib/bookshelf/exporter.rb', line 11 def initialize(book_dir, ) @book_dir = book_dir @options = end |
Instance Attribute Details
#book_dir ⇒ Object
Returns the value of attribute book_dir.
8 9 10 |
# File 'lib/bookshelf/exporter.rb', line 8 def book_dir @book_dir end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/bookshelf/exporter.rb', line 9 def @options end |
Class Method Details
.run(book_dir, options) ⇒ Object
3 4 5 6 |
# File 'lib/bookshelf/exporter.rb', line 3 def self.run(book_dir, ) exporter = new(book_dir, ) exporter.export! end |
Instance Method Details
#config ⇒ Object
60 61 62 |
# File 'lib/bookshelf/exporter.rb', line 60 def config Bookshelf.config end |
#export! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bookshelf/exporter.rb', line 31 def export! helper = Bookshelf.root_dir.join("config/helper.rb") load(helper) if helper.exist? export_assets export_pdf = [nil, "pdf"].include?([:only]) export_epub = [nil, "epub"].include?([: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 if exported.all? color = :green = [: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 = [:auto] ? "could not be exported!" : "** e-book couldn't be exported" end ui.say , color end |
#export_assets ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bookshelf/exporter.rb', line 20 def export_assets FileUtils.mkdir_p("output/assets/fonts") FileUtils.mkdir_p("output/assets/images") FileUtils.mkdir_p("output/assets/styles") FileUtils.cp_r(Dir.glob('assets/fonts/*'), "output/assets/fonts/") FileUtils.cp_r(Dir.glob('assets/images/*'), "output/assets/images/") ["epub","html"].each do |style_sheet| `sass assets/styles/#{style_sheet}.scss output/assets/styles/#{style_sheet}.css` end end |
#ui ⇒ Object
16 17 18 |
# File 'lib/bookshelf/exporter.rb', line 16 def ui @ui ||= Thor::Base.shell.new end |