effective_assets 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +228 -0
- data/Rakefile +23 -0
- data/app/assets/images/effective_assets/icon_close.png +0 -0
- 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/images/effective_assets/spinner.gif +0 -0
- data/app/assets/images/mime-types/excel.jpg +0 -0
- data/app/assets/images/mime-types/file.png +0 -0
- data/app/assets/images/mime-types/mp3.png +0 -0
- data/app/assets/images/mime-types/pdf.png +0 -0
- data/app/assets/images/mime-types/video.png +0 -0
- data/app/assets/images/mime-types/word.jpg +0 -0
- data/app/assets/images/mime-types/zip.png +0 -0
- data/app/assets/javascripts/effective_assets.js +1 -0
- data/app/assets/javascripts/effective_assets/asset_box_input.js.coffee +71 -0
- data/app/assets/javascripts/effective_assets/asset_box_uploader.js +122 -0
- data/app/assets/javascripts/effective_assets/asset_box_uploader_customization.js +166 -0
- data/app/assets/javascripts/effective_assets/jquery_ui_sortable.js +2106 -0
- data/app/assets/stylesheets/effective_assets.css.scss +1 -0
- data/app/assets/stylesheets/effective_assets/_asset_box_input.scss +206 -0
- data/app/controllers/effective/attachments_controller.rb +14 -0
- data/app/controllers/effective/s3_uploads_controller.rb +98 -0
- data/app/helpers/effective_assets_helper.rb +55 -0
- data/app/models/concerns/acts_as_asset_box.rb +97 -0
- data/app/models/effective/asset.rb +224 -0
- data/app/models/effective/attachment.rb +25 -0
- data/app/models/effective/delayed_job.rb +99 -0
- data/app/models/inputs/asset_box_input.rb +87 -0
- data/app/models/validators/asset_box_length_validator.rb +11 -0
- data/app/models/validators/asset_box_presence_validator.rb +6 -0
- data/app/uploaders/asset_uploader.rb +26 -0
- data/app/uploaders/effective_assets_uploader.rb +63 -0
- data/app/views/active_admin/effective_assets/_edit.html.haml +35 -0
- data/app/views/active_admin/effective_assets/_form.html.haml +4 -0
- data/app/views/active_admin/effective_assets/_new.html.haml +3 -0
- data/app/views/asset_box_input/_attachment_fields.html.haml +14 -0
- data/app/views/asset_box_input/_uploader.html.haml +119 -0
- data/app/views/assets/_video.html.erb +4 -0
- data/config/routes.rb +6 -0
- data/db/migrate/01_create_effective_assets.rb.erb +42 -0
- data/lib/effective_assets.rb +31 -0
- data/lib/effective_assets/engine.rb +38 -0
- data/lib/effective_assets/version.rb +3 -0
- data/lib/generators/effective_assets/install_generator.rb +41 -0
- data/lib/generators/templates/README +1 -0
- data/lib/generators/templates/asset_uploader.rb +25 -0
- data/lib/generators/templates/effective_assets.rb +19 -0
- data/lib/tasks/effective_assets_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +65 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +71 -0
- data/spec/dummy/log/test.log +33 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/spec_link +3 -0
- data/spec/models/asset_spec.rb +46 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/factories.rb +28 -0
- metadata +431 -0
@@ -0,0 +1,6 @@
|
|
1
|
+
class AssetBoxPresenceValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
num_in_box = (record.attachments || []).select { |attachment| attachment.box == attribute.to_s.pluralize && attachment.marked_for_destruction? == false }.size
|
4
|
+
record.errors[attribute] << "can't be blank" if num_in_box == 0
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class AssetUploader < EffectiveAssetsUploader
|
2
|
+
# resize_to_fit
|
3
|
+
# Resize the image to fit within the specified dimensions while retaining the
|
4
|
+
# original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension
|
5
|
+
# but will not be larger than the specified values.
|
6
|
+
#
|
7
|
+
# Probably best for taking a big image and making it smaller.
|
8
|
+
# Keeps the aspect ratio
|
9
|
+
# An uploaded image that is smaller will not be made bigger.
|
10
|
+
|
11
|
+
# resize_to_fill
|
12
|
+
# Resize the image to fit within the specified dimensions while retaining the
|
13
|
+
# aspect ratio of the original image. If necessary, crop the image in the larger dimension.
|
14
|
+
|
15
|
+
# resize_to_limit
|
16
|
+
# http://stackoverflow.com/questions/8570181/carrierwave-resizing-images-to-fixed-width
|
17
|
+
# Keep in mind, resize_to_fit will scale up images if they are smaller than 100px.
|
18
|
+
# If you don't want it to do that, then replace that with resize_to_limit.
|
19
|
+
|
20
|
+
version :thumb, :if => :image? do
|
21
|
+
process :resize_to_fit => [70, 70]
|
22
|
+
process :record_info => :thumb
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class EffectiveAssetsUploader < CarrierWave::Uploader::Base
|
2
|
+
include CarrierWave::MiniMagick
|
3
|
+
storage :fog
|
4
|
+
|
5
|
+
def store_dir
|
6
|
+
"#{EffectiveAssets.aws_final_path.chomp('/')}/#{model.id}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Returns a Hash as per the versions above
|
10
|
+
# {:thumb=>{:width=>256, :height=>70}, :full_page=>{:width=>940, :height=>nil}}
|
11
|
+
def versions_info
|
12
|
+
@versions_info ||= calculate_versions_info
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
# record_info
|
18
|
+
# Messy hash merging to a serialized field.
|
19
|
+
# It has the effect of setting asset.versions_info to a Hash, such as
|
20
|
+
#---
|
21
|
+
# :medium:
|
22
|
+
# :data_size: 22259
|
23
|
+
# :height: 400
|
24
|
+
# :width: 400
|
25
|
+
# :thumb:
|
26
|
+
# :data_size: 3105
|
27
|
+
# :height: 128
|
28
|
+
# :width: 128
|
29
|
+
|
30
|
+
def record_info(version)
|
31
|
+
if model and model.respond_to?(:versions_info) and @file.present?
|
32
|
+
info = {}
|
33
|
+
info[:data_size] = @file.size
|
34
|
+
|
35
|
+
img = MiniMagick::Image.open(@file.file)
|
36
|
+
info[:width] = img[:width]
|
37
|
+
info[:height] = img[:height]
|
38
|
+
|
39
|
+
model.versions_info.merge!({version.to_sym => info})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def image?(new_file)
|
44
|
+
new_file.present? and new_file.content_type.to_s.include?('image') and !(new_file.content_type.include?('icon'))
|
45
|
+
end
|
46
|
+
|
47
|
+
def calculate_versions_info
|
48
|
+
retval = {}
|
49
|
+
|
50
|
+
self.class.versions.each do |k, v|
|
51
|
+
v[:uploader].processors.each do |processor|
|
52
|
+
dimensions = processor[1]
|
53
|
+
|
54
|
+
if processor[0].to_s.include?('resize') and dimensions.kind_of?(Array) and dimensions.length == 2
|
55
|
+
retval[k] = {:width => dimensions.first, :height => dimensions.last}
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
retval
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
= semantic_form_for [:admin, asset] do |f|
|
2
|
+
= f.inputs "Asset" do
|
3
|
+
%li
|
4
|
+
%label.label Asset
|
5
|
+
%p.inline-hints= effective_asset_image_tag(asset, :thumb)
|
6
|
+
%li
|
7
|
+
%label.label Uploaded by
|
8
|
+
%p
|
9
|
+
- if defined? User
|
10
|
+
= asset.try(:user)
|
11
|
+
= f.input :title, :hint => "Give this asset a title"
|
12
|
+
= f.input :description, :as => :string, :hint => "Give this asset a description"
|
13
|
+
= f.input :tags, :hint => "Used for searching and filtering. Separate multiple tags with a comma (i.e. blue,car,ford)"
|
14
|
+
= f.input :content_type, :hint => "The computer detected type of file. Be careful when changing this value as you may break things."
|
15
|
+
%li
|
16
|
+
%label.label Files
|
17
|
+
%p.inline-hints{:style => 'font-style: normal'}
|
18
|
+
- if asset.image?
|
19
|
+
= link_to "Original", assets_image_url(asset), :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_image_tag(asset)}
|
20
|
+
= "#{asset.width || '?'}x#{asset.height || '?'}px #{number_to_human_size(asset.data_size, :precision => 3)}"
|
21
|
+
- asset.versions_info.each do |version, attributes|
|
22
|
+
%br
|
23
|
+
= link_to "#{version.to_s.gsub('_',' ').titleize}", assets_image_url(asset, version), :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => assets_image_tag(asset, version) }
|
24
|
+
= "#{attributes[:width]}x#{attributes[:height]}px #{number_to_human_size(attributes[:data_size], :precision => 3)}"
|
25
|
+
- elsif asset.icon?
|
26
|
+
= link_to asset.file_name, asset.image, :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_image_tag(asset)}
|
27
|
+
= "#{number_to_human_size(asset.data_size, :precision => 3)}"
|
28
|
+
- elsif asset.video?
|
29
|
+
= link_to asset.file_name, asset.url, :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_video_tag(asset)}
|
30
|
+
= "#{number_to_human_size(asset.data_size, :precision => 3)}"
|
31
|
+
- else
|
32
|
+
= link_to asset.file_name, asset.url, :class => 'asset-insertable', :data => {'asset-id' => asset.id, 'asset' => effective_asset_link_to(asset)}
|
33
|
+
= "#{number_to_human_size(asset.data_size, :precision => 3)}"
|
34
|
+
|
35
|
+
= f.actions :submit, :cancel
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- attachable_type ||= attachment.attachable_type.titleize.gsub(" ", "_").gsub('/', '_').downcase
|
2
|
+
- uid = (attachment.persisted? ? attachment.id : Time.now.to_i)
|
3
|
+
- hidden ||= false
|
4
|
+
|
5
|
+
.asset-box-attachment{:style => "#{(attachment.marked_for_destruction? || hidden) ? 'display: none;' : ''}"}
|
6
|
+
- if attachment.persisted?
|
7
|
+
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][id]", attachment.id)
|
8
|
+
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][asset_id]", attachment.asset_id)
|
9
|
+
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][box]", attachment.box)
|
10
|
+
= hidden_field_tag("#{attachable_type}[attachments_attributes][#{uid}][_destroy]", attachment.marked_for_destruction? ? 1 : nil, :class => 'asset-box-remove')
|
11
|
+
|
12
|
+
%span.thumbnail= effective_asset_image_tag(attachment.asset, :thumb)
|
13
|
+
%p.title= attachment.asset.title
|
14
|
+
%a.asset-box-remove{:href => '#'} Delete
|
@@ -0,0 +1,119 @@
|
|
1
|
+
.asset_box_uploader{:style => "#{uploader_visible ? '' : 'display: none;'}"}
|
2
|
+
.file_lists
|
3
|
+
%ul.file_done_list.file_list
|
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
|
12
|
+
|
13
|
+
%script{:type => 'text/javascript'}
|
14
|
+
:erb
|
15
|
+
|
16
|
+
$("div.asset_box_input[data-swf='s3_swf_<%= uid %>'][data-mode='multiple']").find('div.attachments').first().sortable();
|
17
|
+
preload_spinner = new Image();
|
18
|
+
preload_spinner.src = '/assets/effective_assets/spinner.gif';
|
19
|
+
|
20
|
+
var s3_swf_<%= uid %>_object = s3_swf_init('s3_swf_<%= uid %>', {
|
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();
|
84
|
+
|
85
|
+
s3_addFileToDoneList('s3_swf_<%= uid %>', upload_options.FileName, upload_options.FileSize);
|
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}"}
|
115
|
+
|
116
|
+
%div
|
117
|
+
%input.StartButton{:onclick => "s3_swf_#{uid}_object.startUploading(); return false;", :type => "submit", :value => "Start Uploading"}
|
118
|
+
%input.ResetButton{:onclick => "s3_swf_#{uid}_object.clearQueue(); return false;", :type => "submit", :value => "Clear Queue"}
|
119
|
+
%input.StopButton{:onclick => "s3_swf_#{uid}_object.stopUploading(); return false;", :type => "submit", :value => "Stop Uploading"}
|
data/config/routes.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
class CreateEffectiveAssets < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table <%= @assets_table_name %> do |t|
|
4
|
+
t.string :title
|
5
|
+
t.text :description
|
6
|
+
t.string :tags
|
7
|
+
|
8
|
+
t.integer :user_id
|
9
|
+
|
10
|
+
t.string :content_type
|
11
|
+
t.string :upload_file
|
12
|
+
t.string :data
|
13
|
+
t.boolean :processed, :default => false
|
14
|
+
|
15
|
+
t.integer :data_size
|
16
|
+
t.integer :height
|
17
|
+
t.integer :width
|
18
|
+
t.text :versions_info
|
19
|
+
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index <%= @assets_table_name %>, :content_type
|
24
|
+
|
25
|
+
create_table <%= @attachments_table_name %> do |t|
|
26
|
+
t.integer :asset_id
|
27
|
+
t.string :attachable_type
|
28
|
+
t.integer :attachable_id
|
29
|
+
t.integer :position
|
30
|
+
t.string :box
|
31
|
+
end
|
32
|
+
|
33
|
+
add_index <%= @attachments_table_name %>, :asset_id
|
34
|
+
add_index <%= @attachments_table_name %>, [:attachable_type, :attachable_id]
|
35
|
+
add_index <%= @attachments_table_name %>, :attachable_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.down
|
39
|
+
drop_table <%= @assets_table_name %>
|
40
|
+
drop_table <%= @attachments_table_name %>
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "effective_assets/engine"
|
2
|
+
require 'carrierwave'
|
3
|
+
require 'delayed_job_active_record'
|
4
|
+
require 'migrant' # Required for rspec to run properly
|
5
|
+
|
6
|
+
module EffectiveAssets
|
7
|
+
# The following are all valid config keys
|
8
|
+
mattr_accessor :assets_table_name
|
9
|
+
mattr_accessor :attachments_table_name
|
10
|
+
|
11
|
+
mattr_accessor :uploader
|
12
|
+
|
13
|
+
mattr_accessor :aws_bucket
|
14
|
+
mattr_accessor :aws_access_key_id
|
15
|
+
mattr_accessor :aws_secret_access_key
|
16
|
+
|
17
|
+
mattr_accessor :aws_upload_path # This directory is where the flash s3 uploader first places files
|
18
|
+
mattr_accessor :aws_final_path # We then authenticate and use Fog to copy the object from upload_path to final_path
|
19
|
+
mattr_accessor :aws_acl
|
20
|
+
|
21
|
+
mattr_accessor :authorization_method
|
22
|
+
|
23
|
+
def self.setup
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.authorized?(controller, action, resource)
|
28
|
+
raise ActiveResource::UnauthorizedAccess.new('') unless (controller || self).instance_exec(controller, action, resource, &EffectiveAssets.authorization_method)
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module EffectiveAssets
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
engine_name 'effective_assets'
|
4
|
+
|
5
|
+
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
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"]
|
9
|
+
|
10
|
+
# Include Helpers to base application
|
11
|
+
initializer 'effective_assets.action_controller' do |app|
|
12
|
+
ActiveSupport.on_load :action_controller do
|
13
|
+
helper EffectiveAssetsHelper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Include acts_as_addressable concern and allow any ActiveRecord object to call it
|
18
|
+
initializer 'effective_assets.active_record' do |app|
|
19
|
+
ActiveSupport.on_load :active_record do
|
20
|
+
ActiveRecord::Base.extend(ActsAsAssetBox::ActiveRecord)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Set up our default configuration options.
|
25
|
+
initializer "effective_assets.defaults", :before => :load_config_initializers do |app|
|
26
|
+
eval File.read("#{config.root}/lib/generators/templates/effective_assets.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
# ActiveAdmin (optional)
|
30
|
+
# This prepends the load path so someone can override the assets.rb if they want.
|
31
|
+
initializer 'effective_assets.active_admin' do
|
32
|
+
if defined?(ActiveAdmin)
|
33
|
+
ActiveAdmin.application.load_paths.unshift Dir["#{config.root}/active_admin"]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module EffectiveAssets
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
desc "Creates an EffectiveAssets initializer in your application."
|
7
|
+
|
8
|
+
source_root File.expand_path("../../templates", __FILE__)
|
9
|
+
|
10
|
+
def self.next_migration_number(dirname)
|
11
|
+
if not ActiveRecord::Base.timestamped_migrations
|
12
|
+
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
13
|
+
else
|
14
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_initializer
|
19
|
+
template "effective_assets.rb", "config/initializers/effective_assets.rb"
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_uploader
|
23
|
+
template "asset_uploader.rb", "app/uploaders/asset_uploader.rb"
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_migration_file
|
27
|
+
@assets_table_name = ':' + EffectiveAssets.assets_table_name.to_s
|
28
|
+
@attachments_table_name = ':' + EffectiveAssets.attachments_table_name.to_s
|
29
|
+
migration_template '../../../db/migrate/01_create_effective_assets.rb.erb', 'db/migrate/create_effective_assets.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
def install_delayed_jobs
|
33
|
+
run "rails generate delayed_job:active_record"
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_readme
|
37
|
+
readme "README" if behavior == :invoke
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|