refinerycms-page-resources 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +16 -0
  3. data/Gemfile +69 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/javascripts/refinery/page-image-picker.js.erb +167 -0
  6. data/app/assets/stylesheets/refinery/page-image-picker.css.scss +57 -0
  7. data/app/models/refinery/image_page.rb +13 -0
  8. data/app/views/refinery/admin/pages/tabs/_images.html.erb +7 -0
  9. data/app/views/refinery/admin/pages/tabs/_images_bar.html.erb +9 -0
  10. data/app/views/refinery/admin/pages/tabs/_images_field.html.erb +33 -0
  11. data/config/locales/bg.yml +16 -0
  12. data/config/locales/cs.yml +16 -0
  13. data/config/locales/de.yml +10 -0
  14. data/config/locales/en.yml +16 -0
  15. data/config/locales/fr.yml +16 -0
  16. data/config/locales/nl.yml +11 -0
  17. data/config/locales/pt-BR.yml +16 -0
  18. data/config/locales/ru.yml +11 -0
  19. data/config/locales/sk.yml +16 -0
  20. data/db/migrate/20101014230041_create_page_images.rb +12 -0
  21. data/db/migrate/20101014230042_add_caption_to_image_pages.rb +5 -0
  22. data/db/migrate/20110511215016_translate_page_image_captions.rb +22 -0
  23. data/db/migrate/20110527052435_change_page_to_polymorphic.rb +5 -0
  24. data/lib/generators/refinery/page_images_generator.rb +15 -0
  25. data/lib/generators/refinery/templates/config/initializers/refinery/page_images.rb.erb +3 -0
  26. data/lib/refinery/page_images.rb +22 -0
  27. data/lib/refinery/page_images/configuration.rb +9 -0
  28. data/lib/refinery/page_images/engine.rb +46 -0
  29. data/lib/refinery/page_images/extension.rb +66 -0
  30. data/lib/refinerycms-page-images.rb +1 -0
  31. data/readme.md +62 -0
  32. data/refinerycms-page-resources.gemspec +16 -0
  33. data/script/rails +6 -0
  34. data/spec/factories/page-images.rb +9 -0
  35. data/spec/models/refinery/blog_spec.rb +15 -0
  36. data/spec/models/refinery/page_spec.rb +69 -0
  37. data/spec/requests/attach_page_images_spec.rb +29 -0
  38. data/spec/spec_helper.rb +56 -0
  39. data/spec/support/database_cleaner.rb +17 -0
  40. data/spec/support/devise.rb +8 -0
  41. data/spec/support/refinery.rb +6 -0
  42. data/tasks/rspec.rake +4 -0
  43. metadata +105 -0
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ spec/dummy/
@@ -0,0 +1,16 @@
1
+ before_script:
2
+ - "bundle exec rake refinery:testing:dummy_app > /dev/null"
3
+ script: "bundle exec rspec ./spec"
4
+ notifications:
5
+ email:
6
+ - parndt@gmail.com
7
+ - ugis.ozolss@gmail.com
8
+ env:
9
+ - DB=postgresql
10
+ - DB=mysql
11
+ rvm:
12
+ - 1.8.7
13
+ - 1.9.2
14
+ - 1.9.3
15
+ - rbx
16
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,69 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'refinerycms', :git => 'git://github.com/resolve/refinerycms.git'
6
+
7
+ group :development, :test do
8
+ gem 'refinerycms-testing', :git => 'git://github.com/resolve/refinerycms.git'
9
+ gem 'guard-rspec', '~> 0.6.0'
10
+
11
+ platforms :jruby do
12
+ gem 'activerecord-jdbcsqlite3-adapter'
13
+ gem 'activerecord-jdbcmysql-adapter'
14
+ gem 'activerecord-jdbcpostgresql-adapter'
15
+ gem 'jruby-openssl'
16
+ end
17
+
18
+ unless defined?(JRUBY_VERSION)
19
+ gem 'sqlite3'
20
+ gem 'mysql2'
21
+ gem 'pg'
22
+ end
23
+
24
+ platforms :mswin, :mingw do
25
+ gem 'win32console'
26
+ gem 'rb-fchange', '~> 0.0.5'
27
+ gem 'rb-notifu', '~> 0.0.4'
28
+ end
29
+
30
+ platforms :ruby do
31
+ gem 'spork', '~> 0.9.0.rc'
32
+ gem 'guard-spork'
33
+
34
+ unless ENV['TRAVIS']
35
+ require 'rbconfig'
36
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
37
+ gem 'rb-fsevent', '>= 0.3.9'
38
+ gem 'ruby_gntp'
39
+ end
40
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
41
+ gem 'rb-inotify', '>= 0.5.1'
42
+ gem 'libnotify', '~> 0.1.3'
43
+ gem 'therubyracer', '~> 0.9.9'
44
+ end
45
+ end
46
+ end
47
+
48
+ platforms :jruby do
49
+ unless ENV['TRAVIS']
50
+ require 'rbconfig'
51
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
52
+ gem 'ruby_gntp'
53
+ end
54
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
55
+ gem 'rb-inotify', '>= 0.5.1'
56
+ gem 'libnotify', '~> 0.1.3'
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ # Refinery/rails should pull in the proper versions of these
63
+ group :assets do
64
+ gem 'sass-rails'
65
+ gem 'coffee-rails'
66
+ gem 'uglifier'
67
+ end
68
+
69
+ gem 'jquery-rails'
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ ENGINE_PATH = File.dirname(__FILE__)
9
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
10
+
11
+ if File.exists?(APP_RAKEFILE)
12
+ load 'rails/tasks/engine.rake'
13
+ end
14
+
15
+ require "refinerycms-testing"
16
+ Refinery::Testing::Railtie.load_tasks
17
+ Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
18
+
19
+ load File.expand_path('../tasks/rspec.rake', __FILE__)
@@ -0,0 +1,167 @@
1
+ $(document).ready(function(){
2
+ $('#custom_images_tab a').click(function(){
3
+ if (!(picker = $('#page_image_picker')).data('size-applied')){
4
+ wym_box = $('.page_part:first .wym_box');
5
+ iframe = $('.page_part:first iframe');
6
+ picker.css({
7
+ height: wym_box.height()
8
+ , width: wym_box.width()
9
+ }).data('size-applied', true).corner('tr 5px').corner('bottom 5px').find('.wym_box').css({
10
+ backgroundColor: 'white'
11
+ , height: iframe.height() + $('.page_part:first .wym_area_top').height() - parseInt($('.wym_area_top .label_inline_with_link a').css('lineHeight'))
12
+ , width: iframe.width() - 20
13
+ , 'border-color': iframe.css('border-top-color')
14
+ , 'border-style': iframe.css('border-top-style')
15
+ , 'border-width': iframe.css('border-top-width')
16
+ , padding: '0px 10px 0px 10px'
17
+ });
18
+ }
19
+ });
20
+
21
+ // Webkit browsers don't like the textarea being moved around the DOM,
22
+ // they ignore the new contents. This is fixed below by adding a hidden
23
+ // field that stays in place.
24
+ $('#content #page_images li textarea:hidden').each(function(index) {
25
+ var old_name = $(this).attr('name');
26
+ $(this).attr('data-old-id', $(this).attr('id'));
27
+ $(this).attr('name', 'ignore_me_' + index);
28
+ $(this).attr('id', 'ignore_me_' + index);
29
+
30
+ var hidden = $('<input>')
31
+ .addClass('caption')
32
+ .attr('type', 'hidden')
33
+ .attr('name', old_name)
34
+ .attr('id', $(this).attr('data-old-id'))
35
+ .val($(this).val());
36
+
37
+ $(this).parents('li').first().append(hidden);
38
+ });
39
+
40
+ reset_functionality();
41
+ });
42
+
43
+ reset_functionality = function() {
44
+ WYMeditor.onload_functions.push(function(){
45
+ $('.wym_box').css({'width':null});
46
+ });
47
+
48
+ $("#page_images").sortable({
49
+ 'tolerance': 'pointer'
50
+ , 'placeholder': 'placeholder'
51
+ , 'cursor': 'drag'
52
+ , 'items': 'li'
53
+ , stop: reindex_images
54
+ });
55
+
56
+ $('#content #page_images li:not(.empty)').live('hover', function(e) {
57
+ if (e.type == 'mouseenter' || e.type == 'mouseover') {
58
+ if ((image_actions = $(this).find('.image_actions')).length == 0) {
59
+ image_actions = $("<div class='image_actions'></div>");
60
+ img_delete = $("<img src='/assets/refinery/icons/delete.png' width='16' height='16' />");
61
+ img_delete.appendTo(image_actions);
62
+ img_delete.click(function() {
63
+ $(this).parents('li').first().remove();
64
+ reindex_images();
65
+ });
66
+
67
+ if ($(this).find('textarea.page_caption').length > 0) {
68
+ img_caption = $("<img src='/assets/refinery/icons/user_comment.png' width='16' height='16' class='caption' />");
69
+ img_caption.appendTo(image_actions);
70
+ img_caption.click(open_image_caption);
71
+ } else {
72
+ image_actions.addClass('no_captions');
73
+ }
74
+
75
+ image_actions.appendTo($(this));
76
+ }
77
+
78
+ image_actions.show();
79
+ } else if (e.type == 'mouseleave' || e.type == 'mouseout') {
80
+ $(this).find('.image_actions').hide();
81
+ }
82
+ });
83
+
84
+ reindex_images();
85
+ }
86
+
87
+ image_added = function(image) {
88
+ new_list_item = (current_list_item = $('li.empty')).clone();
89
+ image_id = $(image).attr('id').replace('image_', '');
90
+ current_list_item.find('input:hidden:first').val(image_id);
91
+
92
+ $("<img />").attr({
93
+ title: $(image).attr('title')
94
+ , alt: $(image).attr('alt')
95
+ , src: $(image).attr('data-grid') // use 'grid' size that is built into Refinery CMS (135x135#c).
96
+ }).appendTo(current_list_item);
97
+
98
+ current_list_item.attr('id', 'image_' + image_id).removeClass('empty');
99
+
100
+ new_list_item.appendTo($('#page_images'));
101
+ reset_functionality();
102
+ }
103
+
104
+ open_image_caption = function(e) {
105
+ // move the textarea out of the list item, and then move the textarea back into it when we click done.
106
+ (list_item = $(this).parents('li').first()).addClass('current_caption_list_item');
107
+ textarea = list_item.find('.textarea_wrapper_for_wym > textarea');
108
+
109
+ textarea.after($("<div class='form-actions'><div class='form-actions-left'><a class='button'><%= I18n.t('refinery.js.admin.page_images.done') %></a></div></div>"));
110
+ textarea.parent().dialog({
111
+ title: "<%= I18n.t('refinery.js.admin.page_images.add_caption') %>"
112
+ , modal: true
113
+ , resizable: false
114
+ , autoOpen: true
115
+ , width: 928
116
+ , height: 530
117
+ });
118
+
119
+ $('.ui-dialog:visible .ui-dialog-titlebar-close, .ui-dialog:visible .form-actions a.button')
120
+ .on('click',
121
+ $.proxy(function(e) {
122
+ // update the editor
123
+ $(this).data('wymeditor').update();
124
+ $(this).removeClass('wymeditor')
125
+ .removeClass('active_rotator_wymeditor');
126
+
127
+ $this_parent = $(this).parent();
128
+ $this_parent.appendTo('li.current_caption_list_item').dialog('close').data('dialog', null);
129
+ $this_parent.find('.form-actions').remove();
130
+ $this_parent.find('.wym_box').remove();
131
+ $this_parent.css('height', 'auto');
132
+ $this_parent.removeClass('ui-dialog-content').removeClass('ui-widget-content');
133
+
134
+ $('li.current_caption_list_item').removeClass('current_caption_list_item');
135
+
136
+ $('.ui-dialog, .ui-widget-overlay:visible').remove();
137
+
138
+ $('#' + $(this).attr('data-old-id')).val($(this).val());
139
+ }, textarea)
140
+ );
141
+
142
+ textarea.addClass('wymeditor active_rotator_wymeditor widest').wymeditor(wymeditor_boot_options);
143
+ }
144
+
145
+ reindex_images = function() {
146
+ $('#page_images li textarea:hidden').each(function(i, input){
147
+ // make the image's name consistent with its position.
148
+ parts = $(input).attr('name').split('_');
149
+ parts[2] = ('' + i);
150
+ $(input).attr('name', parts.join('_'));
151
+
152
+ // make the image's id consistent with its position.
153
+ $(input).attr('id', $(input).attr('id').replace(/_\d/, '_' + i));
154
+ $(input).attr('data-old-id', $(input).attr('data-old-id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_' + i));
155
+ });
156
+ $('#page_images li').each(function(i, li){
157
+ $('input:hidden', li).each(function() {
158
+ // make the image's name consistent with its position.
159
+ parts = $(this).attr('name').split(']');
160
+ parts[1] = ('[' + i);
161
+ $(this).attr('name', parts.join(']'));
162
+
163
+ // make the image's id consistent with its position.
164
+ $(this).attr('id', $(this).attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
165
+ });
166
+ });
167
+ }
@@ -0,0 +1,57 @@
1
+ #page_images {
2
+ margin: 0;
3
+ padding: 0;
4
+ width: 280px;
5
+ width: 100%;
6
+ li {
7
+ position: relative;
8
+ list-style: none;
9
+ float: left;
10
+ margin: 10px 20px 20px 0;
11
+ * {
12
+ cursor: move;
13
+ }
14
+ &.odd {
15
+ margin-right: 18px;
16
+ }
17
+ .image_actions {
18
+ background: white;
19
+ position: absolute;
20
+ padding: 3px;
21
+ left: 0;
22
+ top: 0;
23
+ width: 135px;
24
+ * {
25
+ cursor: pointer;
26
+ }
27
+ &.no_captions {
28
+ background: transparent;
29
+ }
30
+ }
31
+ }
32
+ > li .image_actions img.caption {
33
+ position: absolute;
34
+ right: 3px;
35
+ top: 3px;
36
+ }
37
+ }
38
+
39
+ #content {
40
+ ul.ui-sortable li {
41
+ border: 0;
42
+ background: none !important;
43
+ }
44
+ #page_images.ui-sortable li.placeholder {
45
+ width: 135px;
46
+ height: 135px;
47
+ }
48
+ }
49
+
50
+ a#add_image_link {
51
+ margin-top: 0;
52
+ line-height: 29px;
53
+ padding-left: 20px;
54
+ display: inline;
55
+ border-bottom: 0;
56
+ background: image-url('refinery/icons/add.png') no-repeat 0px 6px;
57
+ }
@@ -0,0 +1,13 @@
1
+ module Refinery
2
+ class ImagePage < Refinery::Core::BaseModel
3
+
4
+ belongs_to :image
5
+ belongs_to :page, :polymorphic => true
6
+
7
+ translates :caption if self.respond_to?(:translates)
8
+
9
+ attr_accessible :image_id, :position, :locale
10
+ self.translation_class.send :attr_accessible, :locale
11
+
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ <div class='wym_skin_refinery page_part' id='page_image_picker'>
2
+ <%= render '/refinery/admin/pages/tabs/images_bar', :f => f %>
3
+ <%= render '/refinery/admin/pages/tabs/images_field', :f => f %>
4
+ </div>
5
+
6
+ <% content_for :stylesheets, stylesheet_link_tag('refinery/page-image-picker') %>
7
+ <% content_for :javascripts, javascript_include_tag('refinery/page-image-picker') %>
@@ -0,0 +1,9 @@
1
+ <div class='wym_area_top'>
2
+ <span class='clearfix label_inline_with_link'>
3
+ <%= link_to t('.add'), refinery.insert_admin_images_path({
4
+ :dialog => true, :width => 950, :height => 510,
5
+ :callback => "image_added"
6
+ }),
7
+ :id => "add_image_link" %>
8
+ </span>
9
+ </div>
@@ -0,0 +1,33 @@
1
+ <div class='wym_box field images_field'>
2
+ <ul id='page_images' class='clearfix'>
3
+ <%= f.fields_for :images do |image_form| %>
4
+ <li id='image_<%= image_form.object.id %>'>
5
+ <%= image_form.hidden_field :id %>
6
+ <%= image_fu image_form.object, '135x135#c' %>
7
+ <% index = image_form.object_name.split('[').last.split(']').first.to_i %>
8
+ <%= hidden_field_tag "#{f.object_name.demodulize}[images_attributes][#{index}][image_page_id]", f.object.image_page_id_for_image_index(index) %>
9
+ <% if Refinery::PageImages.captions %>
10
+ <div class='textarea_wrapper_for_wym'>
11
+ <%= text_area_tag "#{f.object_name.demodulize}[images_attributes][#{index}][caption]",
12
+ f.object.caption_for_image_index(index),
13
+ :style => 'display: none',
14
+ :id => "page_captions_#{index}",
15
+ :class => 'page_caption' %>
16
+ </div>
17
+ <% end %>
18
+ </li>
19
+ <% end %>
20
+ <li class='empty'>
21
+ <%= hidden_field_tag "#{f.object_name.demodulize}[images_attributes][#{f.object.images.size}][id]" %>
22
+ <% if Refinery::PageImages.captions %>
23
+ <div class='textarea_wrapper_for_wym'>
24
+ <%= text_area_tag "#{f.object_name.demodulize}[images_attributes][#{f.object.images.size}][caption]",
25
+ '',
26
+ :style => 'display: none',
27
+ :id => "page_captions_#{f.object.images.size}",
28
+ :class => 'page_caption' %>
29
+ </div>
30
+ <% end %>
31
+ </li>
32
+ </ul>
33
+ </div>
@@ -0,0 +1,16 @@
1
+ bg:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Изображения на страница
6
+ description: Чрез добавката "Изображения на страница" имате възможност да свържите едно или повече изображения с всяка страница в Refinery. Така лесно ще можете да създавате опростени галерии с изображения, които се отварят в изкачащ прозорец като при lightbox.
7
+ js:
8
+ admin:
9
+ page_images:
10
+ add_caption: Добавяне на заглавие
11
+ done: Готово
12
+ admin:
13
+ pages:
14
+ tabs:
15
+ images_bar:
16
+ add: Добавяне на изображение
@@ -0,0 +1,16 @@
1
+ cs:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Obrázky stránek
6
+ description: Obrázky stránek vám dovoli připojit jeden či více obrázků ke stránce v Refinery. Umožní tak jednoduše vytvářet například galerie s lightboxem na frontendu.
7
+ js:
8
+ admin:
9
+ page_images:
10
+ add_caption: Přidat titulek
11
+ done: Hotovo
12
+ admin:
13
+ pages:
14
+ tabs:
15
+ images_bar:
16
+ add: Přidat obrázek
@@ -0,0 +1,10 @@
1
+ de:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Das Seitenbilder-Plugin erlaubt dir ein oder mehrere Bilder einer Seite zuzuordnen. Damit ist es möglich Bildergalerien in der Frontendansicht darzustellen.
6
+ admin:
7
+ pages:
8
+ tabs:
9
+ images_bar:
10
+ add: Bild hinzufügen
@@ -0,0 +1,16 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Page Images
6
+ description: Page Images allows you to relate one or more images to any page in Refinery which makes it really easy for you to create simple image galleries with lightbox style popups on the front end page views.
7
+ js:
8
+ admin:
9
+ page_images:
10
+ add_caption: Add Caption
11
+ done: Done
12
+ admin:
13
+ pages:
14
+ tabs:
15
+ images_bar:
16
+ add: Add Image
@@ -0,0 +1,16 @@
1
+ fr:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Page Images
6
+ description: "Page Images vous permet de lier une ou plusieurs images à n'importe quelle page dans Refinery, cela vous permet de créer très facilement des galeries d'images qui peuvent s'afficher dans une lightbox ou popups pour le front end"
7
+ js:
8
+ admin:
9
+ page_images:
10
+ add_caption: Ajouter une légende
11
+ done: Terminé
12
+ admin:
13
+ pages:
14
+ tabs:
15
+ images_bar:
16
+ add: Ajouter une image
@@ -0,0 +1,11 @@
1
+ nl:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Pagina Afbeeldingen
6
+ description: Pagina Afbeeldingen stelt u in staat op afbeeldingen te koppelen aan een specifieke pagina.
7
+ admin:
8
+ pages:
9
+ tabs:
10
+ images_bar:
11
+ add: Afbeelding toevoegen.
@@ -0,0 +1,16 @@
1
+ pt-BR:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Imagens da Página
6
+ description: Imagens da Página te permite relacionar uma ou mais imagens a qualquer página no Refinery, tornando muito simples a criação de galerias de imagem no front end com popus no estilo lightbox.
7
+ js:
8
+ admin:
9
+ page_images:
10
+ add_caption: Adicionar Legenda
11
+ done: Feito
12
+ admin:
13
+ pages:
14
+ tabs:
15
+ images_bar:
16
+ add: Adicionar Imagem
@@ -0,0 +1,11 @@
1
+ ru:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Изображения страницы
6
+ description: Плагин работы с изображениями страницы "Page Images" позволяет связывать одно или несколько изображений с любой страницей в Refinery. С помощью плагина можно с легкостью создавать простые галереи изображений с поддержкой всплывающих полноразмерных изображений в стиле lightbox.
7
+ admin:
8
+ pages:
9
+ tabs:
10
+ images_bar:
11
+ add: Добавить
@@ -0,0 +1,16 @@
1
+ sk:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ title: Obrázky stránok
6
+ description: Obrázky stránok vám umožnia pridať jeden alebo viac obrázkov k stránke v Refinery. Umožnia vám tak jednoducho vytvárať napríklad galérie v spojení s lightboxom.
7
+ js:
8
+ admin:
9
+ page_images:
10
+ add_caption: Pridať titulok
11
+ done: Hotovo
12
+ admin:
13
+ pages:
14
+ tabs:
15
+ images_bar:
16
+ add: Pridať obrázok
@@ -0,0 +1,12 @@
1
+ class CreatePageImages < ActiveRecord::Migration
2
+ def change
3
+ create_table Refinery::ImagePage.table_name, :id => false do |t|
4
+ t.integer :image_id
5
+ t.integer :page_id
6
+ t.integer :position
7
+ end
8
+
9
+ add_index Refinery::ImagePage.table_name, :image_id
10
+ add_index Refinery::ImagePage.table_name, :page_id
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddCaptionToImagePages < ActiveRecord::Migration
2
+ def change
3
+ add_column Refinery::ImagePage.table_name, :caption, :text
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ class TranslatePageImageCaptions < ActiveRecord::Migration
2
+ def up
3
+ add_column Refinery::ImagePage.table_name, :id, :primary_key
4
+
5
+ Refinery::ImagePage.reset_column_information
6
+ unless defined?(Refinery::ImagePage::Translation) && Refinery::ImagePage::Translation.table_exists?
7
+ Refinery::ImagePage.create_translation_table!({
8
+ :caption => :text
9
+ }, {
10
+ :migrate_data => true
11
+ })
12
+ end
13
+ end
14
+
15
+ def down
16
+ Refinery::ImagePage.reset_column_information
17
+
18
+ Refinery::ImagePage.drop_translation_table! :migrate_data => true
19
+
20
+ remove_column Refinery::ImagePage.table_name, :id
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ class ChangePageToPolymorphic < ActiveRecord::Migration
2
+ def change
3
+ add_column Refinery::ImagePage.table_name, :page_type, :string, :default => "page"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Refinery
2
+ class PageImagesGenerator < Rails::Generators::Base
3
+
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def rake_db
7
+ rake("refinery_page_images:install:migrations")
8
+ end
9
+
10
+ def generate_page_images_initializer
11
+ template "config/initializers/refinery/page_images.rb.erb", File.join(destination_root, "config", "initializers", "refinery", "page_images.rb")
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ Refinery::PageImages.configure do |config|
2
+ # config.captions = <%= Refinery::PageImages.captions.inspect %>
3
+ end
@@ -0,0 +1,22 @@
1
+ require 'refinerycms-core'
2
+
3
+ module Refinery
4
+ autoload :PageImagesGenerator, 'generators/refinery/page_images_generator'
5
+
6
+ module PageImages
7
+
8
+ class << self
9
+ def root
10
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
11
+ end
12
+
13
+ def factory_paths
14
+ @factory_paths ||= [ root.join('spec', 'factories').to_s ]
15
+ end
16
+ end
17
+
18
+ require 'refinery/page_images/configuration'
19
+ require 'refinery/page_images/engine'
20
+ require 'refinery/page_images/extension'
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ module Refinery
2
+ module PageImages
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :captions
6
+
7
+ self.captions = false
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ module Refinery
2
+ module PageImages
3
+ class Engine < Rails::Engine
4
+ include Refinery::Engine
5
+
6
+ isolate_namespace Refinery
7
+
8
+ engine_name :refinery_page_images
9
+
10
+ def self.register(tab)
11
+ tab.name = "images"
12
+ tab.partial = "/refinery/admin/pages/tabs/images"
13
+ end
14
+
15
+ initializer "register refinery_page_images plugin" do
16
+ Refinery::Plugin.register do |plugin|
17
+ plugin.name = "page_images"
18
+ plugin.hide_from_menu = true
19
+ end
20
+ end
21
+
22
+ config.to_prepare do
23
+ require 'refinerycms-pages'
24
+ Refinery::Page.send :has_many_page_images
25
+ Refinery::Blog::Post.send :has_many_page_images if defined?(::Refinery::Blog)
26
+ Refinery::Image.module_eval do
27
+ has_many :image_pages, :dependent => :destroy
28
+ end
29
+ end
30
+
31
+ config.after_initialize do
32
+ Refinery::Pages::Tab.register do |tab|
33
+ register tab
34
+ end
35
+
36
+ if defined?(Refinery::Blog::Tab)
37
+ Refinery::Blog::Tab.register do |tab|
38
+ register tab
39
+ end
40
+ end
41
+
42
+ Refinery.register_engine(Refinery::PageImages)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ module Refinery
2
+ module PageImages
3
+ module Extension
4
+ def has_many_page_images
5
+ has_many :image_pages, :as => :page, :order => 'position ASC'
6
+ has_many :images, :through => :image_pages, :order => 'position ASC'
7
+ # accepts_nested_attributes_for MUST come before def images_attributes=
8
+ # this is because images_attributes= overrides accepts_nested_attributes_for.
9
+
10
+ accepts_nested_attributes_for :images, :allow_destroy => false
11
+
12
+ # need to do it this way because of the way accepts_nested_attributes_for
13
+ # deletes an already defined images_attributes
14
+ module_eval do
15
+ def images_attributes=(data)
16
+ ids_to_keep = data.map{|i, d| d['image_page_id']}.compact
17
+
18
+ image_pages_to_delete = if ids_to_keep.empty?
19
+ self.image_pages
20
+ else
21
+ self.image_pages.where(
22
+ Refinery::ImagePage.arel_table[:id].not_in(ids_to_keep)
23
+ )
24
+ end
25
+
26
+ image_pages_to_delete.destroy_all
27
+
28
+ data.each do |i, image_data|
29
+ image_page_id, image_id, caption =
30
+ image_data.values_at('image_page_id', 'id', 'caption')
31
+
32
+ next if image_id.blank?
33
+
34
+ image_page = if image_page_id.present?
35
+ self.image_pages.find(image_page_id)
36
+ else
37
+ self.image_pages.build(:image_id => image_id)
38
+ end
39
+
40
+ image_page.position = i
41
+ image_page.caption = caption if Refinery::PageImages.captions
42
+ image_page.save
43
+ end
44
+ end
45
+ end
46
+
47
+ include Refinery::PageImages::Extension::InstanceMethods
48
+
49
+ attr_accessible :images_attributes
50
+ end
51
+
52
+ module InstanceMethods
53
+
54
+ def caption_for_image_index(index)
55
+ self.image_pages[index].try(:caption).presence || ""
56
+ end
57
+
58
+ def image_page_id_for_image_index(index)
59
+ self.image_pages[index].try(:id)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ ActiveRecord::Base.send(:extend, Refinery::PageImages::Extension)
@@ -0,0 +1 @@
1
+ require 'refinery/page_images'
@@ -0,0 +1,62 @@
1
+ # Page Images Engine for Refinery CMS
2
+
3
+ ## About
4
+
5
+ Page Images allows you to relate one or more images to any page in Refinery which makes it really easy for you to create simple image galleries with lightbox style popups on the front end page views.
6
+
7
+ ## Requirements
8
+
9
+ * refinerycms >= 2.0.0
10
+
11
+ ## Features
12
+
13
+ * Ability to select one or more images from the image picker and relate them to a page
14
+ * Reordering support, simply drag into order
15
+ * Optionally include captions with each image.
16
+
17
+ ## Install
18
+
19
+ Add this line to your applications `Gemfile`
20
+
21
+ ```ruby
22
+ gem 'refinerycms-page-images', '~> 2.0.0'
23
+ ```
24
+
25
+ Next run
26
+
27
+ ```bash
28
+ bundle install
29
+ rails generate refinery:page_images
30
+ rake db:migrate
31
+ ```
32
+
33
+ Now when you start up your Refinery application, edit a page and there should be a new "Images" tab.
34
+
35
+ ## Enable Captions
36
+
37
+ You can enable captions using an initializer containing the following configuration:
38
+
39
+ ```ruby
40
+ Refinery::PageImages.captions = true
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ `app/views/refinery/pages/show.html.erb`
46
+
47
+ ```erb
48
+ <% content_for :body_content_right do %>
49
+ <ul id='gallery'>
50
+ <% @page.images.each do |i| %>
51
+ <li>
52
+ <%= link_to image_tag(i.thumbnail("200x200#c").url), i.thumbnail("900x600").url %>
53
+ </li>
54
+ <% end %>
55
+ </ul>
56
+ <% end %>
57
+ <%= render :partial => "/refinery/content_page" %>
58
+ ```
59
+
60
+ ## Screenshot
61
+
62
+ ![Refinery CMS Page Images Screenshot](http://refinerycms.com/system/images/0000/1736/refinerycms-page-images.png)
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{refinerycms-page-resources}
3
+ s.version = %q{0.0.1}
4
+ s.description = %q{Page Resources Engine for Refinery CMS}
5
+ s.date = Date.today.strftime("%Y-%m-%d")
6
+ s.summary = %q{Page Resources Engine for Refinery CMS}
7
+ s.email = %q{stas.ladonenko@gmail.com}
8
+ s.homepage = %q{http://github.com/stasl/refinerycms-page-resources}
9
+ s.authors = ['Stas Ladonenko']
10
+ s.require_paths = %w(lib)
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ s.test_files = `git ls-files -- spec/*`.split("\n")
14
+
15
+ s.add_dependency 'refinerycms-pages', '~> 2.1.0.dev'
16
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ #!/usr/bin/env ruby
3
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
4
+
5
+ ENGINE_PATH = File.expand_path('../..', __FILE__)
6
+ load File.expand_path('../../spec/dummy/script/rails', __FILE__)
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :page_with_image, :parent => :page do
3
+ after_create { |p| p.images << Factory(:image) }
4
+ end
5
+
6
+ factory :blog_post_with_image, :parent => :blog_post do
7
+ after_create { |b| b.images << Factory(:image) }
8
+ end if defined? Refinery::Blog::Post
9
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ describe BlogPost do
5
+ it "should not have images" do
6
+ blog = Factory(:blog_post)
7
+ blog.images.count.should == 0
8
+ end
9
+
10
+ it "should have images" do
11
+ blog = Factory(:blog_post_with_image)
12
+ blog.images.count.should == 1
13
+ end
14
+ end
15
+ end if defined?(Refinery::Blog::Post)
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ describe Page do
5
+ it "can have images added" do
6
+ page = Factory(:page)
7
+ page.images.count.should eq(0)
8
+
9
+ page.images << Factory(:image)
10
+ page.images.count.should eq(1)
11
+ end
12
+
13
+ describe "#images_attributes=" do
14
+ it "adds images" do
15
+ page = Factory(:page)
16
+ image = Factory(:image)
17
+
18
+ page.images.count.should == 0
19
+ page.update_attributes({:images_attributes => {"0" => {"id" => image.id}}})
20
+
21
+ page.images.count.should == 1
22
+ end
23
+
24
+ it "deletes specific images" do
25
+ page = Factory(:page)
26
+ images = [Factory(:image), Factory(:image)]
27
+ page.images = images
28
+
29
+ page.update_attributes(:images_attributes => {
30
+ "0" => {
31
+ "id" => images.first.id.to_s,
32
+ "image_page_id" => page.image_pages.first.id,
33
+ },
34
+ })
35
+
36
+ page.images.should eq([images.first])
37
+ end
38
+
39
+ it "deletes all images" do
40
+ page = Factory(:page)
41
+ images = [Factory(:image), Factory(:image)]
42
+ page.images = images
43
+
44
+ page.update_attributes(:images_attributes => {"0" => {"id"=>""}})
45
+
46
+ page.images.should be_empty
47
+ end
48
+
49
+ it "reorders images" do
50
+ page = Factory(:page)
51
+ images = [Factory(:image), Factory(:image)]
52
+ page.images = images
53
+
54
+ page.update_attributes(:images_attributes => {
55
+ "0" => {
56
+ "id" => images.second.id,
57
+ "image_page_id" => page.image_pages.second.id,
58
+ },
59
+ "1" => {
60
+ "id" => images.first.id,
61
+ "image_page_id" => page.image_pages.first.id,
62
+ },
63
+ })
64
+
65
+ page.images.should eq([images.second, images.first])
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe "attach page images" do
4
+ login_refinery_user
5
+
6
+ before(:each) do
7
+ Factory(:page)
8
+
9
+ visit refinery.admin_pages_path
10
+
11
+ click_link "Edit this page"
12
+ end
13
+
14
+ it "shows images tab" do
15
+ within "#custom_images_tab" do
16
+ page.should have_content("Images")
17
+ end
18
+ end
19
+
20
+ # This spec actually is broken in a way because Add Image link would
21
+ # be visible to capybara even if we don't click on Images tab.
22
+ it "shows add image link" do
23
+ within "#custom_images_tab" do
24
+ click_link "Images"
25
+ end
26
+
27
+ page.should have_content("Add Image")
28
+ end
29
+ end
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+
3
+ def setup_environment
4
+ # Configure Rails Environment
5
+ ENV["RAILS_ENV"] ||= 'test'
6
+
7
+ require File.expand_path("../dummy/config/environment", __FILE__)
8
+
9
+ require 'rspec/rails'
10
+ require 'capybara/rspec'
11
+ require 'factory_girl_rails'
12
+
13
+ Rails.backtrace_cleaner.remove_silencers!
14
+
15
+ RSpec.configure do |config|
16
+ config.mock_with :rspec
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.filter_run :focus => true
19
+ config.run_all_when_everything_filtered = true
20
+ end
21
+
22
+ # set javascript driver for capybara
23
+ Capybara.javascript_driver = :selenium
24
+ end
25
+
26
+ def each_run
27
+ ActiveSupport::Dependencies.clear
28
+
29
+ FactoryGirl.reload
30
+
31
+ # Requires supporting files with custom matchers and macros, etc,
32
+ # in ./support/ and its subdirectories including factories.
33
+ ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
34
+ Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
35
+ }.flatten.sort.each do |support_file|
36
+ require support_file
37
+ end
38
+ end
39
+
40
+ # If spork is available in the Gemfile it'll be used but we don't force it.
41
+ unless (begin; require 'spork'; rescue LoadError; nil end).nil?
42
+ Spork.prefork do
43
+ # Loading more in this block will cause your tests to run faster. However,
44
+ # if you change any configuration or code from libraries loaded here, you'll
45
+ # need to restart spork for it take effect.
46
+ setup_environment
47
+ end
48
+
49
+ Spork.each_run do
50
+ # This code will be run each time you run your specs.
51
+ each_run
52
+ end
53
+ else
54
+ setup_environment
55
+ each_run
56
+ end
@@ -0,0 +1,17 @@
1
+ require 'database_cleaner'
2
+
3
+ RSpec.configure do |config|
4
+ config.use_transactional_fixtures = false
5
+
6
+ config.before(:suite) do
7
+ DatabaseCleaner.strategy = :truncation
8
+ end
9
+
10
+ config.before(:each) do
11
+ DatabaseCleaner.start
12
+ end
13
+
14
+ config.after(:each) do
15
+ DatabaseCleaner.clean
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ require 'devise'
2
+
3
+ RSpec.configure do |config|
4
+ config.mock_with :rspec
5
+ config.use_transactional_fixtures = false
6
+
7
+ config.include Devise::TestHelpers, :type => :controller
8
+ end
@@ -0,0 +1,6 @@
1
+ require 'refinerycms-testing'
2
+
3
+ RSpec.configure do |config|
4
+ config.extend Refinery::Testing::ControllerMacros::Authentication, :type => :controller
5
+ config.extend Refinery::Testing::RequestMacros::Authentication, :type => :request
6
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc "Run specs"
4
+ RSpec::Core::RakeTask.new
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-page-resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stas Ladonenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: refinerycms-pages
16
+ requirement: &70154759588520 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0.dev
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70154759588520
25
+ description: Page Resources Engine for Refinery CMS
26
+ email: stas.ladonenko@gmail.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - .gitignore
32
+ - .travis.yml
33
+ - Gemfile
34
+ - Rakefile
35
+ - app/assets/javascripts/refinery/page-image-picker.js.erb
36
+ - app/assets/stylesheets/refinery/page-image-picker.css.scss
37
+ - app/models/refinery/image_page.rb
38
+ - app/views/refinery/admin/pages/tabs/_images.html.erb
39
+ - app/views/refinery/admin/pages/tabs/_images_bar.html.erb
40
+ - app/views/refinery/admin/pages/tabs/_images_field.html.erb
41
+ - config/locales/bg.yml
42
+ - config/locales/cs.yml
43
+ - config/locales/de.yml
44
+ - config/locales/en.yml
45
+ - config/locales/fr.yml
46
+ - config/locales/nl.yml
47
+ - config/locales/pt-BR.yml
48
+ - config/locales/ru.yml
49
+ - config/locales/sk.yml
50
+ - db/migrate/20101014230041_create_page_images.rb
51
+ - db/migrate/20101014230042_add_caption_to_image_pages.rb
52
+ - db/migrate/20110511215016_translate_page_image_captions.rb
53
+ - db/migrate/20110527052435_change_page_to_polymorphic.rb
54
+ - lib/generators/refinery/page_images_generator.rb
55
+ - lib/generators/refinery/templates/config/initializers/refinery/page_images.rb.erb
56
+ - lib/refinery/page_images.rb
57
+ - lib/refinery/page_images/configuration.rb
58
+ - lib/refinery/page_images/engine.rb
59
+ - lib/refinery/page_images/extension.rb
60
+ - lib/refinerycms-page-images.rb
61
+ - readme.md
62
+ - refinerycms-page-resources.gemspec
63
+ - script/rails
64
+ - spec/factories/page-images.rb
65
+ - spec/models/refinery/blog_spec.rb
66
+ - spec/models/refinery/page_spec.rb
67
+ - spec/requests/attach_page_images_spec.rb
68
+ - spec/spec_helper.rb
69
+ - spec/support/database_cleaner.rb
70
+ - spec/support/devise.rb
71
+ - spec/support/refinery.rb
72
+ - tasks/rspec.rake
73
+ homepage: http://github.com/stasl/refinerycms-page-resources
74
+ licenses: []
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Page Resources Engine for Refinery CMS
97
+ test_files:
98
+ - spec/factories/page-images.rb
99
+ - spec/models/refinery/blog_spec.rb
100
+ - spec/models/refinery/page_spec.rb
101
+ - spec/requests/attach_page_images_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/database_cleaner.rb
104
+ - spec/support/devise.rb
105
+ - spec/support/refinery.rb