Permalink
Browse files

dragonfly middleware added

  • Loading branch information...
1 parent 3b003af commit 5e8a6384c173a78f7cfe7030f0075f3b5f2d6f82 @zlorfi committed Mar 17, 2013
Showing with 32 additions and 14 deletions.
  1. +21 −9 app.rb
  2. +4 −5 config.ru
  3. +7 −0 views/show.haml
View
30 app.rb
@@ -7,20 +7,22 @@
require 'dragonfly'
require 'mongoid'
-#configure { set :server, :puma }
-
class App < Sinatra::Base
configure :production, :development do
enable :logging
end
+ use Dragonfly::Middleware, :images
+
app = Dragonfly[:images].configure_with(:imagemagick)
app.datastore = Dragonfly::DataStorage::FileDataStore.new
app.define_macro_on_include(Mongoid::Document, :image_accessor)
- app.datastore.configure do |d|
- d.root_path = File.join('upload')
+ app.configure do |d|
+ d.datastore.root_path = File.join('upload')
+ d.datastore.server_root = File.join('upload')
+ d.url_format = '/images/:job/:basename.:format'
end
Mongoid.load!('config/mongoid.yml', ENV['RACK_ENV'] )
@@ -55,6 +57,7 @@ class Picture
field :image_uid
field :image_name
+ field :image_width
field :base_path
image_accessor :image
@@ -65,10 +68,6 @@ class Picture
scss :"sass/#{path}"
end
- get "/" do
- haml :index
- end
-
get "/upload" do
haml :upload
end
@@ -78,7 +77,7 @@ class Picture
filename = params[:file][:filename]
file = params[:file][:tempfile]
- image_uid = app.store(file)
+ image_uid = app.store(file, :meta => {:time => Time.now, :name => filename})
picture = Picture.create(image_uid: image_uid, image_name: filename)
flash "Upload successful of #{filename}"
@@ -89,4 +88,17 @@ class Picture
redirect '/upload'
end
+ get '/:image_id' do |image_id|
+ @image = Picture.find(image_id).image
+ haml :show
+ end
+
+ get '/d/:image_id' do |image_id|
+ Picture.find(image_id).image.thumb("200x200#").to_response(env)
+ end
+
+ get "/" do
+ haml :index
+ end
+
end
View
@@ -3,12 +3,11 @@ require 'sinatra'
require 'rack/cache'
require "./app"
-#use Rack::Cache,
-# :metastore => 'file:./tmp/meta',
-# :entitystore => 'file:./tmp/body',
+use Rack::Cache,
+ :metastore => 'file:./tmp/meta',
+ :entitystore => 'file:./tmp/body',
# #:metastore => 'memcached://localhost:11211/meta',
# #:entitystore => 'memcached://localhost:11211/body',
-# :verbose => true
+ :verbose => true
-#run Sinatra::Application
run App
View
@@ -0,0 +1,7 @@
+.row
+ .large-8.columns
+ =# @image.path
+ = @image.remote_url
+ = @image.url
+ %img{:src => "#{@image.thumb('600x600').url}"}/
+ %img{:src => "#{@image.thumb('100x100').url}"}/

0 comments on commit 5e8a638

Please sign in to comment.