Sha256: 115cf61d97d8e6433e32c21a9ae5113a48746bde99c9924efeb50a2a6bbbf731

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

require 'uri'
require 'dragonfly'
begin
  require 'rack/cache'
rescue LoadError => e
  puts "Couldn't find rack-cache - make sure you have it in your Gemfile:"
  puts "  gem 'rack-cache', :require => 'rack/cache'"
  puts " or configure dragonfly manually instead of using 'dragonfly/rails/images'"
  raise e
end

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

# set the cache lifetime
app.cache_duration = 3600*24*365*3  # 3 years in seconds

### Extend active record ###
app.define_macro(ActiveRecord::Base, :image_accessor)
app.define_macro(ActiveRecord::Base, :file_accessor)

## configure it ##
Dragonfly[:files].configure do |c|
  # Convert absolute location needs to be specified
  # to avoid issues with Phusion Passenger not using $PATH
  c.convert_command  = `which convert`.strip.presence || "/usr/local/bin/convert"
  c.identify_command = `which identify`.strip.presence || "/usr/local/bin/identify"

  c.allow_fetch_url  = true
  c.allow_fetch_file = true

  c.url_format = '/uploads/assets/:job/:basename.:format'
end

app.datastore = Smithy::Asset.dragonfly_datastore

# ### Insert the middleware ###
rack_cache_already_inserted = Rails.application.config.action_controller.perform_caching && Rails.application.config.action_dispatch.rack_cache

Rails.application.middleware.insert 0, Rack::Cache, {
  :verbose     => true,
  :metastore   => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
  :entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
} unless rack_cache_already_inserted

Rails.application.middleware.insert_after Rack::Cache, Dragonfly::Middleware, :files

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
smithycms-0.0.3 config/initializers/dragonfly.rb
smithycms-0.0.2 config/initializers/dragonfly.rb
smithycms-0.0.1 config/initializers/dragonfly.rb