Sha256: 3cb56e929bf2c3af365c1f2319095641c0d5440333dec5abc4cd9cf364cbb1af

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

module Locomotive
  module Steam
    module Services
      class Dragonfly

        attr_reader :path

        def initialize(path = nil)
          @path = path
        end

        def enabled?
          !!self.enabled
        end

        def resize_url(source, resize_string)
          image = (case url_or_path = get_url_or_path(source)
          when '', nil
            Locomotive::Common::Logger.error "Unable to resize on the fly: #{source.inspect}"
            nil
          when /^http:\/\//
            app.fetch_url(url_or_path)
          else
            app.fetch_file(File.join([self.path, 'public', url_or_path].compact))
          end)

          # apply the conversion if possible
          image ? image.thumb(resize_string).url : source
        end

        def self.app
          ::Dragonfly.app
        end

        protected

        def get_url_or_path(source)
          case source
          when String   then source.strip
          when Hash     then source['url'] || source[:url]
          else
            source.try(:url)
          end
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
locomotivecms_steam-0.1.2.pre.beta lib/locomotive/steam/services/dragonfly.rb
locomotivecms_steam-0.1.1 lib/locomotive/steam/services/dragonfly.rb