Sha256: a1d7dd3cfb5e86cb358424e9c46e483924c654ebddac8a111a2f45b20d37dd26

Contents?: true

Size: 1.71 KB

Versions: 11

Compression:

Stored size: 1.71 KB

Contents

module Softcover
  module Builders
    class Mobi < Builder
      include Softcover::Utils
      include Softcover::EpubUtils

      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
      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[:kindlegen]
          "#{kindlegen} ebooks/#{filename}.epub"
        else
          "#{calibre} ebooks/#{filename}.epub ebooks/#{filename}.mobi" +
          " #{calibre_options}"
        end
      end

      private

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

        # Returns the options for the Calibre `ebook-convert` CLI.
        def calibre_options
          # Include both Mobipocket & KF8 formats.
          # It took me forever to figure this out. It really should be
          # the Calibre default.
          opts = "--mobi-file-type both"
          if cover?
            opts += " --cover #{cover_img_path}"
            # Get covers to work in Kindle desktop app.
            opts += " --share-not-sync"
          end
          opts
        end

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

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
softcover-1.0.beta10 lib/softcover/builders/mobi.rb
softcover-1.0.beta9 lib/softcover/builders/mobi.rb
softcover-1.0.beta8 lib/softcover/builders/mobi.rb
softcover-1.0.beta7 lib/softcover/builders/mobi.rb
softcover-1.0.beta6 lib/softcover/builders/mobi.rb
softcover-1.0.beta5 lib/softcover/builders/mobi.rb
softcover-1.0.beta4 lib/softcover/builders/mobi.rb
softcover-1.0.beta3 lib/softcover/builders/mobi.rb
softcover-nonstop-1.0.beta2 lib/softcover/builders/mobi.rb
softcover-1.0.beta2 lib/softcover/builders/mobi.rb
softcover-1.0.beta1 lib/softcover/builders/mobi.rb