effective_assets 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/effective/assets_controller.rb +5 -5
- data/app/controllers/effective/s3_uploads_controller.rb +6 -1
- data/app/helpers/effective_assets_helper.rb +11 -8
- data/app/models/effective/asset.rb +21 -15
- data/app/models/effective/attachment.rb +7 -5
- data/app/models/effective/delayed_job.rb +0 -1
- data/app/models/effective/{user_uploads.rb → iframe_uploads.rb} +1 -1
- data/app/models/effective/snippets/effective_asset.rb +1 -1
- data/app/models/inputs/asset_box.rb +15 -24
- data/app/uploaders/effective_assets_uploader.rb +1 -1
- data/app/views/asset_box_input/_attachment_as_list.html.haml +4 -2
- data/app/views/asset_box_input/_attachment_as_table.html.haml +7 -5
- data/app/views/asset_box_input/_attachment_as_thumbnail.html.haml +4 -2
- data/app/views/{assets → effective/assets}/_video.html.erb +0 -0
- data/app/views/effective/assets/iframe.html.haml +1 -1
- data/app/views/effective/snippets/_effective_asset.html.haml +1 -1
- data/lib/effective_assets.rb +5 -2
- data/lib/effective_assets/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47cf237da48597a134011c3256f2631b731b2d6b
|
4
|
+
data.tar.gz: b4a479a03cff5dfda60b5a5566f3674bbd494361
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95bcb6b27a4e4623f05d0b4d40a6bc676ca6a5067da6bef4a24ea5b686b84db5b4a10fc93bb2e19c8aab08d7d90ab1bfca8a609e3b120dd8a8497d8ec9a8a364
|
7
|
+
data.tar.gz: ab67f6beab1aa7a87d375f66ace82566dd6e0dca4004e143e0ba27c1060bbf43861b2770aa9d1756ef380ea73302656ebf6efaff7f1e5be0e2c7f79c818bc769
|
@@ -4,22 +4,22 @@ module Effective
|
|
4
4
|
class AssetsController < ApplicationController
|
5
5
|
layout false
|
6
6
|
|
7
|
-
|
7
|
+
# iframe
|
8
|
+
def index # This is the IFRAME modal dialog that is read by CKEDITOR
|
8
9
|
EffectiveAssets.authorized?(self, :index, Effective::Asset.new(:user_id => current_user.try(:id)))
|
9
10
|
|
10
|
-
|
11
|
-
@
|
11
|
+
effective_iframe_uploads = Effective::Attachment.where(box: EffectiveAssets::IFRAME_UPLOADS).pluck(:asset_id)
|
12
|
+
@assets = Effective::Asset.where(id: effective_iframe_uploads)
|
12
13
|
|
13
14
|
if params[:only] == 'images'
|
14
15
|
@assets = @assets.images
|
15
16
|
@file_types = [:jpg, :gif, :png, :bmp, :ico]
|
16
|
-
@aws_acl = 'public-read' # The CKEditor Insert Image functionality needs a public-read image here
|
17
17
|
elsif params[:only] == 'nonimages'
|
18
18
|
@assets = @assets.nonimages
|
19
19
|
@file_types = [:pdf, :zip, :doc, :docx, :xls, :xlsx, :txt, :csv, :avi, :m4v, :m2v, :mov, :mp3, :mp4, :eml]
|
20
20
|
end
|
21
21
|
|
22
|
-
@user_uploads =
|
22
|
+
@user_uploads = IframeUploads.new(@assets)
|
23
23
|
|
24
24
|
render :file => 'effective/assets/iframe'
|
25
25
|
end
|
@@ -34,6 +34,11 @@ module Effective
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
# Kind of a hacky way of saving IFRAME uploads without joining them to anything
|
38
|
+
if params[:attachable_object_name] == EffectiveAssets::IFRAME_UPLOADS
|
39
|
+
Effective::Attachment.new(asset: @asset, box: EffectiveAssets::IFRAME_UPLOADS, position: 0).save!
|
40
|
+
end
|
41
|
+
|
37
42
|
# If the attachment information is present, then our input needs some attachment HTML
|
38
43
|
if params.key?(:attachable_object_name)
|
39
44
|
attachment = Effective::Attachment.new
|
@@ -44,7 +49,7 @@ module Effective
|
|
44
49
|
attachment.position = 0
|
45
50
|
attachable_object_name = params[:attachable_object_name].to_s
|
46
51
|
attachment_actions = params[:attachment_actions]
|
47
|
-
attachment_links = ![
|
52
|
+
attachment_links = !['0', 'f', 'false', 'off'].include?(params[:attachment_links].to_s.downcase)
|
48
53
|
|
49
54
|
attachment_partial =
|
50
55
|
case params[:attachment_style].to_s
|
@@ -13,24 +13,27 @@ module EffectiveAssetsHelper
|
|
13
13
|
opts = {}
|
14
14
|
end
|
15
15
|
|
16
|
+
public_url = options.delete(:public) || options.delete(:public_url)
|
17
|
+
|
16
18
|
opts = opts.merge({:alt => asset.title || asset.file_name}).merge(options)
|
17
19
|
|
18
|
-
content_tag(:img, nil, opts.merge(:src => _effective_asset_image_url(asset, version))).gsub('"', "'").html_safe
|
20
|
+
content_tag(:img, nil, opts.merge(:src => _effective_asset_image_url(asset, version, public_url))).gsub('"', "'").html_safe
|
19
21
|
end
|
20
22
|
|
21
23
|
def effective_asset_link_to(asset, version = nil, options = {})
|
22
24
|
options_title = options.delete(:title)
|
25
|
+
public_url = options.delete(:public) || options.delete(:public_url)
|
23
26
|
link_title = options_title || asset.title || asset.file_name || "Asset ##{asset.id}"
|
24
27
|
|
25
28
|
if asset.image?
|
26
|
-
link_to(link_title, _effective_asset_image_url(asset, version
|
29
|
+
link_to(link_title, _effective_asset_image_url(asset, version, public_url), options)
|
27
30
|
else
|
28
|
-
link_to(link_title, asset.url, options)
|
29
|
-
end
|
31
|
+
link_to(link_title, (public_url ? asset.public_url : asset.url), options)
|
32
|
+
end.gsub('"', "'").html_safe # we need all ' quotes or it breaks Insert as functionality
|
30
33
|
end
|
31
34
|
|
32
35
|
def effective_asset_video_tag(asset)
|
33
|
-
render(:partial => 'assets/video', :locals => { :asset => asset }).gsub('"', "'").html_safe # we need all ' quotes or it breaks Insert as functionality
|
36
|
+
render(:partial => 'effective/assets/video', :locals => { :asset => asset }).gsub('"', "'").html_safe # we need all ' quotes or it breaks Insert as functionality
|
34
37
|
end
|
35
38
|
|
36
39
|
def effective_asset_title(asset)
|
@@ -41,15 +44,15 @@ module EffectiveAssetsHelper
|
|
41
44
|
].compact.join("\n")
|
42
45
|
end
|
43
46
|
|
44
|
-
def _effective_asset_image_url(asset, version = nil)
|
47
|
+
def _effective_asset_image_url(asset, version = nil, public_url = nil)
|
45
48
|
# asset_url and image_url will work in Rails4
|
46
49
|
|
47
50
|
return image_path('mime-types/file.png') if !asset.content_type.present? or asset.content_type == 'unknown'
|
48
51
|
|
49
52
|
if asset.icon?
|
50
|
-
asset.url
|
53
|
+
(public_url ? asset.public_url : asset.url)
|
51
54
|
elsif asset.image?
|
52
|
-
asset.url(version)
|
55
|
+
(public_url ? asset.public_url(version) : asset.url(version))
|
53
56
|
elsif asset.audio?
|
54
57
|
image_path('mime-types/mp3.png')
|
55
58
|
elsif asset.video?
|
@@ -19,26 +19,32 @@ module Effective
|
|
19
19
|
|
20
20
|
has_many :attachments, :dependent => :delete_all
|
21
21
|
|
22
|
-
structure do
|
23
|
-
|
24
|
-
|
22
|
+
# structure do
|
23
|
+
# title :string
|
24
|
+
# extra :text
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
# content_type :string
|
27
|
+
# upload_file :string # The full url of the file, as originally uploaded
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
# processed :boolean, :default => false
|
30
|
+
# aws_acl :string, :default => 'public-read'
|
31
31
|
|
32
|
-
|
32
|
+
# data :string
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
# data_size :integer
|
35
|
+
# height :integer
|
36
|
+
# width :integer
|
37
37
|
|
38
|
-
|
38
|
+
# versions_info :text # We store a hash of {:thumb => 34567, :medium => 3343434} data sizes
|
39
39
|
|
40
|
-
|
41
|
-
end
|
40
|
+
# timestamps
|
41
|
+
# end
|
42
|
+
|
43
|
+
validates :content_type, presence: true
|
44
|
+
validates :upload_file, presence: true
|
45
|
+
validates :aws_acl, presence: true, inclusion: { in: [EffectiveAssets::AWS_PUBLIC, EffectiveAssets::AWS_PRIVATE] }
|
46
|
+
validates :height, numericality: { allow_nil: true }
|
47
|
+
validates :width, numericality: { allow_nil: true }
|
42
48
|
|
43
49
|
serialize :versions_info, Hash
|
44
50
|
serialize :extra, Hash
|
@@ -128,7 +134,7 @@ module Effective
|
|
128
134
|
end
|
129
135
|
|
130
136
|
def url(version = nil, expire_in = nil)
|
131
|
-
aws_acl ==
|
137
|
+
aws_acl == EffectiveAssets::AWS_PRIVATE ? authenticated_url(version, expire_in) : public_url(version)
|
132
138
|
end
|
133
139
|
|
134
140
|
def public_url(version = nil)
|
@@ -7,14 +7,16 @@ module Effective
|
|
7
7
|
belongs_to :asset
|
8
8
|
belongs_to :attachable, :polymorphic => true
|
9
9
|
|
10
|
-
structure do
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
# structure do
|
11
|
+
# position :integer
|
12
|
+
# box :string, :default => 'assets' # This is essentially a category
|
13
|
+
# end
|
14
14
|
|
15
15
|
default_scope -> { includes(:asset).order("\"#{EffectiveAssets.attachments_table_name.to_s}\".\"position\" ASC, \"#{EffectiveAssets.attachments_table_name.to_s}\".\"asset_id\" ASC") }
|
16
16
|
|
17
|
-
|
17
|
+
validates :asset_id, presence: true
|
18
|
+
validates :position, presence: true, numericality: true
|
19
|
+
validates :box, presence: true
|
18
20
|
|
19
21
|
end
|
20
22
|
end
|
@@ -70,11 +70,7 @@ module Inputs
|
|
70
70
|
def attachments_table_head_html
|
71
71
|
content_tag(:thead) do
|
72
72
|
content_tag(:tr) do
|
73
|
-
|
74
|
-
content_tag(:th, ''),
|
75
|
-
content_tag(:th, ''),
|
76
|
-
content_tag(:th, filter_bar_html, :colspan => 2)
|
77
|
-
].join().html_safe
|
73
|
+
content_tag(:th, filter_bar_html, :colspan => 4)
|
78
74
|
end
|
79
75
|
end
|
80
76
|
end
|
@@ -106,16 +102,11 @@ module Inputs
|
|
106
102
|
end
|
107
103
|
|
108
104
|
def filter_bar_html
|
109
|
-
"<input type='text' class='form-control filter-attachments' placeholder='
|
105
|
+
"<input type='text' class='form-control filter-attachments' placeholder='Filter by title'>".html_safe
|
110
106
|
end
|
111
107
|
|
112
108
|
def build_values_html
|
113
|
-
|
114
|
-
|
115
|
-
attachments.map do |attachment|
|
116
|
-
count += 1 unless attachment.marked_for_destruction?
|
117
|
-
|
118
|
-
attachment_partial =
|
109
|
+
attachment_partial =
|
119
110
|
case @options[:attachment_style]
|
120
111
|
when :table
|
121
112
|
'attachment_as_table'
|
@@ -129,18 +120,18 @@ module Inputs
|
|
129
120
|
raise "unknown AssetBox attachment_style: #{@options[:attachment_style]}. Valid options are :thumbnail, :list and :table"
|
130
121
|
end
|
131
122
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
123
|
+
render(
|
124
|
+
:partial => "asset_box_input/#{attachment_partial}",
|
125
|
+
:collection => attachments.reject { |attachment| attachment.marked_for_destruction? },
|
126
|
+
:as => :attachment,
|
127
|
+
:locals => {
|
128
|
+
:attachment_actions => @options[:attachment_actions].map { |action| action.to_s },
|
129
|
+
:attachment_links => @options[:attachment_links],
|
130
|
+
:limit => @options[:limit],
|
131
|
+
:disabled => @options[:disabled],
|
132
|
+
:attachable_object_name => @object_name
|
133
|
+
}
|
134
|
+
)
|
144
135
|
end
|
145
136
|
|
146
137
|
def footer_html
|
@@ -1,10 +1,12 @@
|
|
1
1
|
- uid = (attachment.persisted? ? attachment.id : Time.now.to_f.to_s.split('.')[1] + Random.rand(10000).to_s)
|
2
|
-
-
|
2
|
+
- limit ||= 99999999
|
3
|
+
- attachment_counter ||= 0
|
4
|
+
- hidden ||= (attachment_counter >= limit)
|
3
5
|
|
4
6
|
%li.attachment
|
5
7
|
.attachment-title.caption
|
6
8
|
- if attachment_links
|
7
|
-
= link_to attachment.asset.title, attachment.asset.
|
9
|
+
= link_to attachment.asset.title, attachment.asset.public_url, :target => '_blank'
|
8
10
|
- else
|
9
11
|
= attachment.asset.title
|
10
12
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
- uid = (attachment.persisted? ? attachment.id : Time.now.to_f.to_s.split('.')[1] + Random.rand(10000).to_s)
|
2
|
-
-
|
2
|
+
- limit ||= 99999999
|
3
|
+
- attachment_counter ||= 0
|
4
|
+
- hidden ||= (attachment_counter >= limit)
|
3
5
|
|
4
6
|
%tr.attachment{:style => "#{(attachment.marked_for_destruction? || hidden) ? 'display: none;' : ''}"}
|
5
7
|
%td.attachment-image
|
6
8
|
= effective_asset_image_tag(attachment.asset)
|
7
9
|
%td.attachment-title{:title => effective_asset_title(attachment.asset)}
|
8
10
|
- if attachment_links
|
9
|
-
= link_to attachment.asset.title, attachment.asset.
|
11
|
+
= link_to attachment.asset.title, attachment.asset.public_url, :target => '_blank'
|
10
12
|
- else
|
11
13
|
= attachment.asset.title
|
12
14
|
%td.attachment-size
|
@@ -15,11 +17,11 @@
|
|
15
17
|
- if attachment_actions.include?('insert') || attachment_actions.include?('attach')
|
16
18
|
- asset = attachment.asset
|
17
19
|
- if asset.image? || asset.icon?
|
18
|
-
%a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_image_tag(asset)} Attach
|
20
|
+
%a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_image_tag(asset, nil, public: true)} Attach
|
19
21
|
- elsif asset.video?
|
20
|
-
%a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_video_tag(asset)} Attach
|
22
|
+
%a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_video_tag(asset, nil, public: true)} Attach
|
21
23
|
- else
|
22
|
-
%a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_link_to(asset)} Attach
|
24
|
+
%a.btn.btn-primary.attachment-insert{:href => '#', 'data-asset-id' => asset.id, 'data-asset' => effective_asset_link_to(asset, nil, public: true)} Attach
|
23
25
|
|
24
26
|
- if attachment_actions.include?('remove')
|
25
27
|
%a.attachment-remove{:href => '#', :title => 'Remove'}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
- uid = (attachment.persisted? ? attachment.id : Time.now.to_f.to_s.split('.')[1] + Random.rand(10000).to_s)
|
2
|
-
-
|
2
|
+
- limit ||= 99999999
|
3
|
+
- attachment_counter ||= 0
|
4
|
+
- hidden ||= (attachment_counter >= limit)
|
3
5
|
|
4
6
|
.col-sm-3.attachment
|
5
7
|
.thumbnail{:style => "#{(attachment.marked_for_destruction? || hidden) ? 'display: none;' : ''}", :title => effective_asset_title(attachment.asset)}
|
@@ -7,7 +9,7 @@
|
|
7
9
|
|
8
10
|
.attachment-title.caption
|
9
11
|
- if attachment_links
|
10
|
-
= link_to attachment.asset.title, attachment.asset.
|
12
|
+
= link_to attachment.asset.title, attachment.asset.public_url, :target => '_blank'
|
11
13
|
- else
|
12
14
|
= attachment.asset.title
|
13
15
|
|
File without changes
|
data/lib/effective_assets.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'carrierwave-aws'
|
2
2
|
require 'delayed_job_active_record'
|
3
|
-
require 'migrant' # Required for rspec to run properly
|
4
3
|
require 'jquery-fileupload-rails'
|
5
4
|
require 'haml-rails'
|
6
5
|
require 'effective_assets/engine'
|
7
6
|
require 'effective_assets/version'
|
8
7
|
|
9
8
|
module EffectiveAssets
|
9
|
+
AWS_PUBLIC = 'public-read'
|
10
|
+
AWS_PRIVATE = 'authenticated-read'
|
11
|
+
IFRAME_UPLOADS = 'effective_iframe_uploads'
|
12
|
+
|
10
13
|
# The following are all valid config keys
|
11
14
|
mattr_accessor :assets_table_name
|
12
15
|
mattr_accessor :attachments_table_name
|
@@ -49,7 +52,7 @@ module EffectiveAssets
|
|
49
52
|
CarrierWave.configure do |config|
|
50
53
|
config.storage = :aws
|
51
54
|
config.aws_bucket = EffectiveAssets.aws_bucket
|
52
|
-
config.aws_acl = EffectiveAssets.aws_acl.presence ||
|
55
|
+
config.aws_acl = EffectiveAssets.aws_acl.presence || EffectiveAssets::AWS_PUBLIC
|
53
56
|
config.cache_dir = "#{Rails.root}/tmp/uploads" # For heroku
|
54
57
|
|
55
58
|
config.aws_credentials = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_assets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: migrant
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: mini_magick
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -197,8 +183,8 @@ files:
|
|
197
183
|
- app/models/effective/asset.rb
|
198
184
|
- app/models/effective/attachment.rb
|
199
185
|
- app/models/effective/delayed_job.rb
|
186
|
+
- app/models/effective/iframe_uploads.rb
|
200
187
|
- app/models/effective/snippets/effective_asset.rb
|
201
|
-
- app/models/effective/user_uploads.rb
|
202
188
|
- app/models/inputs/asset_box.rb
|
203
189
|
- app/models/inputs/asset_box_form_input.rb
|
204
190
|
- app/models/inputs/asset_box_formtastic_input.rb
|
@@ -217,7 +203,7 @@ files:
|
|
217
203
|
- app/views/asset_box_input/_dialog.html.haml
|
218
204
|
- app/views/asset_box_input/_progress_bar_template.html.haml
|
219
205
|
- app/views/asset_box_input/_uploader.html.haml
|
220
|
-
- app/views/assets/_video.html.erb
|
206
|
+
- app/views/effective/assets/_video.html.erb
|
221
207
|
- app/views/effective/assets/iframe.html.haml
|
222
208
|
- app/views/effective/snippets/_effective_asset.html.haml
|
223
209
|
- config/routes.rb
|