applicious_utils 0.1.30 → 0.1.31

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,148 +1,150 @@
1
1
  module AppliciousUtils
2
+ module ViewHelpers
2
3
 
3
- # Creates an instance of a plupload S3 file uploader
4
- ###
5
- # required parameters:
6
- ###
7
- # key s3 'path' to uploaded files
8
- #
9
- ###
10
- # optional parameters:
11
- ###
12
- # s3_config_filename filename of s3 config yaml file (full path), defaults to "#{RAILS_ROOT}/config/amazon_s3.yml"
13
- #
14
- # content_type binary/octet-stream
15
- #
16
- # acl public-read
17
- #
18
- # expiration_date 10.hours.from_now.utc.iso8601
19
- #
20
- # max_filesize 2.megabytes
4
+ # Creates an instance of a plupload S3 file uploader
5
+ ###
6
+ # required parameters:
7
+ ###
8
+ # key s3 'path' to uploaded files
9
+ #
10
+ ###
11
+ # optional parameters:
12
+ ###
13
+ # s3_config_filename filename of s3 config yaml file (full path), defaults to "#{RAILS_ROOT}/config/amazon_s3.yml"
14
+ #
15
+ # content_type binary/octet-stream
16
+ #
17
+ # acl public-read
18
+ #
19
+ # expiration_date 10.hours.from_now.utc.iso8601
20
+ #
21
+ # max_filesize 2.megabytes
21
22
 
22
- def s3_uploader(options = {})
23
- options[:s3_config_filename] ||= "#{Rails.root}/config/amazon_s3.yml"
24
- config = YAML.load_file(options[:s3_config_filename])[Rails.env].symbolize_keys
25
- bucket = config[:bucket_name]
26
- access_key_id = config[:access_key_id]
27
- secret_access_key = config[:secret_access_key]
23
+ def s3_uploader(options = {})
24
+ options[:s3_config_filename] ||= "#{Rails.root}/config/amazon_s3.yml"
25
+ config = YAML.load_file(options[:s3_config_filename])[Rails.env].symbolize_keys
26
+ bucket = config[:bucket_name]
27
+ access_key_id = config[:access_key_id]
28
+ secret_access_key = config[:secret_access_key]
28
29
 
29
- options[:key] ||= 'test' # folder on AWS to store file in
30
- options[:acl] ||= 'public-read'
31
- options[:expiration_date] ||= 10.hours.from_now.utc.iso8601
32
- options[:max_filesize] ||= 500.megabytes
33
- options[:content_type] ||= 'image/' # Videos would be binary/octet-stream
34
- options[:filter_title] ||= 'Images'
35
- options[:filter_extentions] ||= 'jpg,jpeg,gif,png,bmp'
30
+ options[:key] ||= 'test' # folder on AWS to store file in
31
+ options[:acl] ||= 'public-read'
32
+ options[:expiration_date] ||= 10.hours.from_now.utc.iso8601
33
+ options[:max_filesize] ||= 500.megabytes
34
+ options[:content_type] ||= 'image/' # Videos would be binary/octet-stream
35
+ options[:filter_title] ||= 'Images'
36
+ options[:filter_extentions] ||= 'jpg,jpeg,gif,png,bmp'
36
37
 
37
- id = options[:id] ? "_#{options[:id]}" : ''
38
+ id = options[:id] ? "_#{options[:id]}" : ''
38
39
 
