config/initializers/dragonfly.rb in smithycms-0.0.3 vs config/initializers/dragonfly.rb in smithycms-0.4.0

- old
+ new

@@ -1,48 +1,28 @@ -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) +# Configure +Dragonfly.app.configure do + plugin :imagemagick -# set the cache lifetime -app.cache_duration = 3600*24*365*3 # 3 years in seconds + protect_from_dos_attacks true + secret "7fb765cbc9f1d92d5d1a56a43193d34d4f9b54dced3e62cb4e42f25d2500dd0f" -### Extend active record ### -app.define_macro(ActiveRecord::Base, :image_accessor) -app.define_macro(ActiveRecord::Base, :file_accessor) + convert_command = `which convert`.strip.presence || "/usr/local/bin/convert" + identify_command = `which identify`.strip.presence || "/usr/local/bin/identify" -## 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" + url_format '/uploads/assets/:job/:basename.:format' - c.allow_fetch_url = true - c.allow_fetch_file = true - - c.url_format = '/uploads/assets/:job/:basename.:format' + datastore Smithy::Asset.dragonfly_datastore end -app.datastore = Smithy::Asset.dragonfly_datastore +# Logger +Dragonfly.logger = Rails.logger -# ### Insert the middleware ### -rack_cache_already_inserted = Rails.application.config.action_controller.perform_caching && Rails.application.config.action_dispatch.rack_cache +# Mount as middleware +Rails.application.middleware.use Dragonfly::Middleware -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 +# Add model functionality +if defined?(ActiveRecord::Base) + ActiveRecord::Base.extend Dragonfly::Model + ActiveRecord::Base.extend Dragonfly::Model::Validations +end