Sha256: b7302c7e4b53f3d7e746a0ff028db901277dc343ffcebb784404b1b5d599a3ea

Contents?: true

Size: 1.31 KB

Versions: 23

Compression:

Stored size: 1.31 KB

Contents

module Softcover
  module Builders
    class Mobi < Builder

      def build!(options={})
        Softcover::Builders::Epub.new.build!(options)
        filename = mobi_filename(options)
        command  = mobi_command(filename, options)
        silent   = options[:silent] || Softcover.test?
        if options[:quiet] || silent
          silence { system(command) }
        else
          system(command)
        end
        if options[:calibre]
          FileUtils.mv("ebooks/#{filename}.azw3", "ebooks/#{filename}.mobi")
          puts "MOBI saved to ebooks/#{filename}.mobi" unless silent
        end
      end

      # Returns the filename of the MOBI (preview if necessary).
      def mobi_filename(options={})
        options[:preview] ? manifest.filename + '-preview' : manifest.filename
      end

      # Returns the command for making a MOBI, based on the options.
      def mobi_command(filename, options={})
        if options[:calibre]
          "#{calibre} ebooks/#{filename}.epub ebooks/#{filename}.azw3"
        else
          "#{kindlegen} ebooks/#{filename}.epub"
        end
      end

      private

        def calibre
          @calibre ||= executable(dependency_filename(:calibre))
        end

        def kindlegen
          @kindlegen ||= executable(dependency_filename(:kindlegen))
        end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
softcover-0.9.23 lib/softcover/builders/mobi.rb
softcover-0.9.22 lib/softcover/builders/mobi.rb
softcover-0.9.21 lib/softcover/builders/mobi.rb
softcover-0.9.20 lib/softcover/builders/mobi.rb
softcover-0.9.19 lib/softcover/builders/mobi.rb
softcover-0.9.18 lib/softcover/builders/mobi.rb
softcover-0.9.17 lib/softcover/builders/mobi.rb
softcover-0.9.16 lib/softcover/builders/mobi.rb
softcover-0.9.15 lib/softcover/builders/mobi.rb
softcover-0.9.13 lib/softcover/builders/mobi.rb
softcover-0.9.12 lib/softcover/builders/mobi.rb
softcover-0.9.11 lib/softcover/builders/mobi.rb
softcover-0.9.10 lib/softcover/builders/mobi.rb
softcover-0.9.9 lib/softcover/builders/mobi.rb
softcover-0.9.8 lib/softcover/builders/mobi.rb
softcover-0.9.7 lib/softcover/builders/mobi.rb
softcover-0.9.6 lib/softcover/builders/mobi.rb
softcover-0.9.5 lib/softcover/builders/mobi.rb
softcover-0.9.4 lib/softcover/builders/mobi.rb
softcover-0.9.3 lib/softcover/builders/mobi.rb