refinerycms-images 2.0.10 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/refinery/admin/images_controller.rb +40 -6
  3. data/app/helpers/refinery/admin/images_helper.rb +2 -2
  4. data/app/models/refinery/image.rb +40 -21
  5. data/app/views/refinery/admin/images/_existing_image.html.erb +1 -1
  6. data/app/views/refinery/admin/images/_form.html.erb +1 -1
  7. data/app/views/refinery/admin/images/_grid_view.html.erb +2 -2
  8. data/app/views/refinery/admin/images/_list_view_image.html.erb +1 -1
  9. data/app/views/refinery/admin/images/_records.html.erb +4 -6
  10. data/app/views/refinery/admin/images/insert.html.erb +6 -1
  11. data/config/locales/bg.yml +1 -2
  12. data/config/locales/cs.yml +1 -2
  13. data/config/locales/da.yml +1 -2
  14. data/config/locales/de.yml +1 -2
  15. data/config/locales/el.yml +1 -2
  16. data/config/locales/en.yml +2 -2
  17. data/config/locales/es.yml +1 -2
  18. data/config/locales/fi.yml +1 -2
  19. data/config/locales/fr.yml +1 -2
  20. data/config/locales/hu.yml +44 -0
  21. data/config/locales/it.yml +1 -1
  22. data/config/locales/ja.yml +1 -2
  23. data/config/locales/ko.yml +1 -2
  24. data/config/locales/lt.yml +1 -2
  25. data/config/locales/lv.yml +1 -2
  26. data/config/locales/nb.yml +1 -2
  27. data/config/locales/nl.yml +15 -15
  28. data/config/locales/pl.yml +1 -2
  29. data/config/locales/pt-BR.yml +1 -2
  30. data/config/locales/pt.yml +44 -0
  31. data/config/locales/rs.yml +1 -2
  32. data/config/locales/ru.yml +1 -2
  33. data/config/locales/sk.yml +2 -3
  34. data/config/locales/sl.yml +1 -2
  35. data/config/locales/sv.yml +1 -2
  36. data/config/locales/tr.yml +44 -0
  37. data/config/locales/uk.yml +44 -0
  38. data/config/locales/vi.yml +1 -2
  39. data/config/locales/zh-CN.yml +3 -4
  40. data/config/locales/zh-TW.yml +1 -2
  41. data/config/routes.rb +3 -3
  42. data/db/migrate/20120625093918_remove_image_ext_from_refinery_images.rb +9 -0
  43. data/lib/generators/refinery/images/templates/config/initializers/refinery/images.rb.erb +7 -1
  44. data/lib/refinery/images/configuration.rb +22 -8
  45. data/lib/refinery/images/dragonfly.rb +13 -10
  46. data/lib/refinery/images/engine.rb +1 -2
  47. data/lib/refinery/images/validators.rb +1 -0
  48. data/lib/refinery/images/validators/image_update_validator.rb +17 -0
  49. data/refinerycms-images.gemspec +2 -4
  50. data/spec/factories/image.rb +4 -0
  51. data/spec/{requests → features}/refinery/admin/images_spec.rb +65 -7
  52. data/spec/fixtures/beach-alternate.jpeg +0 -0
  53. data/spec/fixtures/cape-town-tide-table.pdf +0 -0
  54. data/spec/models/refinery/image_spec.rb +70 -40
  55. metadata +18 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 726ab0771b2270af874c268a53a9260e6e67002a
4
- data.tar.gz: 75cebc30239e823057e512aec2a5a014b1db7899
3
+ metadata.gz: c249ed2d31ca6c37f8eb87228a4465adf9f75602
4
+ data.tar.gz: d84f1c7b9a53e9f191ced15928ef40a7804740d9
5
5
  SHA512:
