refinerycms-images 4.0.3 → 4.1.0
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/app/controllers/refinery/admin/images_controller.rb +48 -9
- data/app/helpers/refinery/admin/images_helper.rb +12 -6
- data/app/models/refinery/image.rb +20 -12
- data/app/presenters/refinery/admin/grid_presenter.rb +42 -0
- data/app/presenters/refinery/admin/group_presenter.rb +68 -0
- data/app/presenters/refinery/admin/image_presenter.rb +145 -0
- data/app/presenters/refinery/admin/list_presenter.rb +23 -0
- data/app/views/refinery/admin/images/_crop.html.erb +7 -0
- data/app/views/refinery/admin/images/_existing_image.html.erb +52 -27
- data/app/views/refinery/admin/images/_form.html.erb +60 -12
- data/app/views/refinery/admin/images/_image.html.erb +5 -0
- data/app/views/refinery/admin/images/_list_view.html.erb +2 -2
- data/app/views/refinery/admin/images/destroy_crop.js.erb +18 -0
- data/config/locales/en.yml +11 -1
- data/config/locales/fr.yml +10 -0
- data/config/locales/sk.yml +17 -1
- data/config/routes.rb +6 -4
- data/db/migrate/20150430171341_translate_refinery_images.rb +13 -17
- data/db/migrate/20180711122352_add_parent_id_to_refinery_images.rb +5 -0
- data/lib/generators/refinery/images/templates/config/initializers/refinery/images.rb.erb +5 -2
- data/lib/refinery/images/configuration.rb +13 -7
- data/lib/refinery/images/validators/image_size_validator.rb +8 -8
- data/lib/refinery/images/validators/image_update_validator.rb +3 -3
- data/lib/refinery/images.rb +3 -3
- data/lib/refinerycms/images.rb +1 -0
- data/lib/refinerycms-images.rb +0 -1
- data/refinerycms-images.gemspec +13 -20
- data/spec/factories/image.rb +3 -3
- data/spec/support/shared_contexts/admin_images_tab.rb +1 -1
- data/spec/support/shared_contexts/grid_view.rb +8 -0
- data/spec/support/shared_contexts/list_view.rb +12 -0
- data/spec/support/shared_examples/image_deleter.rb +1 -1
- data/spec/support/shared_examples/image_previewer.rb +1 -1
- data/spec/support/shared_examples/image_translator.rb +1 -1
- data/spec/support/shared_examples/image_uploader.rb +6 -3
- data/spec/{features → system}/refinery/admin/dialog_spec.rb +1 -1
- data/spec/{features → system}/refinery/admin/images_spec.rb +13 -1
- metadata +31 -87
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
object: @image,
|
|
6
6
|
include_object_name: false %>
|
|
7
7
|
|
|
8
|
-
<%= render '/refinery/admin/locale_picker', :current_locale =>
|
|
8
|
+
<%= render '/refinery/admin/locale_picker', :current_locale => Mobility.locale if @image.persisted? %>
|
|
9
9
|
|
|
10
10
|
<div class="field">
|
|
11
11
|
<% if action_name =~ /(edit)|(update)/ %>
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
<%= f.file_field :image %>
|
|
18
18
|
</p>
|
|
19
19
|
<% else %>
|
|
20
|
-
|
|
20
|
+
<%# we must only hint at multiple when it's a new record otherwise update fails. %>
|
|
21
21
|
<%= f.file_field :image, multiple: true %>
|
|
22
22
|
<% end %>
|
|
23
23
|
</div>
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<label><%= t('.maximum_image_size', bytes: number_to_human_size(Refinery::Images.max_image_size)) %></label>
|
|
27
27
|
</div>
|
|
28
28
|
<div class="field" id="title">
|
|
29
|
-
<span class=
|
|
29
|
+
<span class="label_with_help">
|
|
30
30
|
<%= f.label :image_title, t('.image_title') %>
|
|
31
31
|
<%= refinery_help_tag t('.image_title_help') %>
|
|
32
32
|
</span>
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
</div>
|
|
35
35
|
|
|
36
36
|
<div class="field" id="alt">
|
|
37
|
-
<span class=
|
|
37
|
+
<span class="label_with_help">
|
|
38
38
|
<%= f.label :image_alt, t('.image_alt') %>
|
|
39
39
|
<%= refinery_help_tag t('.image_alt_help') %>
|
|
40
40
|
</span>
|
|
@@ -51,18 +51,66 @@
|
|
|
51
51
|
cancel_url: refinery.admin_images_path -%>
|
|
52
52
|
|
|
53
53
|
<% if @app_dialog %>
|
|
54
|
-
<input type="hidden" name="app_dialog" value="<%= @app_dialog %>"
|
|
55
|
-
<input type="hidden" name="field" value="<%= @field %>"
|
|
56
|
-
<input type="hidden" name="update_image" value="<%= @update_image %>"
|
|
57
|
-
<input type="hidden" name="thumbnail" value="<%= @thumbnail %>"
|
|
58
|
-
<input type="hidden" name="callback" value="<%= @callback %>"
|
|
59
|
-
<input type="hidden" name="conditions" value="<%= @conditions %>"
|
|
54
|
+
<input type="hidden" name="app_dialog" value="<%= @app_dialog %>">
|
|
55
|
+
<input type="hidden" name="field" value="<%= @field %>">
|
|
56
|
+
<input type="hidden" name="update_image" value="<%= @update_image %>">
|
|
57
|
+
<input type="hidden" name="thumbnail" value="<%= @thumbnail %>">
|
|
58
|
+
<input type="hidden" name="callback" value="<%= @callback %>">
|
|
59
|
+
<input type="hidden" name="conditions" value="<%= @conditions %>">
|
|
60
60
|
<% end %>
|
|
61
61
|
<% end %>
|
|
62
62
|
|
|
63
63
|
<% if action_name =~ /(edit)|(update)/ %>
|
|
64
64
|
<div id="existing_image">
|
|
65
|
-
<label><%=t('.current_image') %></label>
|
|
66
|
-
|
|
65
|
+
<label><%= t('.current_image') %></label>
|
|
66
|
+
<div id="original-image">
|
|
67
|
+
<%= image_tag @image.url, id: 'crop',
|
|
68
|
+
data: { mime_type: @image.mime_type,
|
|
69
|
+
filename: @image.image_name,
|
|
70
|
+
image_id: @image.id } %>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<section id="ratios" class="clearfix">
|
|
74
|
+
<%= form_for @image,
|
|
75
|
+
url: refinery.admin_image_crop_path(@image),
|
|
76
|
+
html: {
|
|
77
|
+
multipart: true,
|
|
78
|
+
id: "crop_image_#{@image.id}",
|
|
79
|
+
class: 'crop_image'
|
|
80
|
+
} do |f| %>
|
|
81
|
+
<div class="field">
|
|
82
|
+
<span class="label_with_help">
|
|
83
|
+
<%= f.label :ratio, t('.ratios') %>
|
|
84
|
+
<%= refinery_help_tag t('.choose_crop') %>
|
|
85
|
+
</span>
|
|
86
|
+
|
|
87
|
+
<% ::Refinery::Images.user_image_ratios.each do |ratio, value| %>
|
|
88
|
+
<%= f.button value, type: 'button', data: { value: value, ratio: ratio.to_s.parameterize } %>
|
|
89
|
+
<% end %>
|
|
90
|
+
|
|
91
|
+
<%= f.submit t('.save'), id: 'save_crop' %>
|
|
92
|
+
</div>
|
|
93
|
+
<% end %>
|
|
94
|
+
</section>
|
|
95
|
+
|
|
96
|
+
<section id="crops">
|
|
97
|
+
<h2><%= t('.available_crops') %></h2>
|
|
98
|
+
|
|
99
|
+
<% if @image.crops.present? %>
|
|
100
|
+
<ul id="crop-list" class="clearfix">
|
|
101
|
+
<%= render partial: 'crop', collection: @image.crops %>
|
|
102
|
+
</ul>
|
|
103
|
+
<% else %>
|
|
104
|
+
<p id="no-crops-yet"><strong><%= t('.no_crops_yet') %></strong></p>
|
|
105
|
+
<% end %>
|
|
106
|
+
</section>
|
|
67
107
|
</div>
|
|
108
|
+
|
|
109
|
+
<% content_for :after_javascript_libraries do %>
|
|
110
|
+
<%= javascript_include_tag 'cropper' %>
|
|
111
|
+
<%= javascript_include_tag 'canvas-to-blob' %>
|
|
112
|
+
<%= javascript_include_tag 'refinery/image_crop' %>
|
|
113
|
+
<% end %>
|
|
114
|
+
|
|
115
|
+
<% content_for :stylesheets, stylesheet_link_tag('cropper') -%>
|
|
68
116
|
<% end %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div id= 'image_list' class="<%= ['clearfix', 'pagination_frame', pagination_css_class].compact.join(' ') %>">
|
|
2
|
-
<% group_by_date(@images).each do |container| %>
|
|
3
|
-
<% date_time = (image_group = container.last).first.
|
|
2
|
+
<% group_by_date(@images, :updated_at).each do |container| %>
|
|
3
|
+
<% date_time = (image_group = container.last).first.updated_at %>
|
|
4
4
|
<% date = Date.parse(date_time.to_s) %>
|
|
5
5
|
<h3><%= l(date, format: :long ) %></h3>
|
|
6
6
|
<ul class='images_list'>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let cropList = document.getElementById('crop-list');
|
|
2
|
+
let deletedCrop = document.getElementById('crop_<%= image_id %>');
|
|
3
|
+
|
|
4
|
+
if(deletedCrop !== null) {
|
|
5
|
+
deletedCrop.parentNode.removeChild(deletedCrop);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if( cropList.querySelectorAll('li').length == 0) {
|
|
9
|
+
displayNoCropsYetText();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function displayNoCropsYetText(){
|
|
13
|
+
const noCropsYetText = document.getElementById('no-crops-yet');
|
|
14
|
+
|
|
15
|
+
if(noCropsYetText !== null && noCropsYetText.style.display != 'block') {
|
|
16
|
+
noCropsYetText.style.display = 'block';
|
|
17
|
+
}
|
|
18
|
+
}
|
data/config/locales/en.yml
CHANGED
|
@@ -21,6 +21,15 @@ en:
|
|
|
21
21
|
image_title_help: Extra information about the image
|
|
22
22
|
image_alt: Alt
|
|
23
23
|
image_alt_help: Text to use if the image cannot be displayed.
|
|
24
|
+
ratios: Ratios
|
|
25
|
+
choose_crop: To edit a crop, please select a format from the following list
|
|
26
|
+
available_crops: Available crops
|
|
27
|
+
save: Save crop
|
|
28
|
+
format: Format
|
|
29
|
+
crop_success: Crop has been successfully generated
|
|
30
|
+
no_crops_yet: There are no image crops yet. Click "Save crop" to add your first image crop.
|
|
31
|
+
crop:
|
|
32
|
+
delete_crop: "%{title} - Crop %{id}"
|
|
24
33
|
actions:
|
|
25
34
|
create_new_image: Add new image
|
|
26
35
|
records:
|
|
@@ -35,6 +44,7 @@ en:
|
|
|
35
44
|
button_text: Insert
|
|
36
45
|
resize_image: Resize the image?
|
|
37
46
|
size: Size
|
|
47
|
+
select_resize: Select resize
|
|
38
48
|
insert:
|
|
39
49
|
existing_image: Library
|
|
40
50
|
new_image: Upload
|
|
@@ -46,5 +56,5 @@ en:
|
|
|
46
56
|
refinery/image:
|
|
47
57
|
blank: You must specify an image for upload
|
|
48
58
|
too_big: Image should be smaller than %{size} bytes in size
|
|
49
|
-
incorrect_format:
|
|
59
|
+
incorrect_format: "Your image type is '%{actual}' but must be one of %{valid_types}"
|
|
50
60
|
different_file_name: New image can't have different file name
|
data/config/locales/fr.yml
CHANGED
|
@@ -19,6 +19,15 @@ fr:
|
|
|
19
19
|
image_title_help: Information complémentaire sur l'image
|
|
20
20
|
image_alt: Alt
|
|
21
21
|
image_alt_help: Texte utilise si l'image ne peut pas être affichée.
|
|
22
|
+
ratios: Ratios
|
|
23
|
+
choose_crop: Pour éditer un recadrage, veuillez sélectionner un format parmi la liste suivante
|
|
24
|
+
available_crops: Liste des recadrages disponibles
|
|
25
|
+
save: Sauvegarder le recadrage
|
|
26
|
+
format: Format
|
|
27
|
+
crop_success: Le recadrage a été généré avec succès
|
|
28
|
+
no_crops_yet: "Il n'y a actuellement aucun recadrage d'image. Cliquez sur 'Sauvegarder le recadrage' pour en ajouter un."
|
|
29
|
+
crop:
|
|
30
|
+
delete_crop: "%{title} - Recadrage %{id}"
|
|
22
31
|
actions:
|
|
23
32
|
create_new_image: Ajouter une image
|
|
24
33
|
records:
|
|
@@ -33,6 +42,7 @@ fr:
|
|
|
33
42
|
button_text: Insérer
|
|
34
43
|
resize_image: Redimensionner l'image ?
|
|
35
44
|
size: Taille
|
|
45
|
+
select_resize: Sélectionnez une taille
|
|
36
46
|
insert:
|
|
37
47
|
existing_image: Image existante
|
|
38
48
|
new_image: Nouvelle image
|
data/config/locales/sk.yml
CHANGED
|
@@ -5,6 +5,8 @@ sk:
|
|
|
5
5
|
title: Obrázky
|
|
6
6
|
description: Spravovať obrázky
|
|
7
7
|
admin:
|
|
8
|
+
locale_picker:
|
|
9
|
+
language: Jazyk
|
|
8
10
|
images:
|
|
9
11
|
delete: Zmazať tento obrázok
|
|
10
12
|
edit: Upraviť tento obrázok
|
|
@@ -15,6 +17,19 @@ sk:
|
|
|
15
17
|
replace_image: " nahradiť ho týmto..."
|
|
16
18
|
current_image: Vybraný obrázok
|
|
17
19
|
maximum_image_size: Maximálna veľkosť obrázku je %{bytes}.
|
|
20
|
+
image_title: Názov
|
|
21
|
+
image_title_help: Extra informácie o obrázku
|
|
22
|
+
image_alt: Alt
|
|
23
|
+
image_alt_help: Text, ktorý sa zobrazí, ak obrázok nemôže byť zobrazený.
|
|
24
|
+
ratios: Pomer strán
|
|
25
|
+
choose_crop: Aby ste mohli editovať zmenšeninu, prosím zvoľte formát z nasledovného zoznamu
|
|
26
|
+
available_crops: Dostupné zmenšeniny
|
|
27
|
+
save: Uložiť zmenšeninu
|
|
28
|
+
format: Formát
|
|
29
|
+
crop_success: Zmenšenina bola úspešne vygenerovaná
|
|
30
|
+
no_crops_yet: Zatiaľ neboli vytvorené žiadne zmenšeniny. Kliknite "Uložiť zmenšeninu" ak chcete pridať prvú
|
|
31
|
+
crop:
|
|
32
|
+
delete_crop: "%{title} - Zmenšenina %{id}"
|
|
18
33
|
actions:
|
|
19
34
|
create_new_image: Pridať nový obrázok
|
|
20
35
|
records:
|
|
@@ -29,6 +44,7 @@ sk:
|
|
|
29
44
|
button_text: Vložiť
|
|
30
45
|
resize_image: Upraviť veľkosť?
|
|
31
46
|
size: Veľkosť
|
|
47
|
+
select_resize: Vyberte veľkosť
|
|
32
48
|
insert:
|
|
33
49
|
existing_image: Knižnica
|
|
34
50
|
new_image: Nový obrázok
|
|
@@ -41,4 +57,4 @@ sk:
|
|
|
41
57
|
blank: Musíte zadať obrázok ktorý chcete nahrať.
|
|
42
58
|
too_big: Maximálna veľkosť obrázku %{size}MB in size.
|
|
43
59
|
incorrect_format: 'Obrázok musí byť vo formáte JPG, PNG alebo GIF.'
|
|
44
|
-
different_file_name: Nový obrázok nesmie mať odlišný názov súboru
|
|
60
|
+
different_file_name: Nový obrázok nesmie mať odlišný názov súboru
|
data/config/routes.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Refinery::Core::Engine.routes.draw do
|
|
2
|
-
get '/system/images/*dragonfly', :
|
|
2
|
+
get '/system/images/*dragonfly', to: Dragonfly.app(:refinery_images)
|
|
3
3
|
|
|
4
|
-
namespace :admin, :
|
|
5
|
-
resources :images, :
|
|
6
|
-
get :insert, :
|
|
4
|
+
namespace :admin, path: Refinery::Core.backend_route do
|
|
5
|
+
resources :images, except: :show do
|
|
6
|
+
get :insert, on: :collection
|
|
7
|
+
patch :crop
|
|
8
|
+
match 'crop', to: 'images#destroy_crop', via: :delete
|
|
7
9
|
end
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
class TranslateRefineryImages < ActiveRecord::Migration[4.2]
|
|
2
|
-
def
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
:migrate_data => true
|
|
9
|
-
})
|
|
10
|
-
rescue NameError
|
|
11
|
-
warn "Refinery::Image was not defined!"
|
|
12
|
-
end
|
|
13
|
-
end
|
|
2
|
+
def change
|
|
3
|
+
create_table :refinery_image_translations do |t|
|
|
4
|
+
|
|
5
|
+
# Translated attribute(s)
|
|
6
|
+
t.string :image_alt
|
|
7
|
+
t.string :image_title
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
warn "Refinery::Image was not defined!"
|
|
9
|
+
t.string :locale, null: false
|
|
10
|
+
t.integer :refinery_image_id, null: false
|
|
11
|
+
|
|
12
|
+
t.timestamps null: false
|
|
20
13
|
end
|
|
14
|
+
|
|
15
|
+
add_index :refinery_image_translations, :locale, name: :index_refinery_image_translations_on_locale
|
|
16
|
+
add_index :refinery_image_translations, [:refinery_image_id, :locale], name: :index_2f245f0c60154d35c851e1df2ffc4c86571726f0, unique: true
|
|
21
17
|
end
|
|
22
18
|
end
|
|
@@ -19,8 +19,11 @@ Refinery::Images.configure do |config|
|
|
|
19
19
|
# Configure image sizes
|
|
20
20
|
# config.user_image_sizes = <%= Refinery::Images.user_image_sizes.inspect %>
|
|
21
21
|
|
|
22
|
-
# Configure
|
|
23
|
-
# config.
|
|
22
|
+
# Configure image ratios
|
|
23
|
+
# config.user_image_ratios = <%= Refinery::Images.user_image_ratios.inspect %>
|
|
24
|
+
|
|
25
|
+
# Configure allowed mime types for validation
|
|
26
|
+
# config.allowed_mime_types = <%= Refinery::Images.allowed_mime_types.inspect %>
|
|
24
27
|
|
|
25
28
|
# Configure image view options
|
|
26
29
|
# config.image_views = <%= Refinery::Images.image_views.inspect %>
|
|
@@ -5,20 +5,26 @@ module Refinery
|
|
|
5
5
|
include ActiveSupport::Configurable
|
|
6
6
|
|
|
7
7
|
config_accessor :max_image_size, :pages_per_dialog, :pages_per_admin_index,
|
|
8
|
-
:pages_per_dialog_that_have_size_options, :user_image_sizes,
|
|
8
|
+
:pages_per_dialog_that_have_size_options, :user_image_sizes, :user_image_ratios,
|
|
9
9
|
:image_views, :preferred_image_view,
|
|
10
|
-
:
|
|
10
|
+
:allowed_mime_types, :allowed_mime_types_msg
|
|
11
11
|
|
|
12
12
|
self.max_image_size = 5_242_880
|
|
13
13
|
self.pages_per_dialog = 18
|
|
14
14
|
self.pages_per_dialog_that_have_size_options = 12
|
|
15
15
|
self.pages_per_admin_index = 20
|
|
16
16
|
self.user_image_sizes = {
|
|
17
|
-
:
|
|
18
|
-
:
|
|
19
|
-
:
|
|
17
|
+
small: '110x110>',
|
|
18
|
+
medium: '225x255>',
|
|
19
|
+
large: '450x450>'
|
|
20
20
|
}
|
|
21
|
-
self.
|
|
21
|
+
self.user_image_ratios = {
|
|
22
|
+
'16/9': '1.778',
|
|
23
|
+
'4/3': '1.333',
|
|
24
|
+
'1:1': 1
|
|
25
|
+
}
|
|
26
|
+
self.allowed_mime_types = %w[image/jpeg image/png image/gif image/tiff]
|
|
27
|
+
self.allowed_mime_types_msg = self.allowed_mime_types.to_sentence(last_word_connector: ' or ')
|
|
22
28
|
self.image_views = [:grid, :list]
|
|
23
29
|
self.preferred_image_view = :grid
|
|
24
30
|
|
|
@@ -31,6 +37,6 @@ module Refinery
|
|
|
31
37
|
name: :strip,
|
|
32
38
|
block: -> (content) { content.process!(:convert, '-strip') }
|
|
33
39
|
}]
|
|
34
|
-
|
|
35
40
|
end
|
|
41
|
+
|
|
36
42
|
end
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Refinery
|
|
2
4
|
module Images
|
|
3
5
|
module Validators
|
|
4
6
|
class ImageSizeValidator < ActiveModel::Validator
|
|
5
|
-
|
|
6
7
|
def validate(record)
|
|
7
|
-
image
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
record.errors[:image] << ::I18n.t('too_big',
|
|
11
|
-
:scope => 'activerecord.errors.models.refinery/image',
|
|
12
|
-
:size => Images.max_image_size)
|
|
13
|
-
end
|
|
8
|
+
record.errors.add(:image, ::I18n.t('too_big',
|
|
9
|
+
scope: 'activerecord.errors.models.refinery/image',
|
|
10
|
+
size: Images.max_image_size)) if too_big(record.image)
|
|
14
11
|
end
|
|
15
12
|
|
|
13
|
+
private def too_big(image)
|
|
14
|
+
image.respond_to?(:length) && image.length > Images.max_image_size
|
|
15
|
+
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Refinery
|
|
2
4
|
module Images
|
|
3
5
|
module Validators
|
|
4
6
|
class ImageUpdateValidator < ActiveModel::Validator
|
|
5
|
-
|
|
6
7
|
def validate(record)
|
|
7
8
|
if record.image_name_changed?
|
|
8
9
|
record.errors.add :image_name,
|
|
9
10
|
::I18n.t("different_file_name",
|
|
10
|
-
:
|
|
11
|
+
scope: "activerecord.errors.models.refinery/image")
|
|
11
12
|
end
|
|
12
13
|
end
|
|
13
|
-
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
end
|
data/lib/refinery/images.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
require 'refinerycms
|
|
2
|
-
require 'refinerycms
|
|
1
|
+
require 'refinerycms/core'
|
|
2
|
+
require 'refinerycms/dragonfly'
|
|
3
3
|
|
|
4
4
|
module Refinery
|
|
5
5
|
autoload :ImagesGenerator, 'generators/refinery/images/images_generator'
|
|
@@ -24,5 +24,5 @@ module Refinery
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
ActiveSupport.on_load(:active_record) do
|
|
27
|
-
require '
|
|
27
|
+
require 'mobility'
|
|
28
28
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative '../refinery/images'
|
data/lib/refinerycms-images.rb
CHANGED
data/refinerycms-images.gemspec
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../core/lib/refinery/version', __dir__)
|
|
3
4
|
|
|
4
5
|
version = Refinery::Version.to_s
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |s|
|
|
7
8
|
s.platform = Gem::Platform::RUBY
|
|
8
|
-
s.name =
|
|
9
|
+
s.name = 'refinerycms-images'
|
|
9
10
|
s.version = version
|
|
10
|
-
s.summary =
|
|
11
|
-
s.description =
|
|
12
|
-
s.email =
|
|
13
|
-
s.homepage =
|
|
14
|
-
s.
|
|
15
|
-
s.
|
|
16
|
-
s.
|
|
17
|
-
s.require_paths = %w(lib)
|
|
11
|
+
s.summary = 'Images extension for Refinery CMS'
|
|
12
|
+
s.description = 'Handles all image upload and processing functionality in Refinery CMS.'
|
|
13
|
+
s.email = 'gems@p.arndt.io'
|
|
14
|
+
s.homepage = 'https://www.refinerycms.com'
|
|
15
|
+
s.authors = ['Philip Arndt', 'David Jones', 'Uģis Ozols', 'Brice Sanchez']
|
|
16
|
+
s.license = 'MIT'
|
|
17
|
+
s.require_paths = %w[lib]
|
|
18
18
|
|
|
19
19
|
s.files = `git ls-files`.split("\n")
|
|
20
20
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
21
21
|
|
|
22
|
-
s.add_dependency 'refinerycms-
|
|
23
|
-
s.add_dependency '
|
|
24
|
-
s.add_dependency 'activemodel-serializers-xml', '~> 1.0', '>= 1.0.1'
|
|
25
|
-
s.add_dependency 'refinerycms-core', version
|
|
22
|
+
s.add_dependency 'refinerycms-core', version
|
|
23
|
+
s.add_dependency 'refinerycms-dragonfly', '~> 1.0'
|
|
26
24
|
|
|
27
25
|
s.required_ruby_version = Refinery::Version.required_ruby_version
|
|
28
|
-
|
|
29
|
-
s.cert_chain = [File.expand_path("../../certs/parndt.pem", __FILE__)]
|
|
30
|
-
if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__)
|
|
31
|
-
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
|
|
32
|
-
end
|
|
33
26
|
end
|
data/spec/factories/image.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
FactoryBot.define do
|
|
2
2
|
factory :image, :class => ::Refinery::Image do
|
|
3
|
-
image Refinery.roots('refinery/images').join("spec/fixtures/beach.jpeg")
|
|
3
|
+
image { Refinery.roots('refinery/images').join("spec/fixtures/beach.jpeg") }
|
|
4
4
|
end
|
|
5
5
|
|
|
6
6
|
factory :alternate_image, :class => ::Refinery::Image do
|
|
7
|
-
image Refinery.roots('refinery/images').join("spec/fixtures/beach-alternate.jpeg")
|
|
7
|
+
image { Refinery.roots('refinery/images').join("spec/fixtures/beach-alternate.jpeg") }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
factory :another_image, :class => ::Refinery::Image do
|
|
11
|
-
image Refinery.roots('refinery/images').join("spec/fixtures/fathead.png")
|
|
11
|
+
image { Refinery.roots('refinery/images').join("spec/fixtures/fathead.png") }
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
shared_context 'admin images tab' do
|
|
2
2
|
|
|
3
|
-
let(:open_upload_dialog) { find('a', text: ::I18n.t('create_new_image', scope: 'refinery.admin.images.actions')).
|
|
3
|
+
let(:open_upload_dialog) { find('a', text: ::I18n.t('create_new_image', scope: 'refinery.admin.images.actions')).click }
|
|
4
4
|
let(:select_upload) {}
|
|
5
5
|
let(:initialize_context) {}
|
|
6
6
|
let(:index_in_frame) {false}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
shared_context 'grid view' do
|
|
2
|
+
let(:initial_path) { refinery.admin_images_path + '?view=grid' }
|
|
3
|
+
let(:img_selector) { '> a img' }
|
|
4
|
+
let(:alt_selector) { 'span.alt' }
|
|
5
|
+
let(:title_selector) { 'span.title' }
|
|
6
|
+
let(:view_selector) {'#image_index.grid'}
|
|
7
|
+
let(:alt_view) {'list'}
|
|
8
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
shared_context 'list view' do
|
|
2
|
+
let(:initial_path) { refinery.admin_images_path + '?view=list' }
|
|
3
|
+
let(:img_selector) { '' }
|
|
4
|
+
let(:alt_selector) { 'span.alt' }
|
|
5
|
+
let(:title_selector) { 'a.edit_link' }
|
|
6
|
+
let(:image_title) { [index_item_selector, title_selector].join(' ') }
|
|
7
|
+
let(:view_selector) {'#image_index.list'}
|
|
8
|
+
|
|
9
|
+
let(:filename_selector) { '.filename' }
|
|
10
|
+
let(:filename) { [index_item_selector, filename_selector ].join(' ') }
|
|
11
|
+
let(:alt_view) {'grid'}
|
|
12
|
+
end
|
|
@@ -16,7 +16,7 @@ shared_examples_for 'deletes an image' do
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "removes an image" do
|
|
19
|
-
expect
|
|
19
|
+
expect { deleting_an_image.call }.to change(Refinery::Image, :count).by(-1)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it 'says the image has been removed' do
|
|
@@ -25,7 +25,7 @@ shared_examples 'translates an image' do
|
|
|
25
25
|
click_button "Save"
|
|
26
26
|
|
|
27
27
|
expect(page).to have_content("'Titre de la première image' was successfully updated.")
|
|
28
|
-
expect(Refinery::Image.
|
|
28
|
+
expect(Refinery::Image::Translation.count).to eq(1)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -21,16 +21,19 @@ shared_examples 'uploads images' do
|
|
|
21
21
|
context 'when the image type is acceptable' do
|
|
22
22
|
let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/image-with-dashes.jpg")}
|
|
23
23
|
it 'the image is uploaded', :js => true do
|
|
24
|
-
expect
|
|
24
|
+
expect { uploading_an_image.call }.to change(Refinery::Image, :count).by(1)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
context 'when the image type is not acceptable' do
|
|
29
29
|
let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")}
|
|
30
30
|
it 'the image is rejected', :js => true do
|
|
31
|
-
expect
|
|
31
|
+
expect { uploading_an_image.call }.to_not change(Refinery::Image, :count)
|
|
32
32
|
page.within_frame(dialog_frame_id) do
|
|
33
|
-
expect(page).to have_content(::I18n.t('incorrect_format',
|
|
33
|
+
expect(page).to have_content(::I18n.t('incorrect_format',
|
|
34
|
+
:scope => 'activerecord.errors.models.refinery/image',
|
|
35
|
+
actual: 'application/pdf',
|
|
36
|
+
valid_types: 'image/jpeg, image/png, image/gif or image/tiff'))
|
|
34
37
|
end
|
|
35
38
|
end
|
|
36
39
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
module Refinery
|
|
4
|
-
describe "the Admin Images Tab", type: :
|
|
4
|
+
describe "the Admin Images Tab", type: :system do
|
|
5
5
|
refinery_login
|
|
6
6
|
include_context 'admin images tab'
|
|
7
7
|
|
|
@@ -13,6 +13,18 @@ module Refinery
|
|
|
13
13
|
expect(page).to have_content(::I18n.t('no_images_yet', scope: 'refinery.admin.images.records'))
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
it 'shows flash notice after successful upload' do
|
|
17
|
+
visit refinery.new_admin_image_path
|
|
18
|
+
|
|
19
|
+
attach_file 'image_image', Refinery.roots('refinery/images').join("spec/fixtures/beach.jpeg")
|
|
20
|
+
fill_in 'image_image_title', with: 'Beach Photo'
|
|
21
|
+
fill_in 'image_image_alt', with: 'A beach'
|
|
22
|
+
click_button 'Save'
|
|
23
|
+
|
|
24
|
+
expect(page).to have_content("'Beach Photo' was successfully added.")
|
|
25
|
+
expect(page).to have_current_path(refinery.admin_images_path)
|
|
26
|
+
end
|
|
27
|
+
|
|
16
28
|
it_has_behaviour 'uploads images'
|
|
17
29
|
end
|
|
18
30
|
|