effective_assets 0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +1 -1
- data/README.md +341 -72
- data/app/assets/javascripts/effective/snippets/effective_asset.js.coffee +53 -0
- data/app/assets/javascripts/effective_assets.js +4 -0
- data/app/assets/javascripts/effective_assets/asset_box.js.coffee +36 -0
- data/app/assets/javascripts/effective_assets/asset_box_dialog.js.coffee +49 -0
- data/app/assets/javascripts/effective_assets/asset_box_drag_and_drop.js.coffee +2 -0
- data/app/assets/javascripts/effective_assets/asset_box_filtering.js.coffee +16 -0
- data/app/assets/javascripts/effective_assets/asset_box_sorting.js.coffee +8 -0
- data/app/assets/javascripts/effective_assets/jquery_ui_sortable.js +813 -585
- data/app/assets/javascripts/effective_assets/s3_uploader.js.coffee +268 -0
- data/app/assets/javascripts/effective_assets_iframe.js.coffee +28 -0
- data/app/assets/stylesheets/active_admin/effective_assets.css.scss +57 -0
- data/app/assets/stylesheets/effective_assets/_asset_box_input.scss +54 -175
- data/app/assets/stylesheets/effective_assets/_iframe_bootstrap.scss +1714 -0
- data/app/assets/stylesheets/effective_assets/_input_bootstrap.scss +508 -0
- data/app/assets/stylesheets/effective_assets_iframe.css.scss +23 -0
- data/app/controllers/effective/assets_controller.rb +41 -0
- data/app/controllers/effective/s3_uploads_controller.rb +58 -74
- data/app/helpers/effective_assets_helper.rb +30 -14
- data/app/helpers/effective_assets_s3_helper.rb +69 -0
- data/app/models/concerns/acts_as_asset_box.rb +75 -11
- data/app/models/effective/access_denied.rb +17 -0
- data/app/models/effective/asset.rb +130 -93
- data/app/models/effective/attachment.rb +2 -7
- data/app/models/effective/delayed_job.rb +33 -78
- data/app/models/effective/snippets/effective_asset.rb +19 -0
- data/app/models/effective/user_uploads.rb +19 -0
- data/app/models/inputs/asset_box.rb +154 -0
- data/app/models/inputs/asset_box_form_input.rb +7 -0
- data/app/models/inputs/asset_box_formtastic_input.rb +9 -0
- data/app/models/inputs/asset_box_input.rb +13 -82
- data/app/models/inputs/asset_box_simple_form_input.rb +7 -0
- data/app/uploaders/effective_assets_uploader.rb +14 -2
- data/app/uploaders/{asset_uploader.rb → test_asset_uploader.rb} +1 -1
- data/app/views/active_admin/effective_assets/_edit.html.haml +3 -3
- data/app/views/active_admin/effective_assets/_new.html.haml +2 -1
- data/app/views/asset_box_input/_attachment_as_list.html.haml +17 -0
- data/app/views/asset_box_input/_attachment_as_table.html.haml +32 -0
- data/app/views/asset_box_input/_attachment_as_thumbnail.html.haml +20 -0
- data/app/views/asset_box_input/_dialog.html.haml +18 -0
- data/app/views/asset_box_input/_progress_bar_template.html.haml +8 -0
- data/app/views/asset_box_input/_uploader.html.haml +21 -115
- data/app/views/effective/assets/iframe.html.haml +17 -0
- data/app/views/effective/snippets/_effective_asset.html.haml +8 -0
- data/config/routes.rb +8 -2
- data/db/migrate/01_create_effective_assets.rb.erb +3 -0
- data/lib/effective_assets.rb +34 -3
- data/lib/effective_assets/engine.rb +11 -8
- data/lib/effective_assets/version.rb +1 -1
- data/lib/generators/templates/asset_uploader.rb +35 -0
- data/lib/generators/templates/effective_assets.rb +31 -4
- data/lib/tasks/effective_assets_tasks.rake +115 -4
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/effective_assets.rb +18 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +52 -0
- data/spec/internal/log/test.log +793 -0
- data/spec/{dummy → internal}/public/favicon.ico +0 -0
- data/spec/internal/public/sprites.png +0 -0
- data/spec/models/asset_spec.rb +119 -35
- data/spec/spec_helper.rb +9 -3
- metadata +95 -234
- data/app/assets/images/effective_assets/s3_down_button.gif +0 -0
- data/app/assets/images/effective_assets/s3_over_button.gif +0 -0
- data/app/assets/images/effective_assets/s3_up_button.gif +0 -0
- data/app/assets/images/effective_assets/s3_upload.swf +0 -0
- data/app/assets/javascripts/effective_assets/asset_box_input.js.coffee +0 -71
- data/app/assets/javascripts/effective_assets/asset_box_uploader.js +0 -122
- data/app/assets/javascripts/effective_assets/asset_box_uploader_customization.js +0 -166
- data/app/controllers/effective/attachments_controller.rb +0 -14
- data/app/views/asset_box_input/_attachment_fields.html.haml +0 -14
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -65
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -58
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +0 -16
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -71
- data/spec/dummy/log/test.log +0 -33
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/script/rails +0 -6
- data/spec/dummy/spec_link +0 -3
@@ -0,0 +1,20 @@
|
|
1
|
+
- uid = (attachment.persisted? ? attachment.id : Time.now.to_f.to_s.split('.')[1] + Random.rand(10000).to_s)
|
2
|
+
- hidden ||= false
|
3
|
+
|
4
|
+
.col-sm-3.attachment
|
5
|
+
.thumbnail{:style => "#{(attachment.marked_for_destruction? || hidden) ? 'display: none;' : ''}", :title => effective_asset_title(attachment.asset)}
|
6
|
+
= effective_asset_image_tag(attachment.asset)
|
7
|
+
|
8
|
+
.attachment-title.caption
|
9
|
+
= link_to attachment.asset.title, attachment.asset.url, :target => '_blank'
|
10
|
+
|
11
|
+
- if attachment_actions.include?('remove')
|
12
|
+
%a.attachment-remove{:href => '#'}
|
13
|
+
%img{:src => asset_path('effective_assets/icon_close.png'), :alt => 'Remove'}
|
14
|
+
|
15
|
+
- if attachment.persisted?
|
16
|
+
= hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][id]", attachment.id)
|
17
|
+
= hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][asset_id]", attachment.asset_id)
|
18
|
+
= hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][box]", attachment.box)
|
19
|
+
= hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][_destroy]", attachment.marked_for_destruction? ? 1 : nil, :class => 'asset-box-remove')
|
20
|
+
= hidden_field_tag(attachable_object_name + "[attachments_attributes][#{uid}][position]", 1)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
%button.asset-box-dialog{:href => '#', 'data-dialog-url' => dialog_url} Attach...
|
2
|
+
|
3
|
+
.asset-box-modal.modal.fade
|
4
|
+
.modal-dialog.modal-lg
|
5
|
+
.modal-content
|
6
|
+
.modal-header
|
7
|
+
%button{:type => 'button', :class => 'close', 'data-dismiss' => 'modal'}
|
8
|
+
%span{'aria-hidden' => true} ×
|
9
|
+
%span.sr-only Close
|
10
|
+
%h4.modal-title Attach / Upload Asset
|
11
|
+
.modal-body
|
12
|
+
%iframe#effective_assets_iframe{:src => dialog_url, :width => '100%', :height => '100%', :marginWidth => 0, :marginHeight => 0, :frameBorder => 0, :scrolling => :auto, :title => 'Attach / Upload Asset'}
|
13
|
+
|
14
|
+
.modal-footer
|
15
|
+
%button{:type => 'button', :class => 'btn btn-default', 'data-dismiss' => 'modal'} Close
|
16
|
+
|
17
|
+
|
18
|
+
|
@@ -1,119 +1,25 @@
|
|
1
|
-
.
|
2
|
-
|
3
|
-
|
4
|
-
%ul.file_todo_list.file_list
|
5
|
-
.queue_size
|
6
|
-
%span.numerator
|
7
|
-
%span.denominator
|
8
|
-
.overall
|
9
|
-
%span.progress
|
10
|
-
%span.amount
|
11
|
-
%span.status
|
1
|
+
.uploads
|
2
|
+
.asset-box-uploader{:id => "s3_#{uid}"}
|
3
|
+
= s3_uploader_fields(:aws_acl => aws_acl)
|
12
4
|
|
13
|
-
|
14
|
-
:
|
15
|
-
|
16
|
-
|
17
|
-
preload_spinner = new Image();
|
18
|
-
preload_spinner.src = '/assets/effective_assets/spinner.gif';
|
5
|
+
- if limit > 1
|
6
|
+
%input{:type => 'file', :name => 'file', :multiple => 'multiple', :disabled => disabled}
|
7
|
+
- else
|
8
|
+
%input{:type => 'file', :name => 'file', :disabled => disabled}
|
19
9
|
|
20
|
-
|
21
|
-
buttonWidth: 100,
|
22
|
-
buttonHeight: 30,
|
23
|
-
flashVersion: '9.0.0',
|
24
|
-
queueSizeLimit: <%= limit %>,
|
25
|
-
fileSizeLimit: 524288000,
|
26
|
-
fileTypes: '<%= file_types.present? ? file_types.map { |t| "*.#{t.to_s}"}.join(';') : '*.*' %>',
|
27
|
-
fileTypeDescs: 'Uploadable Files',
|
28
|
-
selectMultipleFiles: <%= limit > 1 ? 'true' : 'false' %>,
|
29
|
-
keyPrefix: '<%= "#{EffectiveAssets.aws_upload_path.chomp('/')}" + '/' %>',
|
30
|
-
signaturePath: '/s3_uploads.xml',
|
31
|
-
swfFilePath: '/assets/effective_assets/s3_upload.swf',
|
32
|
-
buttonUpPath: '/assets/effective_assets/s3_up_button.gif',
|
33
|
-
buttonOverPath: '/assets/effective_assets/s3_over_button.gif',
|
34
|
-
buttonDownPath: '/assets/effective_assets/s3_down_button.gif',
|
35
|
-
swfVarObj: 's3_swf_<%= uid %>_object',
|
36
|
-
onFileSizeLimitReached: function(file) {
|
37
|
-
alert('That file is too big');
|
38
|
-
},
|
39
|
-
onQueueSizeLimitReached: function(queue) {
|
40
|
-
alert('There are too many files in the queue');
|
41
|
-
},
|
42
|
-
onQueueEmpty: function(queue) {
|
43
|
-
alert('You gotta have at least one file in there');
|
44
|
-
},
|
45
|
-
onSignatureSecurityError: function(file,security_error_event) {
|
46
|
-
alert('There was an error');
|
47
|
-
},
|
48
|
-
onSignatureIOError: function(file,io_error_event) {
|
49
|
-
alert('There was an error');
|
50
|
-
},
|
51
|
-
onSignatureXMLError: function(file,error_message) {
|
52
|
-
alert('There was an error');
|
53
|
-
},
|
54
|
-
onUploadError: function(upload_options,error) {
|
55
|
-
alert('There was an error');
|
56
|
-
},
|
57
|
-
onUploadIOError: function(upload_options,io_error_event) {
|
58
|
-
alert('There was an error');
|
59
|
-
},
|
60
|
-
onUploadSecurityError: function(upload_options,security_error_event) {
|
61
|
-
alert('There was an error');
|
62
|
-
},
|
63
|
-
onQueueClear: function(queue) {
|
64
|
-
s3_queueClearHandler('s3_swf_<%= uid %>', queue);
|
65
|
-
},
|
66
|
-
onUploadingFinish: function() {
|
67
|
-
s3_uploadingFinishHandler('s3_swf_<%= uid %>');
|
68
|
-
},
|
69
|
-
onUploadingStart: function() {
|
70
|
-
s3_uploadingStartHandler('s3_swf_<%= uid %>');
|
71
|
-
},
|
72
|
-
onQueueChange: function(queue) {
|
73
|
-
s3_queueChangeHandler('s3_swf_<%= uid %>', queue);
|
74
|
-
},
|
75
|
-
onUploadProgress: function(upload_options,progress_event) {
|
76
|
-
s3_progressHandler('s3_swf_<%= uid %>', progress_event);
|
77
|
-
},
|
78
|
-
onUploadComplete: function(upload_options,event) {
|
79
|
-
var obj = $("div.asset_box_input[data-swf='s3_swf_<%= uid %>']").find('div.asset_box_uploader').first();
|
80
|
-
var one_file = obj.find('.file_todo_list').find("li.file_to_upload").first()
|
81
|
-
var title = one_file.find('input.title').val();
|
82
|
-
var description = one_file.find('input.description').val();
|
83
|
-
var tags = one_file.find('input.tags').val();
|
10
|
+
= render :partial => progress_bar_partial
|
84
11
|
|
85
|
-
|
86
|
-
|
87
|
-
$.ajax({
|
88
|
-
url: '<%= s3_uploads_path %>',
|
89
|
-
beforeSend: function(jqXHR, settings) {
|
90
|
-
s3_showAttachmentLoading('s3_swf_<%= uid %>', title);
|
91
|
-
},
|
92
|
-
complete: function(jqXHR, textStatus) {
|
93
|
-
s3_loadAttachmentHtml('s3_swf_<%= uid %>', jqXHR.responseText);
|
94
|
-
},
|
95
|
-
global: false,
|
96
|
-
type: 'POST',
|
97
|
-
dataType: 'script',
|
98
|
-
data: {
|
99
|
-
'authenticity_token' : '<%= form_authenticity_token %>',
|
100
|
-
'file_name' : upload_options.FileName,
|
101
|
-
'file_path' : upload_options.key,
|
102
|
-
'file_size' : upload_options.FileSize,
|
103
|
-
'box' : '<%= box %>',
|
104
|
-
'attachable_type' : '<%= attachable_type %>',
|
105
|
-
'attachable_id' : '<%= attachable_id %>',
|
106
|
-
'content_type' : upload_options.ContentType,
|
107
|
-
'title' : title,
|
108
|
-
'description' : description,
|
109
|
-
'tags' : tags
|
110
|
-
}
|
111
|
-
})
|
112
|
-
}
|
113
|
-
});
|
114
|
-
%div{:id => "s3_swf_#{uid}"}
|
12
|
+
%script{:type => 'text/javascript'}
|
13
|
+
:erb
|
115
14
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
15
|
+
$("#s3_<%= uid %>").S3Uploader({
|
16
|
+
url: '<%= s3_uploader_url %>',
|
17
|
+
progress_bar_target: $("#s3_<%= uid %>").siblings('.uploads').first(),
|
18
|
+
progress_bar_template: $("#s3_<%= uid %>").children("script[type='text/x-tmpl']").first(),
|
19
|
+
remove_completed_progress_bar: true,
|
20
|
+
allow_multiple_files: <%= limit > 1 %>,
|
21
|
+
file_types: '<%= [file_types].flatten.join('|').to_s %>',
|
22
|
+
create_asset_url: '<%= effective_assets.s3_uploads_url %>',
|
23
|
+
update_asset_url: '<%= effective_assets.s3_uploads_url %>/:id',
|
24
|
+
dropZone: $("#s3_<%= uid %>").parent()
|
25
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title Insert / Upload
|
5
|
+
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}
|
6
|
+
%meta{:charset => 'utf-8'}
|
7
|
+
%meta{:name => 'viewport', :content => 'width=device-width, initial-scale=1, maximum-scale=1'}
|
8
|
+
|
9
|
+
= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js'
|
10
|
+
= javascript_include_tag 'effective_assets'
|
11
|
+
= javascript_include_tag 'effective_assets_iframe'
|
12
|
+
= stylesheet_link_tag 'effective_assets_iframe'
|
13
|
+
= csrf_meta_tags
|
14
|
+
|
15
|
+
%body
|
16
|
+
= simple_form_for @user_uploads, :url => '/' do |f|
|
17
|
+
= f.input :uploads, :as => :asset_box, :label => false, :uploader => true, :attachment_style => :table, :table_filter_bar => true, :attachment_actions => [:insert, :delete], :file_types => (@file_types || :any), :aws_acl => (@aws_acl || 'public-read')
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
+
mount EffectiveAssets::Engine => '/', :as => 'effective_assets'
|
3
|
+
end
|
4
|
+
|
5
|
+
EffectiveAssets::Engine.routes.draw do
|
2
6
|
scope :module => 'effective' do
|
3
|
-
resources :
|
4
|
-
|
7
|
+
resources :s3_uploads, :only => [:create, :update]
|
8
|
+
|
9
|
+
match '/effective/assets', :to => 'assets#index', :via => [:get], :as => 'effective_assets'
|
10
|
+
match '/effective/assets/:id', :to => 'assets#destroy', :via => [:delete], :as => 'effective_asset'
|
5
11
|
end
|
6
12
|
end
|
@@ -4,6 +4,7 @@ class CreateEffectiveAssets < ActiveRecord::Migration
|
|
4
4
|
t.string :title
|
5
5
|
t.text :description
|
6
6
|
t.string :tags
|
7
|
+
t.text :extra
|
7
8
|
|
8
9
|
t.integer :user_id
|
9
10
|
|
@@ -11,6 +12,7 @@ class CreateEffectiveAssets < ActiveRecord::Migration
|
|
11
12
|
t.string :upload_file
|
12
13
|
t.string :data
|
13
14
|
t.boolean :processed, :default => false
|
15
|
+
t.string :aws_acl, :default => 'public-read'
|
14
16
|
|
15
17
|
t.integer :data_size
|
16
18
|
t.integer :height
|
@@ -21,6 +23,7 @@ class CreateEffectiveAssets < ActiveRecord::Migration
|
|
21
23
|
end
|
22
24
|
|
23
25
|
add_index <%= @assets_table_name %>, :content_type
|
26
|
+
add_index <%= @assets_table_name %>, :user_id
|
24
27
|
|
25
28
|
create_table <%= @attachments_table_name %> do |t|
|
26
29
|
t.integer :asset_id
|
data/lib/effective_assets.rb
CHANGED
@@ -2,6 +2,7 @@ require "effective_assets/engine"
|
|
2
2
|
require 'carrierwave'
|
3
3
|
require 'delayed_job_active_record'
|
4
4
|
require 'migrant' # Required for rspec to run properly
|
5
|
+
require 'jquery-fileupload-rails'
|
5
6
|
|
6
7
|
module EffectiveAssets
|
7
8
|
# The following are all valid config keys
|
@@ -14,18 +15,48 @@ module EffectiveAssets
|
|
14
15
|
mattr_accessor :aws_access_key_id
|
15
16
|
mattr_accessor :aws_secret_access_key
|
16
17
|
|
17
|
-
mattr_accessor :
|
18
|
-
mattr_accessor :aws_final_path # We then authenticate and use Fog to copy the object from upload_path to final_path
|
18
|
+
mattr_accessor :aws_path # This directory is where we upload files to
|
19
19
|
mattr_accessor :aws_acl
|
20
20
|
|
21
21
|
mattr_accessor :authorization_method
|
22
22
|
|
23
|
+
mattr_accessor :use_active_admin
|
24
|
+
|
23
25
|
def self.setup
|
24
26
|
yield self
|
27
|
+
|
28
|
+
configure_carrierwave
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.permitted_params
|
32
|
+
{:attachments_attributes => [:id, :asset_id, :attachable_type, :attachable_id, :position, :box, :_destroy]}
|
25
33
|
end
|
26
34
|
|
27
35
|
def self.authorized?(controller, action, resource)
|
28
|
-
|
36
|
+
if authorization_method.respond_to?(:call) || authorization_method.kind_of?(Symbol)
|
37
|
+
raise Effective::AccessDenied.new() unless (controller || self).instance_exec(controller, action, resource, &authorization_method)
|
38
|
+
end
|
29
39
|
true
|
30
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.configure_carrierwave
|
45
|
+
if (@carrierwave_configured != true) && EffectiveAssets.uploader.present? && EffectiveAssets.aws_bucket.present?
|
46
|
+
CarrierWave.configure do |config|
|
47
|
+
config.fog_credentials = {
|
48
|
+
:provider => 'AWS',
|
49
|
+
:aws_access_key_id => EffectiveAssets.aws_access_key_id,
|
50
|
+
:aws_secret_access_key => EffectiveAssets.aws_secret_access_key
|
51
|
+
}
|
52
|
+
config.fog_directory = EffectiveAssets.aws_bucket
|
53
|
+
config.fog_public = EffectiveAssets.aws_acl.to_s.include?('public')
|
54
|
+
config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}
|
55
|
+
config.cache_dir = "#{Rails.root}/tmp/uploads" # For heroku
|
56
|
+
end
|
57
|
+
|
58
|
+
@carrierwave_configured = true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
31
62
|
end
|
@@ -2,15 +2,13 @@ module EffectiveAssets
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
engine_name 'effective_assets'
|
4
4
|
|
5
|
-
config.autoload_paths += Dir["#{config.root}/app/models
|
6
|
-
config.autoload_paths += Dir["#{config.root}/app/models/inputs"]
|
7
|
-
config.autoload_paths += Dir["#{config.root}/app/models/validators"]
|
8
|
-
config.autoload_paths += Dir["#{config.root}/app/models/uploaders"]
|
5
|
+
config.autoload_paths += Dir["#{config.root}/app/models/**/"]
|
9
6
|
|
10
7
|
# Include Helpers to base application
|
11
8
|
initializer 'effective_assets.action_controller' do |app|
|
12
9
|
ActiveSupport.on_load :action_controller do
|
13
10
|
helper EffectiveAssetsHelper
|
11
|
+
helper EffectiveAssetsS3Helper
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -21,15 +19,20 @@ module EffectiveAssets
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
initializer 'effective_assets.action_view' do |app|
|
23
|
+
ActiveSupport.on_load :action_view do
|
24
|
+
ActionView::Helpers::FormBuilder.send(:include, Inputs::AssetBoxFormInput)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
initializer "effective_assets.append_precompiled_assets" do |app|
|
29
|
+
Rails.application.config.assets.precompile += ['effective_assets.js', 'effective_assets_iframe.js', 'effective_assets_iframe.css']
|
27
30
|
end
|
28
31
|
|
29
32
|
# ActiveAdmin (optional)
|
30
33
|
# This prepends the load path so someone can override the assets.rb if they want.
|
31
34
|
initializer 'effective_assets.active_admin' do
|
32
|
-
if defined?(ActiveAdmin)
|
35
|
+
if defined?(ActiveAdmin) && EffectiveAssets.use_active_admin == true
|
33
36
|
ActiveAdmin.application.load_paths.unshift Dir["#{config.root}/active_admin"]
|
34
37
|
end
|
35
38
|
end
|
@@ -20,6 +20,41 @@ class AssetUploader < EffectiveAssetsUploader
|
|
20
20
|
version :thumb, :if => :image? do
|
21
21
|
process :resize_to_fit => [70, 70]
|
22
22
|
process :record_info => :thumb
|
23
|
+
# process :watermark! => [70, 70]
|
24
|
+
# process :grayscale!
|
25
|
+
# process :transparent! => ['#3F7F42', '12%']
|
23
26
|
end
|
24
27
|
|
28
|
+
# If you want to do a watermark, you can use something like this
|
29
|
+
# def watermark!(width, height)
|
30
|
+
# manipulate! do |image|
|
31
|
+
# logo = MiniMagick::Image.open("#{ Rails.root }/app/assets/images/watermark.png")
|
32
|
+
# logo.resize("#{ width }x#{ height }>")
|
33
|
+
# result = image.composite(logo) do |comp|
|
34
|
+
# comp.gravity "center"
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
|
39
|
+
# If you want to Grayscale images, you can use something like this
|
40
|
+
# def grayscale!
|
41
|
+
# manipulate! do |image|
|
42
|
+
# image.colorspace("Gray")
|
43
|
+
# image = yield(image) if block_given?
|
44
|
+
# image
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
|
48
|
+
# If you want to make a certain color in the image transparent (assumes gif or png), you can use something like this
|
49
|
+
# def transparent!(color, fuzz)
|
50
|
+
# manipulate! do |image|
|
51
|
+
# image.transparent(color) do |cmd|
|
52
|
+
# cmd.fuzz fuzz
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# image = yield(image) if block_given?
|
56
|
+
# image
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
|
25
60
|
end
|
@@ -4,16 +4,43 @@ EffectiveAssets.setup do |config|
|
|
4
4
|
config.assets_table_name = :assets
|
5
5
|
config.attachments_table_name = :attachments
|
6
6
|
|
7
|
-
config.uploader = AssetUploader
|
7
|
+
config.uploader = AssetUploader # Must extend from EffectiveAssetsUploader
|
8
|
+
|
9
|
+
# Authorization Method
|
10
|
+
#
|
11
|
+
# This method is called by all controller actions with the appropriate action and resource
|
12
|
+
# If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
|
13
|
+
#
|
14
|
+
# Use via Proc (and with CanCan):
|
15
|
+
# config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
|
16
|
+
#
|
17
|
+
# Use via custom method:
|
18
|
+
# config.authorization_method = :my_authorization_method
|
19
|
+
#
|
20
|
+
# And then in your application_controller.rb:
|
21
|
+
#
|
22
|
+
# def my_authorization_method(action, resource)
|
23
|
+
# current_user.is?(:admin)
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Or disable the check completely:
|
27
|
+
# config.authorization_method = false
|
28
|
+
config.authorization_method = Proc.new { |controller, action, resource| true } # All users can see every screen
|
29
|
+
|
8
30
|
|
9
31
|
# This is your S3 bucket information
|
10
32
|
config.aws_bucket = ''
|
11
33
|
config.aws_access_key_id = ''
|
12
34
|
config.aws_secret_access_key = ''
|
13
35
|
|
14
|
-
config.
|
15
|
-
|
36
|
+
config.aws_path = 'assets/'
|
37
|
+
|
38
|
+
# This is the default aws_acl all assets will be created with
|
39
|
+
# Unless you override the value by passing :aws_acl => '' to the asset_box_input, Asset.create_from_url, or Asset.create_from_string
|
40
|
+
# Valid settings are public-read, authenticated-read
|
16
41
|
config.aws_acl = 'public-read'
|
17
42
|
|
18
|
-
|
43
|
+
|
44
|
+
# Register Effective::Asset with ActiveAdmin if ActiveAdmin is present
|
45
|
+
config.use_active_admin = true
|
19
46
|
end
|