6
- metadata.gz: e296d332629b64ce731b35d1dbad3a41159b7a88110c1a684cf1d2871b6b2a82bf9901b10782253456ddcbde32f3f7df98e27ea73dd031fc3f1337a03850eab1
7
- data.tar.gz: 83c4947b02ba3bc9033ea12e287b60371930f580aa4e90482d691033442678ad52d53121e6dbc39b8a3af2e85063118a1357c823571579dde5a99b20b5c3a6b5
6
+ metadata.gz: 5a895254472271b2ae02268523d879ad0fc6596ae1489a5522955ebaed4a8cdfc355766164d0bcf0eed26a9c6fe5fcf3e34a6dd602608a208adef0246b214a64
7
+ data.tar.gz: db92a5a44f577ed56cb7a5c0948731ce1077780442660e4261740304d75b444681d64d50fec6a7a1ffc74ab83606943decf1650d92c3856e6da8ff4c8d38b4ec
@@ -29,7 +29,7 @@ module Refinery
29
29
  extra_condition[1] = nil if extra_condition[1] == "nil"
30
30
  end
31
31
 
32
- find_all_images(({extra_condition[0].to_sym => extra_condition[1]} if extra_condition.present?))
32
+ find_all_images(({extra_condition[0] => extra_condition[1]} if extra_condition.present?))
33
33
  search_all_images if searching?
34
34
 
35
35
  paginate_images
@@ -70,8 +70,45 @@ module Refinery
70
70
  if @images.all?(&:valid?)
71
71
  @image_id = @image.id if @image.persisted?
72
72
  @image = nil
73
+ end
74
+
75
+ self.insert
76
+ end
77
+ end
73
78
 
74
- self.insert
79
+ def update
80
+ attributes_before_assignment = @image.attributes
81
+ @image.attributes = params[:image]
82
+ if @image.valid? && @image.save
83
+ flash.notice = t(
84
+ 'refinery.crudify.updated',
85
+ :what => "'#{@image.title}'"
86
+ )
87
+
88
+ unless from_dialog?
89
+ unless params[:continue_editing] =~ /true|on|1/
90
+ redirect_back_or_default refinery.admin_images_path
91
+ else
92
+ unless request.xhr?
93
+ redirect_to :back
94
+ else
95
+ render :partial => '/refinery/message'
96
+ end
97
+ end
98
+ else
99
+ self.index
100
+ @dialog_successful = true
101
+ render :index
102
+ end
103
+ else
104
+ @thumbnail = Image.find params[:id]
105
+ unless request.xhr?
106
+ render :action => 'edit'
107
+ else
108
+ render :partial => '/refinery/admin/error_messages', :locals => {
109
+ :object => @image,
110
+ :include_object_name => true
111
+ }
75
112
  end
76
113
  end
77
114
  end
@@ -84,6 +121,7 @@ module Refinery
84
121
  @update_image = params[:update_image]
85
122
  @thumbnail = params[:thumbnail]
86
123
  @callback = params[:callback]
124
+ @multiple = params[:multiple]
87
125
  @conditions = params[:conditions]
88
126
  end
89
127
 
@@ -101,10 +139,6 @@ module Refinery
101
139
  super unless action_name == 'insert'
102
140
  end
103
141
 
104
- def store_current_location!
105
- super unless action_name == 'insert' or from_dialog?
106
- end
107
-
108
142
  end
109
143
  end
110
144
  end
@@ -10,11 +10,11 @@ module Refinery
10
10
  def thumbnail_urls(image)
11
11
  thumbnail_urls = {
12
12
  :"data-original" => asset_paths.compute_public_path(image.url, ''),
13
- :"data-grid" => asset_paths.compute_public_path(image.thumbnail('135x135#c').url, '')
13
+ :"data-grid" => asset_paths.compute_public_path(image.thumbnail(:geometry => '135x135#c').url, '')
14
14
  }
15
15
 
16
16
  Refinery::Images.user_image_sizes.sort_by{|key,geometry| geometry}.each do |size, pixels|
17
- thumbnail_urls[:"data-#{size.to_s.parameterize}"] = asset_paths.compute_public_path(image.thumbnail(pixels).url, '')
17
+ thumbnail_urls[:"data-#{size.to_s.parameterize}"] = asset_paths.compute_public_path(image.thumbnail(:geometry => pixels).url, '')
18
18
  end
19
19
 
20
20
  thumbnail_urls
@@ -10,12 +10,12 @@ module Refinery
10
10
 
11
11
  validates :image, :presence => true
12
12
  validates_with ImageSizeValidator
