tb_banners 1.2.1 → 1.3.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.markdown +2 -12
- data/Rakefile +2 -5
- data/app/assets/javascripts/admin/banners/banners.js +34 -41
- data/app/controllers/admin/banner_sets_controller.rb +15 -19
- data/app/controllers/admin/banners_controller.rb +30 -52
- data/app/helpers/spud_banners_helper.rb +12 -12
- data/app/models/spud_banner.rb +18 -18
- data/app/models/spud_banner_set.rb +15 -17
- data/app/views/admin/banners/_form.html.erb +1 -3
- data/lib/spud_banners/configuration.rb +2 -2
- data/lib/spud_banners/engine.rb +6 -6
- data/lib/spud_banners/liquid_tags.rb +6 -3
- data/lib/spud_banners/version.rb +1 -1
- data/lib/tb_banners.rb +1 -1
- data/spec/authlogic_helper.rb +1 -1
- data/spec/controllers/admin/banner_sets_controller_spec.rb +33 -33
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +3 -6
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/20121127192247_create_spud_users.spud_core.rb +12 -12
- data/spec/dummy/db/migrate/20121127192248_add_time_zone_to_spud_user.spud_core.rb +0 -1
- data/spec/dummy/db/migrate/20121127192249_add_scope_to_spud_admin_permissions.spud_core.rb +0 -1
- data/spec/dummy/db/migrate/20130920154443_create_spud_permissions.tb_core.rb +3 -3
- data/spec/dummy/db/migrate/20130920154444_create_spud_role_permissions.tb_core.rb +2 -2
- data/spec/dummy/db/migrate/20130920154446_create_spud_banners.tb_banners.rb +4 -4
- data/spec/dummy/db/migrate/20130920154447_create_spud_banner_sets.tb_banners.rb +5 -5
- data/spec/dummy/db/migrate/20130920154448_add_rich_text_to_spud_banners.tb_banners.rb +1 -1
- data/spec/dummy/db/migrate/20160310164644_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
- data/spec/dummy/db/schema.rb +85 -92
- data/spec/dummy/script/rails +2 -2
- data/spec/rails_helper.rb +12 -5
- data/spec/spec_helper.rb +42 -44
- metadata +72 -31
- data/app/views/admin/banners/legacy.js.erb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4c5570408f1fd6f89b4ded74aaf55fbe28485c35
|
|
4
|
+
data.tar.gz: c747224366ee66af3f347a8c569d8d66bdb51956
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f55b7a276d17e9215bb54c109fdda5d0fe1515bb41c01da8197f98daff23f192fc31dc9c47f5c9d633a3ccb11654fe818ce8cbb4a3b977283404fa7f617f824
|
|
7
|
+
data.tar.gz: 10bef6d2c769966df3dd61b1543e2371a78c0a8e7ec2b541d8680109ce2614c5ef7fdd675f5e997d6c4f36b1f20531575cb836bdbf37d5bfdba863a4dffb99ed
|
data/README.markdown
CHANGED
|
@@ -103,21 +103,11 @@ Displaying banners using the helper, with a block for even more custom html.
|
|
|
103
103
|
</ul>
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
## Liquid
|
|
107
|
-
|
|
108
|
-
TB Banners comes with its own custom [Liquid][liquid] tag. For now the liquid tag only supports rendering the standard html as generated by the `spud_banners_for_set`. Will provide support more advanced options in the future.
|
|
109
|
-
|
|
110
|
-
Usage:
|
|
111
|
-
|
|
112
|
-
```erb
|
|
113
|
-
<%= raw Liquid::Template.parse("{% spud_banner_set Promotions %}").render %>
|
|
114
|
-
```
|
|
115
|
-
|
|
116
106
|
## Rich Text
|
|
117
107
|
|
|
118
|
-
Banner Sets contain a configuration for rich text. Turning this feature on will enable a rich text editor on individual banners. The default setting for this option is off.
|
|
108
|
+
Banner Sets contain a configuration for rich text. Turning this feature on will enable a rich text editor on individual banners. The default setting for this option is off.
|
|
119
109
|
|
|
120
|
-
Rich text is intended to be more of an edge case feature, and should be used only if your banner needs to include an editable HTML block. The built-in helpers described earlier will not automatically include your rich text; If you want to use this feature, you should supply a block to the helper and render the rich text yourself.
|
|
110
|
+
Rich text is intended to be more of an edge case feature, and should be used only if your banner needs to include an editable HTML block. The built-in helpers described earlier will not automatically include your rich text; If you want to use this feature, you should supply a block to the helper and render the rich text yourself.
|
|
121
111
|
|
|
122
112
|
```erb
|
|
123
113
|
<ul id="slides">
|
data/Rakefile
CHANGED
|
@@ -20,11 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
APP_RAKEFILE = File.expand_path(
|
|
23
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
|
24
24
|
load 'rails/tasks/engine.rake'
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
26
|
Bundler::GemHelper.install_tasks
|
|
29
27
|
|
|
30
28
|
require 'rake/testtask'
|
|
@@ -36,5 +34,4 @@ Rake::TestTask.new(:test) do |t|
|
|
|
36
34
|
t.verbose = false
|
|
37
35
|
end
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
task :default => :test
|
|
37
|
+
task default: :test
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
(function(){
|
|
5
5
|
|
|
6
|
-
var html5upload = false;
|
|
7
6
|
var bannerEditId = false;
|
|
8
7
|
|
|
9
8
|
spud.admin.banners = {
|
|
@@ -11,9 +10,6 @@ spud.admin.banners = {
|
|
|
11
10
|
// Index Page
|
|
12
11
|
/////////////
|
|
13
12
|
init: function(){
|
|
14
|
-
if(typeof(FormData) != 'undefined'){
|
|
15
|
-
html5upload = true;
|
|
16
|
-
}
|
|
17
13
|
$('.admin-banner-set-item-add').on('click', clickedAddNewBanner);
|
|
18
14
|
$('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-edit', clickedEditBanner);
|
|
19
15
|
$('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-delete', clickedDeleteBanner);
|
|
@@ -87,43 +83,41 @@ var clickedDeleteBanner = function(e){
|
|
|
87
83
|
};
|
|
88
84
|
|
|
89
85
|
var submittedBannerForm = function(e){
|
|
90
|
-
|
|
91
|
-
e.preventDefault();
|
|
86
|
+
e.preventDefault();
|
|
92
87
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
$('input[type=text], input[type=hidden], select').each(function(index, element){
|
|
97
|
-
var input = $(element);
|
|
98
|
-
var name = input.attr('name');
|
|
99
|
-
var value = input.val();
|
|
100
|
-
fd.append(name, value);
|
|
101
|
-
});
|
|
88
|
+
var form = $(this);
|
|
89
|
+
var fd = new FormData();
|
|
102
90
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
91
|
+
$('input[type=text], input[type=hidden], select').each(function(index, element){
|
|
92
|
+
var input = $(element);
|
|
93
|
+
var name = input.attr('name');
|
|
94
|
+
var value = input.val();
|
|
95
|
+
fd.append(name, value);
|
|
96
|
+
});
|
|
110
97
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
var richText = form.find('.admin-banner-rich-text');
|
|
99
|
+
if(richText.length > 0){
|
|
100
|
+
fd.append('spud_banner[rich_text]', richText.val());
|
|
101
|
+
}
|
|
102
|
+
else{
|
|
103
|
+
fd.append('spud_banner[rich_text]', '');
|
|
104
|
+
}
|
|
116
105
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
xhr.addEventListener('abort', onFileUploadAbort);
|
|
122
|
-
xhr.open('POST', form.attr('action'));
|
|
123
|
-
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
124
|
-
xhr.send(fd);
|
|
125
|
-
return false;
|
|
106
|
+
var file = form.find('#spud_banner_banner')[0].files[0];
|
|
107
|
+
if(file){
|
|
108
|
+
fd.append('spud_banner[banner]', file);
|
|
109
|
+
$('.admin-banner-upload-progress').show();
|
|
126
110
|
}
|
|
111
|
+
|
|
112
|
+
var xhr = new XMLHttpRequest();
|
|
113
|
+
xhr.upload.addEventListener('progress', onFileUploadProgress);
|
|
114
|
+
xhr.addEventListener('load', onFileUploadComplete);
|
|
115
|
+
xhr.addEventListener('error', onFileUploadError);
|
|
116
|
+
xhr.addEventListener('abort', onFileUploadAbort);
|
|
117
|
+
xhr.open('POST', form.attr('action'));
|
|
118
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
119
|
+
xhr.send(fd);
|
|
120
|
+
return false;
|
|
127
121
|
};
|
|
128
122
|
|
|
129
123
|
var onFileUploadProgress = function(e){
|
|
@@ -138,10 +132,10 @@ var onFileUploadProgress = function(e){
|
|
|
138
132
|
var onFileUploadComplete = function(e){
|
|
139
133
|
switch(this.status){
|
|
140
134
|
case 200:
|
|
141
|
-
|
|
135
|
+
onUploadComplete(e.target.response);
|
|
142
136
|
break;
|
|
143
137
|
case 422:
|
|
144
|
-
|
|
138
|
+
onUploadError(e.target.response);
|
|
145
139
|
break;
|
|
146
140
|
default:
|
|
147
141
|
window.alert("Whoops! Something has gone wrong.");
|
|
@@ -156,8 +150,7 @@ var onFileUploadAbort = function(e){
|
|
|
156
150
|
|
|
157
151
|
};
|
|
158
152
|
|
|
159
|
-
|
|
160
|
-
spud.admin.banners.onLegacyUploadComplete = function(html){
|
|
153
|
+
var onUploadComplete = function(html){
|
|
161
154
|
if(bannerEditId){
|
|
162
155
|
var item = $('.admin-banner-set-item[data-id="'+bannerEditId+'"]');
|
|
163
156
|
item.replaceWith(html);
|
|
@@ -168,7 +161,7 @@ spud.admin.banners.onLegacyUploadComplete = function(html){
|
|
|
168
161
|
spud.admin.modal.hide();
|
|
169
162
|
};
|
|
170
163
|
|
|
171
|
-
|
|
164
|
+
var onUploadError = function(html){
|
|
172
165
|
$('.admin-banner-form').replaceWith(html);
|
|
173
166
|
initForm();
|
|
174
167
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class Admin::BannerSetsController < Admin::ApplicationController
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
before_action :get_record, only: [:show, :edit, :update, :destroy]
|
|
4
4
|
respond_to :html
|
|
5
5
|
belongs_to_app :banner_sets
|
|
6
6
|
add_breadcrumb 'Banner Sets', :admin_banner_sets_path
|
|
@@ -8,11 +8,11 @@ class Admin::BannerSetsController < Admin::ApplicationController
|
|
|
8
8
|
|
|
9
9
|
def index
|
|
10
10
|
@banner_sets = SpudBannerSet.all
|
|
11
|
-
respond_with @banner_sets, :
|
|
11
|
+
respond_with @banner_sets, layout: 'admin/detail'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def show
|
|
15
|
-
respond_with @banner_set, :
|
|
15
|
+
respond_with @banner_set, layout: 'admin/detail'
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def new
|
|
@@ -23,10 +23,10 @@ class Admin::BannerSetsController < Admin::ApplicationController
|
|
|
23
23
|
def create
|
|
24
24
|
@banner_set = SpudBannerSet.new(banner_set_params)
|
|
25
25
|
if @banner_set.save
|
|
26
|
-
flash.now[:notice] = 'BannerSet created successfully'
|
|
26
|
+
flash.now[:notice] = 'BannerSet created successfully'
|
|
27
27
|
render 'create'
|
|
28
28
|
else
|
|
29
|
-
render 'new', :
|
|
29
|
+
render 'new', status: 422
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -39,31 +39,27 @@ class Admin::BannerSetsController < Admin::ApplicationController
|
|
|
39
39
|
flash.now[:notice] = 'BannerSet updated successfully'
|
|
40
40
|
render 'create'
|
|
41
41
|
else
|
|
42
|
-
render 'edit', :
|
|
42
|
+
render 'edit', status: 422
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def destroy
|
|
47
|
-
if @banner_set.destroy
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
render :nothing => true
|
|
47
|
+
flash.now[:notice] = 'BannerSet deleted successfully' if @banner_set.destroy
|
|
48
|
+
head :ok
|
|
51
49
|
end
|
|
52
50
|
|
|
53
|
-
private
|
|
51
|
+
private
|
|
54
52
|
|
|
55
53
|
def get_record
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return false
|
|
62
|
-
end
|
|
54
|
+
@banner_set = SpudBannerSet.find(params[:id])
|
|
55
|
+
rescue ActiveRecord::RecordNotFound => e
|
|
56
|
+
flash.now[:error] = 'Could not find the requested BannerSet'
|
|
57
|
+
redirect_to admin_banner_sets_path
|
|
58
|
+
return false
|
|
63
59
|
end
|
|
64
60
|
|
|
65
61
|
def banner_set_params
|
|
66
62
|
params.require(:spud_banner_set).permit(:cropped, :height, :name, :short_name, :width, :has_rich_text)
|
|
67
63
|
end
|
|
68
64
|
|
|
69
|
-
end
|
|
65
|
+
end
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
class Admin::BannersController < Admin::ApplicationController
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
before_filter :get_set, :only => [:new, :create]
|
|
6
|
-
before_filter :get_record, :only => [:edit, :update, :destroy]
|
|
3
|
+
before_action :get_set, only: [:new, :create]
|
|
4
|
+
before_action :get_record, only: [:edit, :update, :destroy]
|
|
7
5
|
respond_to :html
|
|
8
6
|
layout false
|
|
9
7
|
|
|
10
8
|
def new
|
|
11
|
-
@banner = @banner_set.banners.new(:
|
|
9
|
+
@banner = @banner_set.banners.new(start_date: Date.today)
|
|
12
10
|
respond_with @banner
|
|
13
11
|
end
|
|
14
12
|
|
|
@@ -16,23 +14,14 @@ class Admin::BannersController < Admin::ApplicationController
|
|
|
16
14
|
@banner = @banner_set.banners.build
|
|
17
15
|
@banner.attributes = banner_params
|
|
18
16
|
|
|
19
|
-
last_banner = SpudBanner.select('sort_order').where(:
|
|
20
|
-
if last_banner
|
|
21
|
-
@banner.sort_order = last_banner.sort_order + 1
|
|
22
|
-
end
|
|
17
|
+
last_banner = SpudBanner.select('sort_order').where(spud_banner_set_id: @banner_set.id).order('sort_order desc').first
|
|
18
|
+
@banner.sort_order = last_banner.sort_order + 1 if last_banner
|
|
23
19
|
|
|
24
|
-
if
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
render 'show'
|
|
28
|
-
else
|
|
29
|
-
render 'new', :status => 422
|
|
30
|
-
end
|
|
20
|
+
if @banner.save
|
|
21
|
+
flash.now[:notice] = 'SpudBanner created successfully'
|
|
22
|
+
render 'show'
|
|
31
23
|
else
|
|
32
|
-
|
|
33
|
-
respond_to_parent do
|
|
34
|
-
render 'legacy', :formats => [:js]
|
|
35
|
-
end
|
|
24
|
+
render 'new', status: 422
|
|
36
25
|
end
|
|
37
26
|
end
|
|
38
27
|
|
|
@@ -41,68 +30,57 @@ class Admin::BannersController < Admin::ApplicationController
|
|
|
41
30
|
end
|
|
42
31
|
|
|
43
32
|
def update
|
|
44
|
-
if
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
render 'show'
|
|
48
|
-
else
|
|
49
|
-
render 'edit', :status => 422
|
|
50
|
-
end
|
|
33
|
+
if @banner.update_attributes(banner_params)
|
|
34
|
+
flash.now[:notice] = 'SpudBanner created successfully'
|
|
35
|
+
render 'show'
|
|
51
36
|
else
|
|
52
|
-
|
|
53
|
-
respond_to_parent do
|
|
54
|
-
render 'legacy', :formats => [:js]
|
|
55
|
-
end
|
|
37
|
+
render 'edit', status: 422
|
|
56
38
|
end
|
|
57
39
|
end
|
|
58
40
|
|
|
59
41
|
def destroy
|
|
60
42
|
if @banner.destroy
|
|
61
|
-
flash.now[:notice] = 'SpudBanner deleted successfully'
|
|
43
|
+
flash.now[:notice] = 'SpudBanner deleted successfully'
|
|
62
44
|
status = 200
|
|
63
45
|
else
|
|
64
46
|
status = 422
|
|
65
47
|
end
|
|
66
|
-
render :
|
|
48
|
+
render blank: true, status: status
|
|
67
49
|
end
|
|
68
50
|
|
|
69
51
|
def sort
|
|
70
52
|
banner_ids = params[:spud_banner_ids]
|
|
71
|
-
banners = SpudBanner.where(:
|
|
53
|
+
banners = SpudBanner.where(id: banner_ids).to_a
|
|
72
54
|
SpudBanner.transaction do
|
|
73
55
|
banner_ids.each_with_index do |id, index|
|
|
74
|
-
banner = banners.select{ |b| b.id == id.to_i }.first
|
|
56
|
+
banner = banners.select { |b| b.id == id.to_i }.first
|
|
75
57
|
banner.update_column(:sort_order, index)
|
|
76
58
|
end
|
|
77
59
|
banners.last.owner.touch()
|
|
78
60
|
end
|
|
79
|
-
|
|
61
|
+
head :ok
|
|
80
62
|
end
|
|
81
63
|
|
|
82
|
-
private
|
|
64
|
+
private
|
|
83
65
|
|
|
84
66
|
def get_set
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return false
|
|
91
|
-
end
|
|
67
|
+
@banner_set = SpudBannerSet.find(params[:banner_set_id])
|
|
68
|
+
rescue ActiveRecord::RecordNotFound => e
|
|
69
|
+
flash.now[:error] = 'Could not find the requested SpudBannerSet'
|
|
70
|
+
render blank: true, status: 404
|
|
71
|
+
return false
|
|
92
72
|
end
|
|
93
73
|
|
|
94
74
|
def get_record
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return false
|
|
101
|
-
end
|
|
75
|
+
@banner = SpudBanner.find(params[:id])
|
|
76
|
+
rescue ActiveRecord::RecordNotFound => e
|
|
77
|
+
flash.now[:error] = 'Could not find the requested SpudBanner'
|
|
78
|
+
redirect_to admin_banner_sets_path
|
|
79
|
+
return false
|
|
102
80
|
end
|
|
103
81
|
|
|
104
82
|
def banner_params
|
|
105
83
|
params.require(:spud_banner).permit(:banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text, :start_date, :end_date)
|
|
106
84
|
end
|
|
107
85
|
|
|
108
|
-
end
|
|
86
|
+
end
|
|
@@ -9,11 +9,11 @@ module SpudBannersHelper
|
|
|
9
9
|
# - background_image: Pass true to return the banners as CSS background-image properties rather than <img/> tags
|
|
10
10
|
#
|
|
11
11
|
def spud_banners_for_set(set_or_identifier, options = {})
|
|
12
|
-
if set_or_identifier.is_a?(SpudBannerSet)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
banner_set = if set_or_identifier.is_a?(SpudBannerSet)
|
|
13
|
+
set_or_identifier
|
|
14
|
+
else
|
|
15
|
+
SpudBannerSet.find_with_identifier(set_or_identifier)
|
|
16
|
+
end
|
|
17
17
|
return '' if banner_set.blank?
|
|
18
18
|
cache(banner_set) do
|
|
19
19
|
concat spud_banners_set_tag(banner_set, options)
|
|
@@ -39,13 +39,13 @@ module SpudBannersHelper
|
|
|
39
39
|
content_tag(:div, :class => "spud-banner-set #{options[:wrapper_class]}", 'data-id' => banner_set.id) do
|
|
40
40
|
banners_query.map do |banner|
|
|
41
41
|
if background_image
|
|
42
|
-
concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id, :style => "background-image:url('#{banner.banner.url(:banner)}');")
|
|
42
|
+
concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id, :style => "background-image:url('#{banner.banner.url(:banner)}');") do
|
|
43
43
|
if banner.rich_text
|
|
44
|
-
content_tag :div, raw(banner.rich_text), :
|
|
44
|
+
content_tag :div, raw(banner.rich_text), class: 'spud-banner-rich-text'
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
end)
|
|
47
47
|
else
|
|
48
|
-
concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id){ spud_banner_tag(banner, options) })
|
|
48
|
+
concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id) { spud_banner_tag(banner, options) })
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
end
|
|
@@ -55,11 +55,11 @@ module SpudBannersHelper
|
|
|
55
55
|
# Returns an HTML tag for a single banner
|
|
56
56
|
# May return either an <img/> or an <a/> depending on the banner
|
|
57
57
|
#
|
|
58
|
-
def spud_banner_tag(banner,
|
|
58
|
+
def spud_banner_tag(banner, _options = {})
|
|
59
59
|
if banner.link_to.blank?
|
|
60
60
|
spud_banner_image_tag(banner)
|
|
61
61
|
else
|
|
62
|
-
link_to(banner.link_to, :
|
|
62
|
+
link_to(banner.link_to, target: banner.link_target) do
|
|
63
63
|
spud_banner_image_tag(banner)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -68,7 +68,7 @@ module SpudBannersHelper
|
|
|
68
68
|
# Returns an HTML <img/> tag for a single banner
|
|
69
69
|
#
|
|
70
70
|
def spud_banner_image_tag(banner)
|
|
71
|
-
image_tag(banner.banner.url(:banner), :
|
|
71
|
+
image_tag(banner.banner.url(:banner), alt: banner.alt, title: banner.title)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
end
|
data/app/models/spud_banner.rb
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
class SpudBanner < ActiveRecord::Base
|
|
2
|
-
belongs_to :owner, :
|
|
2
|
+
belongs_to :owner, class_name: 'SpudBannerSet', foreign_key: 'spud_banner_set_id', inverse_of: :banners, touch: true
|
|
3
3
|
|
|
4
|
-
scope :active, ->{
|
|
4
|
+
scope :active, -> {
|
|
5
5
|
where('(start_date IS NULL OR start_date <= ?) AND (end_date IS NULL OR end_date >= ?)', Date.today, Date.today)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
has_attached_file :banner,
|
|
9
|
-
:
|
|
10
|
-
:
|
|
11
|
-
:
|
|
12
|
-
:
|
|
8
|
+
has_attached_file :banner,
|
|
9
|
+
styles: ->(attachment) { attachment.instance.dynamic_styles },
|
|
10
|
+
convert_options: {
|
|
11
|
+
tiny: '-strip -density 72x72',
|
|
12
|
+
banner: '-strip -density 72x72'
|
|
13
13
|
},
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:
|
|
18
|
-
:
|
|
14
|
+
storage: Spud::Banners.paperclip_storage,
|
|
15
|
+
s3_credentials: Spud::Banners.s3_credentials,
|
|
16
|
+
s3_protocol: Spud::Banners.s3_protocol,
|
|
17
|
+
url: Spud::Banners.storage_url,
|
|
18
|
+
path: Spud::Banners.storage_path
|
|
19
19
|
|
|
20
20
|
validates_attachment :banner,
|
|
21
|
-
:
|
|
22
|
-
:
|
|
21
|
+
presence: true,
|
|
22
|
+
content_type: { content_type: ['image/jpg', 'image/jpeg', 'image/png'] }
|
|
23
23
|
|
|
24
24
|
def dynamic_styles
|
|
25
25
|
styles = {
|
|
26
|
-
:
|
|
26
|
+
tiny: '150x150'
|
|
27
27
|
}
|
|
28
28
|
owner_style = nil
|
|
29
|
-
if
|
|
30
|
-
owner_style = "#{
|
|
31
|
-
owner_style += '#' if
|
|
29
|
+
if owner
|
|
30
|
+
owner_style = "#{owner.width}x#{owner.height}"
|
|
31
|
+
owner_style += '#' if owner.cropped
|
|
32
32
|
styles[:banner] = owner_style
|
|
33
33
|
end
|
|
34
34
|
return styles
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
class SpudBannerSet < ActiveRecord::Base
|
|
2
|
-
has_many :banners, ->{ order('sort_order asc') }, :
|
|
2
|
+
has_many :banners, -> { order('sort_order asc') }, class_name: 'SpudBanner', dependent: :destroy, inverse_of: :owner
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
validates :name, presence: true
|
|
5
|
+
validates :name, uniqueness: true
|
|
6
|
+
validates :width, :height, numericality: true
|
|
7
7
|
|
|
8
8
|
acts_as_tb_liquid_tag :spud_banner_set, :name
|
|
9
9
|
|
|
10
10
|
after_update :check_for_dimension_change
|
|
11
11
|
|
|
12
|
-
def self.
|
|
13
|
-
if identifier.class == String
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
def self.find_with_identifier(identifier)
|
|
13
|
+
banner_set = if identifier.class == String
|
|
14
|
+
SpudBannerSet.find_by(name: identifier.strip)
|
|
15
|
+
elsif identifier.class == Symbol
|
|
16
|
+
SpudBannerSet.find_by(name: identifier.to_s.titleize)
|
|
17
|
+
else
|
|
18
|
+
SpudBannerSet.find(identifier)
|
|
19
|
+
end
|
|
20
20
|
return banner_set
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def reprocess_banners!
|
|
24
|
-
|
|
24
|
+
banners.each do |banner|
|
|
25
25
|
banner.banner.reprocess!
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -30,12 +30,10 @@ class SpudBannerSet < ActiveRecord::Base
|
|
|
30
30
|
return name
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
private
|
|
33
|
+
private
|
|
34
34
|
|
|
35
35
|
def check_for_dimension_change
|
|
36
|
-
if
|
|
37
|
-
self.reprocess_banners!
|
|
38
|
-
end
|
|
36
|
+
reprocess_banners! if height_changed? || width_changed? || cropped_changed?
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<%= form_for @banner, :url => path, :builder => TbCore::FormBuilder, :html => {:class => 'admin-banner-form'
|
|
1
|
+
<%= form_for @banner, :url => path, :builder => TbCore::FormBuilder, :html => { :class => 'admin-banner-form' } do |f| %>
|
|
2
2
|
|
|
3
3
|
<%= tb_form_errors(f.object) %>
|
|
4
4
|
|
|
@@ -63,5 +63,3 @@
|
|
|
63
63
|
</div>
|
|
64
64
|
|
|
65
65
|
<% end %>
|
|
66
|
-
|
|
67
|
-
<iframe id="admin-banner-upload-target" name="admin-banner-upload-target" style="display:none;"></iframe>
|
|
@@ -5,7 +5,7 @@ module Spud
|
|
|
5
5
|
self.paperclip_storage = :filesystem
|
|
6
6
|
self.s3_credentials = "#{Rails.root}/config/s3.yml"
|
|
7
7
|
self.s3_protocol = 'https'
|
|
8
|
-
self.storage_path =
|
|
9
|
-
self.storage_url =
|
|
8
|
+
self.storage_path = ':rails_root/public/system/spud_banners/:id/:style/:basename.:extension'
|
|
9
|
+
self.storage_url = '/system/spud_banners/:id/:style/:basename.:extension'
|
|
10
10
|
end
|
|
11
11
|
end
|
data/lib/spud_banners/engine.rb
CHANGED
|
@@ -6,14 +6,14 @@ module Spud
|
|
|
6
6
|
module Banners
|
|
7
7
|
class Engine < Rails::Engine
|
|
8
8
|
engine_name :tb_banners
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
initializer :admin do
|
|
11
11
|
Spud::Core.config.admin_applications += [{
|
|
12
|
-
:
|
|
13
|
-
:
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
12
|
+
name: 'Banner Sets',
|
|
13
|
+
thumbnail: 'admin/banners/banners.png',
|
|
14
|
+
retina: true,
|
|
15
|
+
url: '/admin/banner_sets',
|
|
16
|
+
order: 120
|
|
17
17
|
}]
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -10,8 +10,11 @@ module Spud
|
|
|
10
10
|
include ActionView::Context
|
|
11
11
|
include SpudBannersHelper
|
|
12
12
|
|
|
13
|
-
def initialize(
|
|
14
|
-
|
|
13
|
+
def initialize(_tag_name, set_identifer, _tokens)
|
|
14
|
+
ActiveSupport::Deprecation.warn(
|
|
15
|
+
'Support for the spud_banners liquid tag is going away. If you are using this, please refactor your code soon.'
|
|
16
|
+
)
|
|
17
|
+
@banner_set = SpudBannerSet.find_with_identifier(set_identifer)
|
|
15
18
|
end
|
|
16
19
|
|
|
17
20
|
def tag_name
|
|
@@ -22,7 +25,7 @@ module Spud
|
|
|
22
25
|
return @banner_set.name
|
|
23
26
|
end
|
|
24
27
|
|
|
25
|
-
def render(
|
|
28
|
+
def render(_context)
|
|
26
29
|
return spud_banners_set_tag(@banner_set)
|
|
27
30
|
end
|
|
28
31
|
|
data/lib/spud_banners/version.rb
CHANGED
data/lib/tb_banners.rb
CHANGED
data/spec/authlogic_helper.rb
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
require 'authlogic/test_case'
|
|
2
|
-
include Authlogic::TestCase
|
|
2
|
+
include Authlogic::TestCase
|