39
- policy = Base64.encode64(
40
- "{'expiration': '#{options[:expiration_date]}',
41
- 'conditions': [
42
- {'bucket': '#{bucket}'},
43
- {'acl': '#{options[:acl]}'},
44
- {'success_action_status': '201'},
45
- ['content-length-range', 0, #{options[:max_filesize]}],
46
- ['starts-with', '$key', ''],
47
- ['starts-with', '$Content-Type', ''],
48
- ['starts-with', '$name', ''],
49
- ['starts-with', '$Filename', '']
50
- ]
51
- }").gsub(/\n|\r/, '')
40
+ policy = Base64.encode64(
41
+ "{'expiration': '#{options[:expiration_date]}',
42
+ 'conditions': [
43
+ {'bucket': '#{bucket}'},
44
+ {'acl': '#{options[:acl]}'},
45
+ {'success_action_status': '201'},
46
+ ['content-length-range', 0, #{options[:max_filesize]}],
47
+ ['starts-with', '$key', ''],
48
+ ['starts-with', '$Content-Type', ''],
49
+ ['starts-with', '$name', ''],
50
+ ['starts-with', '$Filename', '']
51
+ ]
52
+ }").gsub(/\n|\r/, '')
52
53
 
53
- signature = Base64.encode64(
54
- OpenSSL::HMAC.digest(
55
- OpenSSL::Digest::Digest.new('sha1'),
56
- secret_access_key, policy)).gsub("\n","")
54
+ signature = Base64.encode64(
55
+ OpenSSL::HMAC.digest(
56
+ OpenSSL::Digest::Digest.new('sha1'),
57
+ secret_access_key, policy)).gsub("\n","")
57
58
 
58
- out = ""
59
+ out = ""
59
60
 
60
- out << javascript_tag("$(function() {
61
+ out << javascript_tag("$(function() {
61
62
 
62
- /*
63
- * S3 Uploader instance
64
- */
65
- // image uploader via plupload
66
- var uploader = new plupload.Uploader({
67
- runtimes : 'html5,flash,silverlight',
68
- browse_button : 'pickfiles',
69
- max_file_size : '500mb',
70
- url : 'http://#{bucket}.s3.amazonaws.com/',
71
- flash_swf_url: 'applicious/plupload/plupload.flash.swf',
72
- silverlight_xap_url: '/applicious/plupload/plupload.silverlight.xap',
73
- init : {
74
- FilesAdded: function(up, files) {
75
- plupload.each(files, function(file) {
76
- if (up.files.length > 1) {
77
- up.removeFile(file);
63
+ /*
64
+ * S3 Uploader instance
65
+ */
66
+ // image uploader via plupload
67
+ var uploader = new plupload.Uploader({
68
+ runtimes : 'html5,flash,silverlight',
69
+ browse_button : 'pickfiles',
70
+ max_file_size : '500mb',
71
+ url : 'http://#{bucket}.s3.amazonaws.com/',
72
+ flash_swf_url: 'applicious/plupload/plupload.flash.swf',
73
+ silverlight_xap_url: '/applicious/plupload/plupload.silverlight.xap',
74
+ init : {
75
+ FilesAdded: function(up, files) {
76
+ plupload.each(files, function(file) {
77
+ if (up.files.length > 1) {
78
+ up.removeFile(file);
79
+ }
80
+ });
81
+ if (up.files.length >= 1) {
82
+ $('#pickfiles').fadeOut('slow');
83
+ }
84
+ },
85
+ FilesRemoved: function(up, files) {
86
+ if (up.files.length < 1) {
87
+ $('#pickfiles').fadeIn('slow');
78
88
  }
79
- });
80
- if (up.files.length >= 1) {
81
- $('#pickfiles').fadeOut('slow');
82
89
  }
83
90
  },
84
- FilesRemoved: function(up, files) {
85
- if (up.files.length < 1) {
86
- $('#pickfiles').fadeIn('slow');
87
- }
88
- }
89
- },
90
- multi_selection: false,
91
- multipart: true,
92
- multipart_params: {
93
- 'key': 'test/${filename}',
94
- 'Filename': '${filename}', // adding this to keep consistency across the runtimes
95
- 'acl': '#{options[:acl]}',
96
- 'Content-Type': '#{options[:content_type]}',
97
- 'success_action_status': '201',
98
- 'AWSAccessKeyId' : '#{access_key_id}',
99
- 'policy': '#{policy}',
100
- 'signature': '#{signature}'
101
- },
102
- filters : [
103
- {title : '#{options[:filter_title]}', extensions : '#{options[:filter_extentions]}'}
104
- ],
105
- file_data_name: 'file'
106
- });
91
+ multi_selection: false,
92
+ multipart: true,
93
+ multipart_params: {
94
+ 'key': 'test/${filename}',
95
+ 'Filename': '${filename}', // adding this to keep consistency across the runtimes
96
+ 'acl': '#{options[:acl]}',
97
+ 'Content-Type': '#{options[:content_type]}',
98
+ 'success_action_status': '201',
99
+ 'AWSAccessKeyId' : '#{access_key_id}',
100
+ 'policy': '#{policy}',
101
+ 'signature': '#{signature}'
102
+ },
103
+ filters : [
104
+ {title : '#{options[:filter_title]}', extensions : '#{options[:filter_extentions]}'}
105
+ ],
106
+ file_data_name: 'file'
107
+ });
107
108
 
108
- // instantiates the uploader
109
- uploader.init();
109
+ // instantiates the uploader
110
+ uploader.init();
110
111
 
111
- // shows the progress bar and kicks off uploading
112
- uploader.bind('FilesAdded', function(up, files) {
113
- $('#progress_bar .ui-progress').css('width', '5%');
114
- $('span.ui-label').show();
112
+ // shows the progress bar and kicks off uploading
113
+ uploader.bind('FilesAdded', function(up, files) {
114
+ $('#progress_bar .ui-progress').css('width', '5%');
115
+ $('span.ui-label').show();
115
116
 
116
- // start the uploader after the progress bar shows
117
- $('#progress_bar').show(function () {
118
- uploader.start();
119
- });
120
- });
117
+ // start the uploader after the progress bar shows
118
+ $('#progress_bar').show(function () {
119
+ uploader.start();
120
+ });
121
+ });
121
122
 
122
- // binds progress to progress bar
123
- uploader.bind('UploadProgress', function(up, file) {
124
- if(file.percent < 100){
125
- $('#progress_bar .ui-progress').css('width', file.percent+'%');
126
- }
127
- else {
128
- $('#progress_bar .ui-progress').css('width', '100%');
129
- $('span.ui-label').text('Complete');
130
- }
131
- });
123
+ // binds progress to progress bar
124
+ uploader.bind('UploadProgress', function(up, file) {
125
+ if(file.percent < 100){
126
+ $('#progress_bar .ui-progress').css('width', file.percent+'%');
127
+ }
128
+ else {
129
+ $('#progress_bar .ui-progress').css('width', '100%');
130
+ $('span.ui-label').text('Complete');
131
+ }
132
+ });
132
133
 
133
- // shows error object in the browser console (for now)
134
- uploader.bind('Error', function(up, error) {
135
- // unfortunately PLUpload gives some extremely vague
136
- // Flash error messages so you have to use WireShark
137
- // for debugging them (read the README)
134
+ // shows error object in the browser console (for now)
135
+ uploader.bind('Error', function(up, error) {
136
+ // unfortunately PLUpload gives some extremely vague
137
+ // Flash error messages so you have to use WireShark
138
+ // for debugging them (read the README)
138
139
 
139
- alert('There was an error. Check the browser console log for more info');
140
- console.log('Expand the error object below to see the error. Use WireShark to debug.');
140
+ alert('There was an error. Check the browser console log for more info');
141
+ console.log('Expand the error object below to see the error. Use WireShark to debug.');
141
142
 
142
- console.log(error);
143
- });
143
+ console.log(error);
144
+ });
144
145
 
145
- });")
146
+ });")
146
147
 
148
+ end
147
149
  end
148
150
  end
@@ -1,3 +1,3 @@
1
1
  module AppliciousUtils
2
- VERSION = "0.1.30"
2
+ VERSION = "0.1.31"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: applicious_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.30
4
+ version: 0.1.31
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: