Sha256: dbe5e9c5fc451840403a05449e5bf8ec5b529f723d3538bb2062e8278b86c5c6

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module Locomotive
  module Dragonfly

    def self.resize_url(source, resize_string)
      if file = self.fetch_file(source)
        file.thumb(resize_string).url
      else
        Locomotive.log :error, "Unable to resize on the fly: #{source.inspect}"
        return
      end
    end

    def self.thumbnail_pdf(source, resize_string)
      if file = self.fetch_file(source)
        file.thumb(resize_string, format: 'png', frame: 0).encode('png').url
      else
        Locomotive.log :error, "Unable to convert the pdf: #{source.inspect}"
        return
      end
    end

    def self.fetch_file(source)
      file = nil

      if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset
        source = source['url'] if source.is_a?(Hash)

        source.strip!

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

      elsif source.respond_to?(:url) # carrierwave uploader
        if source.file.respond_to?(:url)
          file = self.app.fetch_url(source.url) # amazon s3, cloud files, ...etc
        else
          file = self.app.fetch_file(source.path)
        end

      end

      file
    end

    def self.app
      ::Dragonfly.app
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
locomotive_cms-2.5.0 lib/locomotive/dragonfly.rb
locomotive_cms-2.5.0.rc3 lib/locomotive/dragonfly.rb
locomotive_cms-2.5.0.rc2 lib/locomotive/dragonfly.rb
locomotive_cms-2.5.0.rc1 lib/locomotive/dragonfly.rb