Sha256: 41eb04309072748e354a37e9081a4606722339abbb3348f231a28f97247d6736

Contents?: true

Size: 1.96 KB

Versions: 19

Compression:

Stored size: 1.96 KB

Contents

module Locomotive
  module Wagon
    class Dragonfly

      attr_accessor :path, :enabled

      def enabled?
        !!self.enabled
      end

      def resize_url(source, resize_string)
        _source = (case source
        when String then source
        when Hash   then source['url'] || source[:url]
        else
          source.try(:url)
        end)

        if _source.blank?
          Locomotive::Wagon::Logger.error "Unable to resize on the fly: #{source.inspect}"
          return
        end

        return _source unless self.enabled?

        if _source =~ /^http/
          file = self.class.app.fetch_url(_source)
        else
          file = self.class.app.fetch_file(File.join(self.path, 'public', _source))
        end

        file.process(:thumb, resize_string).url
      end

      def self.app
        ::Dragonfly[:images]
      end


      def self.instance
        @@instance ||= new
      end

      def self.setup!(path)
        self.instance.path    = path
        self.instance.enabled = false

        begin
          require 'rack/cache'
          require 'dragonfly'

          ## initialize Dragonfly ##
          app = ::Dragonfly[:images].configure_with(:imagemagick)

          ## configure it ##
          ::Dragonfly[:images].configure do |c|
            convert = `which convert`.strip.presence || '/usr/bin/env convert'
            c.convert_command  = convert
            c.identify_command = convert

            c.allow_fetch_url  = true
            c.allow_fetch_file = true

            c.url_format = '/images/dynamic/:job/:basename.:format'
          end

          self.instance.enabled = true
        rescue Exception => e
          Locomotive::Wagon::Logger.warn %{
[Dragonfly] !disabled!
[Dragonfly] If you want to take full benefits of all the features in the LocomotiveWagon, we recommend you to install ImageMagick and RMagick. Check out the documentation here: http://doc.locomotivecms.com/editor/installation.
}
        end
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.5.8 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.7 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.6 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.5 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.4 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.3 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.2 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.1 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.0 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.5.0.rc1 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.4.0 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.3.3 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.3.2 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.3.1 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.3.0 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.2.2 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/misc/dragonfly.rb
locomotivecms_wagon-1.1.0 lib/locomotive/wagon/misc/dragonfly.rb