Skip to content

Commit

Permalink
copied over jeisenbergs changes and made s3 credentials config based
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Duesing committed May 23, 2012
1 parent 04691b2 commit 125feb2
Show file tree
Hide file tree
Showing 27 changed files with 2,370 additions and 10 deletions.
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ gem 'redcarpet'
gem 'stringex', '~> 1', git: 'git://github.com/rsl/stringex.git'
gem 'kaminari', '~> 0.13'

# Photo uploads
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"

# storage
gem 'aws-s3', :require => 'aws/s3'
gem 'aws-sdk'

group :production do
# gem 'newrelic_rpm', '~> 3'
# gem 'dalli', '~> 1'
Expand Down Expand Up @@ -47,3 +54,4 @@ group :assets do
gem 'coffee-rails', '~> 3'
gem 'uglifier', '~> 1'
end

30 changes: 30 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ GIT
specs:
stringex (1.3.2)

GIT
remote: git://github.com/thoughtbot/paperclip.git
revision: a19f2a4df3d31427cb8404e90d79609fbe45f001
specs:
paperclip (3.0.4)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -35,6 +46,15 @@ GEM
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
aws-s3 (0.6.2)
builder
mime-types
xml-simple
aws-sdk (1.3.6)
httparty (~> 0.7)
json (~> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
builder (3.0.0)
capybara (1.1.2)
mime-types (>= 1.16)
Expand All @@ -45,6 +65,7 @@ GEM
xpath (~> 0.1.4)
childprocess (0.3.1)
ffi (~> 1.0.6)
cocaine (0.2.1)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
Expand Down Expand Up @@ -73,6 +94,9 @@ GEM
thor (>= 0.13.6)
win32console (~> 1.3.0)
hike (1.2.1)
httparty (0.8.1)
multi_json
multi_xml
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.1)
Expand All @@ -89,6 +113,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.1.0)
multi_xml (0.4.2)
nokogiri (1.5.2)
nokogiri (1.5.2-x86-mingw32)
pg (0.13.2)
Expand Down Expand Up @@ -162,6 +187,7 @@ GEM
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
uuidtools (2.1.2)
win32-api (1.4.8-x86-mingw32)
win32-process (0.6.5)
windows-pr (>= 1.1.2)
Expand All @@ -171,6 +197,7 @@ GEM
windows-pr (1.2.1)
win32-api (>= 1.4.5)
windows-api (>= 0.3.0)
xml-simple (1.1.1)
xpath (0.1.4)
nokogiri (~> 1.3)

Expand All @@ -179,6 +206,8 @@ PLATFORMS
x86-mingw32

DEPENDENCIES
aws-s3
aws-sdk
capybara (~> 1)
coffee-rails (~> 3)
database_cleaner (~> 0.7)
Expand All @@ -187,6 +216,7 @@ DEPENDENCIES
foreman (~> 0.40)
jquery-rails (~> 2)
kaminari (~> 0.13)
paperclip!
pg (~> 0.13)
rails (~> 3)
rails_best_practices (~> 1)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/inline_images.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
160 changes: 160 additions & 0 deletions app/assets/javascripts/jquery.fileupload-ip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* jQuery File Upload Image Processing Plugin 1.0.6
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/

/*jslint nomen: true, unparam: true, regexp: true */
/*global define, window, document */

(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'load-image',
'canvas-to-blob',
'./jquery.fileupload'
], factory);
} else {
// Browser globals:
factory(
window.jQuery,
window.loadImage,
window.canvasToBlob
);
}
}(function ($, loadImage, canvasToBlob) {
'use strict';

// The File Upload IP version extends the basic fileupload widget
// with image processing functionality:
$.widget('blueimpIP.fileupload', $.blueimp.fileupload, {

options: {
// The regular expression to define which image files are to be
// resized, given that the browser supports the operation:
resizeSourceFileTypes: /^image\/(gif|jpeg|png)$/,
// The maximum file size of images that are to be resized:
resizeSourceMaxFileSize: 20000000, // 20MB
// The maximum width of the resized images:
resizeMaxWidth: undefined,
// The maximum height of the resized images:
resizeMaxHeight: undefined,
// The minimum width of the resized images:
resizeMinWidth: undefined,
// The minimum height of the resized images:
resizeMinHeight: undefined,

// The add callback is invoked as soon as files are added to the fileupload
// widget (via file input selection, drag & drop or add API call).
// See the basic file upload widget for more information:
add: function (e, data) {
$(this).fileupload('resize', data).done(function () {
data.submit();
});
}
},

// Resizes the image file at the given index and stores the created blob
// at the original position of the files list, returns a Promise object:
_resizeImage: function (files, index, options) {
var that = this,
file = files[index],
deferred = $.Deferred(),
canvas,
blob;
options = options || this.options;
loadImage(
file,
function (img) {
var width = img.width,
height = img.height;
canvas = loadImage.scale(img, {
maxWidth: options.resizeMaxWidth,
maxHeight: options.resizeMaxHeight,
minWidth: options.resizeMinWidth,
minHeight: options.resizeMinHeight,
canvas: true
});
if (width !== canvas.width || height !== canvas.height) {
canvasToBlob(canvas, function (blob) {
if (!blob.name) {
if (file.type === blob.type) {
blob.name = file.name;
} else if (file.name) {
blob.name = file.name.replace(
/\..+$/,
'.' + blob.type.substr(6)
);
}
}
files[index] = blob;
deferred.resolveWith(that);
}, file);
} else {
deferred.resolveWith(that);
}
}
);
return deferred.promise();
},

// Resizes the images given as files property of the data parameter,
// returns a Promise object that allows to bind a done handler, which
// will be invoked after processing all images is done:
resize: function (data) {
var that = this,
options = $.extend({}, this.options, data),
resizeAll = $.type(options.resizeSourceMaxFileSize) !== 'number',
isXHRUpload = this._isXHRUpload(options);
$.each(data.files, function (index, file) {
if (isXHRUpload && that._resizeSupport &&
(options.resizeMaxWidth || options.resizeMaxHeight ||
options.resizeMinWidth || options.resizeMinHeight) &&
(resizeAll || file.size < options.resizeSourceMaxFileSize) &&
options.resizeSourceFileTypes.test(file.type)) {
that._processing += 1;
if (that._processing === 1) {
that.element.addClass('fileupload-processing');
}
that._processingQueue = that._processingQueue.pipe(function () {
var deferred = $.Deferred();
that._resizeImage(
data.files,
index,
options
).done(function () {
that._processing -= 1;
if (that._processing === 0) {
that.element
.removeClass('fileupload-processing');
}
deferred.resolveWith(that);
});
return deferred.promise();
});
}
});
return this._processingQueue;
},

_create: function () {
$.blueimp.fileupload.prototype._create.call(this);
this._processing = 0;
this._processingQueue = $.Deferred().resolveWith(this).promise();
this._resizeSupport = canvasToBlob && canvasToBlob(
document.createElement('canvas'),
$.noop
);
}

});

}));
Loading

1 comment on commit 125feb2

@natew
Copy link

@natew natew commented on 125feb2 Dec 29, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at merging this into the refresh branch shortly.

Please sign in to comment.