13
- validates_property :mime_type, :of => :image, :in => ::Refinery::Images.whitelisted_mime_types,
13
+ validates_with ImageUpdateValidator, :on => :update
14
+ validates_property :mime_type,
15
+ :of => :image,
16
+ :in => ::Refinery::Images.whitelisted_mime_types,
14
17
  :message => :incorrect_format
15
18
 
16
- # Docs for acts_as_indexed http://github.com/dougal/acts_as_indexed
17
- acts_as_indexed :fields => [:title]
18
-
19
19
  # allows Mass-Assignment
20
20
  attr_accessible :id, :image, :image_size
21
21
 
@@ -36,35 +36,44 @@ module Refinery
36
36
  end
37
37
  end
38
38
 
39
- # Get a thumbnail job object given a geometry.
40
- def thumbnail(geometry = nil)
41
- if geometry.is_a?(Symbol) and Refinery::Images.user_image_sizes.keys.include?(geometry)
42
- geometry = Refinery::Images.user_image_sizes[geometry]
39
+ # Get a thumbnail job object given a geometry and whether to strip image profiles and comments.
40
+ def thumbnail(options = {})
41
+ if options.is_a?(String) || options.is_a?(Symbol)
42
+ Refinery.deprecate 'Refinery::Image#thumbnail(geometry)',
43
+ :when => '2.2',
44
+ :replacement => 'Refinery::Image#thumbnail(:geometry => value)'
45
+ options = { :geometry => options }
43
46
  end
44
47
 
45
- if geometry.present? && !geometry.is_a?(Symbol)
46
- image.thumb(geometry)
47
- else
48
- image
49
- end
48
+ options = { :geometry => :no_geometry, :strip => true }.merge(options)
49
+ geometry = convert_to_geometry(options[:geometry])
50
+ thumbnail = image
51
+ thumbnail = thumbnail.thumb(geometry) unless geometry.is_a?(Symbol)
52
+ thumbnail = thumbnail.strip if options[:strip]
53
+ thumbnail
50
54
  end
51
55
 
52
56
  # Intelligently works out dimensions for a thumbnail of this image based on the Dragonfly geometry string.
53
57
  def thumbnail_dimensions(geometry)
54
- geometry = geometry.to_s
58
+ geometry = if geometry.is_a?(Symbol) && Refinery::Images.user_image_sizes.keys.include?(geometry)
59
+ Refinery::Images.user_image_sizes[geometry]
60
+ else
61
+ geometry.to_s
62
+ end
63
+
55
64
  width = original_width = self.image_width.to_f
56
65
  height = original_height = self.image_height.to_f
57
66
  geometry_width, geometry_height = geometry.split(%r{\#{1,2}|\+|>|!|x}im)[0..1].map(&:to_f)
58
- if (original_width * original_height > 0) && geometry =~ ::Dragonfly::ImageMagick::Processor::THUMB_GEOMETRY
59
- if geometry =~ ::Dragonfly::ImageMagick::Processor::RESIZE_GEOMETRY
60
- if geometry !~ %r{\d+x\d+>} || (geometry =~ %r{\d+x\d+>} && (width > geometry_width.to_f || height > geometry_height.to_f))
67
+ if (original_width * original_height > 0) && ::Dragonfly::ImageMagick::Processor::THUMB_GEOMETRY === geometry
68
+ if ::Dragonfly::ImageMagick::Processor::RESIZE_GEOMETRY === geometry
69
+ if geometry !~ %r{\d+x\d+>} || (%r{\d+x\d+>} === geometry && (width > geometry_width.to_f || height > geometry_height.to_f))
61
70
  # Try scaling with width factor first. (wf = width factor)
62
- wf_width = (original_width * (geometry_width / width)).ceil
63
- wf_height = (original_height * (geometry_width / width)).ceil
71
+ wf_width = (original_width * geometry_width / width).round
72
+ wf_height = (original_height * geometry_width / width).round
64
73
 
65
74
  # Scale with height factor (hf = height factor)
66
- hf_width = (original_width * (geometry_height / height)).ceil
67
- hf_height = (original_height * (geometry_height / height)).ceil
75
+ hf_width = (original_width * geometry_height / height).round
76
+ hf_height = (original_height * geometry_height / height).round
68
77
 
69
78
  # Take the highest value that doesn't exceed either axis limit.
70
79
  use_wf = wf_width <= geometry_width && wf_height <= geometry_height
@@ -96,5 +105,15 @@ module Refinery
96
105
  CGI::unescape(image_name.to_s).gsub(/\.\w+$/, '').titleize
97
106
  end
98
107
 
108
+ private
109
+
110
+ def convert_to_geometry(geometry)
111
+ if geometry.is_a?(Symbol) && Refinery::Images.user_image_sizes.keys.include?(geometry)
112
+ Refinery::Images.user_image_sizes[geometry]
113
+ else
114
+ geometry
115
+ end
116
+ end
117
+
99
118
  end
100
119
  end
@@ -32,7 +32,7 @@
32
32
  </p>
33
33
  <ul>
34
34
  <%
35
- Refinery::Images.user_image_sizes.sort_by { |key, geometry| geometry }.each_with_index do |(size, pixels), index|
35
+ Refinery::Images.user_image_sizes.sort_by { |key, geometry| geometry.to_i }.each_with_index do |(size, pixels), index|
36
36
  safe_pixels = pixels.to_s.gsub(/[<>=]/, '')
37
37
  # (parndt): ' selected' if size.to_s == 'medium' is not very generic, but I
38
38
  # can't think of a decent way of making it so for even sets (e.g. 2,4,6,8,etc image sizes).
@@ -45,6 +45,6 @@
45
45
  <% if action_name =~ /(edit)|(update)/ %>
46
46
  <div id="existing_image">
47
47
  <label><%=t('.current_image') %></label>
48
- <%= image_fu @image, '225x255>', :class => "brown_border" %>
48
+ <%= image_fu @thumbnail || @image, '225x255>', :class => 'brown_border' %>
49
49
  </div>
50
50
  <% end %>
@@ -5,12 +5,12 @@
5
5
  <span class="actions">
6
6
  <%= link_to refinery_icon_tag('eye.png'), image.url,
7
7
  :target => '_blank',
8
- :title => t('.view_live_html') %>
8
+ :title => t('view_live_html', :scope => 'refinery.admin.images') %>
9
9
  <%= link_to refinery_icon_tag('application_edit.png'),
10
10
  refinery.edit_admin_image_path(image),
11
11
  :title => t('edit', :scope => 'refinery.admin.images') %>
12
12
  <%= link_to refinery_icon_tag('delete.png'),
13
- refinery.admin_image_path(image),
13
+ refinery.admin_image_path(image, params.slice(:page)),
14
14
  :class => 'cancel confirm-delete',
15
15
  :title => t('delete', :scope => 'refinery.admin.images'),
16
16
  :data => {
@@ -5,7 +5,7 @@
5
5
  <span class="actions">
6
6
  <%= link_to refinery_icon_tag('eye.png'), list_view_image.url,
7
7
  :target => '_blank',
8
- :title => image_fu(list_view_image, '96x96#c', :size => '96x96') %>
8
+ :title => t('view_live_html', :scope => 'refinery.admin.images') %>
9
9
  <%= link_to refinery_icon_tag('application_edit.png'),
10
10
  refinery.edit_admin_image_path(list_view_image),
11
11
  :title => t('edit', :scope => 'refinery.admin.images') %>
@@ -1,17 +1,15 @@
1
- <% if searching? %>
2
- <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
3
- <% end %>
1
+ <%= render 'refinery/admin/search_header', :url => refinery.admin_images_path %>
4
2
  <div class="pagination_container">
5
3
  <% if @images.any? %>
6
4
  <%= render 'images' %>
7
5
  <% else %>
8
6
  <p>
9
- <% unless searching? %>
7
+ <% if searching? %>
8
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
9
+ <% else %>
10
10
  <strong>
11
11
  <%= t('.no_images_yet') %>
12
12
  </strong>
13
- <% else %>
14
- <%= t('no_results', :scope => 'refinery.admin.search') %>
15
13
  <% end %>
16
14
  </p>
17
15
  <% end %>
@@ -38,7 +38,12 @@
38
38
  <% content_for :javascripts do %>
39
39
  <script>
40
40
  $(document).ready(function(){
41
- image_dialog.init(<%= @callback.present? ? "self.parent.#{@callback}" : "null" %>);
41
+ new ImageDialog({
42
+ callback: <%= @callback.present? ? "self.parent.#{h @callback}" : 'null' %>,
43
+ multiple: <%= @multiple == 'true' %>
44
+ }).create();
45
+
46
+ $('input[type=radio][value=upload_image]:checked').click();
42
47
  });
43
48
  </script>
44
49
  <% end %>
@@ -24,8 +24,7 @@ bg:
24
24
  switch_to: Преглед като %{view_name}
25
25
  list: списък
26
26
  grid: решетка
27
- grid_view:
28
- view_live_html: Преглед на това изображение <br/><em>(ще се отвори в нов прозорец)</em>
27
+ view_live_html: Преглед на това изображение <br/><em>(ще се отвори в нов прозорец)</em>
29
28
  existing_image:
30
29
  button_text: Вмъкване
31
30
  resize_image: Оразмеряване на изображението?
@@ -24,8 +24,7 @@ cs:
24
24
  switch_to: "Přepnout pohled na: %{view_name}"
25
25
  list: seznam
26
26
  grid: tabulka
27
- grid_view:
28
- view_live_html: Zobrazit tento obrázek <br/><em>Otevře se novém okně</em>
27
+ view_live_html: Zobrazit tento obrázek <br/><em>Otevře se novém okně</em>
29
28
  existing_image:
30
29
  button_text: Vložit
31
30
  resize_image: Změnít velikost?
@@ -24,8 +24,7 @@ da:
24
24
  switch_to: Skift til %{view_name}visning
25
25
  list: liste
26
26
  grid: gitter
27
- grid_view:
28
- view_live_html: Vis billede<br/><em>(åbner i nyt vindue)</em>
27
+ view_live_html: Vis billede<br/><em>(åbner i nyt vindue)</em>
29
28
  existing_image:
30
29
  button_text: Indsæt
31
30
  resize_image: Skalér billedet?
@@ -24,8 +24,7 @@ de:
24
24
  switch_to: Zur %{view_name}-Ansicht wechseln
25
25
  list: Listen
26
26
  grid: Gitter
27
- grid_view:
28
- view_live_html: Dieses Bild betrachten <br/><em>Öffnet sich in einem neuen Fenster</em>
27
+ view_live_html: Dieses Bild betrachten <br/><em>Öffnet sich in einem neuen Fenster</em>
29
28
  existing_image:
30
29
  button_text: Einfügen
31
30
  resize_image: Bild in der Größe ändern?
@@ -24,8 +24,7 @@ el:
24
24
  switch_to: Αλλαγή σε %{view_name} view
25
25
  list: λίστα
26
26
  grid: πλέγμα
27
- grid_view:
28
- view_live_html: Δείτε την εικόνα <br/><em>Ανοίγει σε νέο παράθυρο</em>
27
+ view_live_html: Δείτε την εικόνα <br/><em>Ανοίγει σε νέο παράθυρο</em>
29
28
  existing_image:
30
29
  button_text: Εισαγωγή
31
30
  resize_image: Αλλαγή μεγέθους;
@@ -24,8 +24,7 @@ en:
24
24
  switch_to: Switch to %{view_name} view
25
25
  list: list
26
26
  grid: grid
27
- grid_view:
28
- view_live_html: View this image <br/><em>Opens in a new window</em>
27
+ view_live_html: View this image <br/><em>Opens in a new window</em>
29
28
  existing_image:
30
29
  button_text: Insert
31
30
  resize_image: Resize the image?
@@ -42,3 +41,4 @@ en:
42
41
  blank: You must specify an image for upload
43
42
  too_big: Image should be smaller than %{size} bytes in size
44
43
  incorrect_format: 'Your image must be either a JPG, PNG or GIF'
44
+ different_file_name: New image can't have different file name
@@ -25,8 +25,7 @@ es:
25
25
  switch_to: Cambiar a vista %{view_name}
26
26
  list: lista
27
27
  grid: cuadrícula
28
- grid_view:
29
- view_live_html: Ver imagen <br/><em>Abre en ventana nueva</em>
28
+ view_live_html: Ver imagen <br/><em>Abre en ventana nueva</em>
30
29
  existing_image:
31
30
  button_text: Insertar
32
31
  resize_image: ¿Redimensionar la imagen?
@@ -24,8 +24,7 @@ fi:
24
24
  switch_to: "%{view_name}näkymä"
25
25
  list: Lista
26
26
  grid: Ruudukko
27
- grid_view:
28
- view_live_html: Katsele tätä kuvaa <br/><em>Avautuu uudessa ikkunassa</em>
27
+ view_live_html: Katsele tätä kuvaa <br/><em>Avautuu uudessa ikkunassa</em>
29
28
  existing_image:
30
29
  button_text: Lisää
31
30
  resize_image: Suurenna tai pienennä kuvaa?
@@ -24,8 +24,7 @@ fr:
24
24
  switch_to: Afficher sous forme de %{view_name}
25
25
  list: liste
26
26
  grid: grille
27
- grid_view:
28
- view_live_html: "Voir cette image<br/><em>Ouvre une nouvelle fenêtre</em>"
27
+ view_live_html: "Voir cette image<br/><em>Ouvre une nouvelle fenêtre</em>"
29
28
  existing_image:
30
29
  button_text: Insérer
31
30
  resize_image: Redimensionner l'image ?
@@ -0,0 +1,44 @@
1
+ hu:
2
+ refinery:
3
+ plugins:
4
+ refinery_images:
5
+ title: Képek
6
+ description: Képek kezelése
7
+ admin:
8
+ images:
9
+ delete: Kép végleges eltávolítása
10
+ edit: Kép szerkesztése
11
+ form:
12
+ image: Kép
13
+ use_current_image: Jelenlegi kép használata
14
+ or: vagy
15
+ replace_image: " lecserélés a következővel..."
16
+ current_image: Jelenlegi Kép
17
+ maximum_image_size: 'A maximum képméret: %{bytes}.'
18
+ actions:
19
+ create_new_image: Új kép hozzáadása
20
+ records:
21
+ no_images_yet: Még nincsenek képek. Kattints az "Új kép hozzáadása"-ra hogy hozzáadd az első képet.
22
+ index:
23
+ view:
24
+ switch_to: 'Váltás %{view_name} nézetre'
25
+ list: lista
26
+ grid: rács
27
+ view_live_html: Kép megtekintésekor <br/><em>új ablakban nyílik meg</em>
28
+ existing_image:
29
+ button_text: Beszúrás
30
+ resize_image: Kép átméretezése?
31
+ size: Méret
32
+ insert:
33
+ existing_image: Könyvtár
34
+ new_image: Feltölt
35
+ activerecord:
36
+ models:
37
+ refinery/image: kép
38
+ errors:
39
+ models:
40
+ refinery/image:
41
+ blank: Meg kell adnod egy feltöltendő képet
42
+ too_big: A képnek kisebbnek kell lennie mint %{size} bájt
43
+ incorrect_format: 'A kép formátuma csak JPG, PNG vagy GIF lehet'
44
+ different_file_name: Új kép nem lehet más néven
@@ -26,7 +26,7 @@ it:
26
26
  grid: Griglia
27
27
  grid_view:
28
28
  edit: Modifica questa immagine
29
- view_live_html: Visualizza questa immagine <br/><em>Apri in una nuova finestra</em>
29
+ view_live_html: Visualizza questa immagine <br/><em>Apri in una nuova finestra</em>
30
30
  existing_image:
31
31
  button_text: Inserisci
32
32
  resize_image: "Ridimensionare l'immagine?"
@@ -24,8 +24,7 @@ ja:
24
24
  switch_to: '%{view_name}表示に切り替え'
25
25
  list: リスト
26
26
  grid: グリッド
27
- grid_view:
28
- view_live_html: 'この画像を<br/><em>新しいウィンドウで開く</em>'
27
+ view_live_html: 'この画像を<br/><em>新しいウィンドウで開く</em>'
29
28
  existing_image:
30
29
  button_text: 挿入
31
30
  resize_image: サイズ変更