refinerycms-page-options 2.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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.travis.yml +27 -0
  4. data/Gemfile +41 -0
  5. data/Rakefile +21 -0
  6. data/app/assets/javascripts/refinery/page-image-picker.js.erb +190 -0
  7. data/app/assets/javascripts/refinery/page-options.js.erb +13 -0
  8. data/app/assets/stylesheets/refinery/page-image-picker.css.scss +63 -0
  9. data/app/helpers/refinery/page_options_helper.rb +5 -0
  10. data/app/models/refinery/page_option.rb +9 -0
  11. data/app/views/refinery/admin/pages/tabs/_option_fields.erb +3 -0
  12. data/app/views/refinery/admin/pages/tabs/_options.html.erb +25 -0
  13. data/app/views/refinery/admin/pages/tabs/_options_bar.html.erb +9 -0
  14. data/app/views/refinery/admin/pages/tabs/_options_field.html.erb +7 -0
  15. data/config/locales/bg.yml +17 -0
  16. data/config/locales/cs.yml +17 -0
  17. data/config/locales/de.yml +12 -0
  18. data/config/locales/en.yml +18 -0
  19. data/config/locales/es.yml +19 -0
  20. data/config/locales/fr.yml +17 -0
  21. data/config/locales/ja.yml +18 -0
  22. data/config/locales/nl.yml +12 -0
  23. data/config/locales/pt-BR.yml +17 -0
  24. data/config/locales/ru.yml +12 -0
  25. data/config/locales/sk.yml +17 -0
  26. data/db/migrate/20101014230041_create_page_options.rb +10 -0
  27. data/lib/generators/refinery/page_options_generator.rb +15 -0
  28. data/lib/generators/refinery/templates/config/initializers/refinery/page_options.rb.erb +2 -0
  29. data/lib/refinery/page_options/configuration.rb +27 -0
  30. data/lib/refinery/page_options/engine.rb +44 -0
  31. data/lib/refinery/page_options/extension.rb +15 -0
  32. data/lib/refinery/page_options.rb +33 -0
  33. data/lib/refinerycms-page-options.rb +1 -0
  34. data/readme.md +55 -0
  35. data/refinerycms-page-options.gemspec +16 -0
  36. data/script/rails +6 -0
  37. data/spec/factories/page-images.rb +9 -0
  38. data/spec/features/attach_page_images_spec.rb +58 -0
  39. data/spec/lib/refinery/initializer_spec.rb +42 -0
  40. data/spec/models/refinery/blog_spec.rb +15 -0
  41. data/spec/models/refinery/page_spec.rb +79 -0
  42. data/spec/spec_helper.rb +31 -0
  43. data/tasks/rspec.rake +4 -0
  44. metadata +105 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ffc4dcdf02c188ee9d885a3e787480b435f18b43
4
+ data.tar.gz: 802b7ac4c899fb9e43c5a664b2a448529d9fc890
5
+ SHA512:
6
+ metadata.gz: 9b2f7154b47906c560a657e6818841e9ef3bb22d339d5dcd9e56ec4fc830d0b128d67ee0a47d17b4d0e0d60fdd92a878a74028c60a46858603fcad4892d26c0d
7
+ data.tar.gz: a805e78463e47de6484b3a2ca4eb966f48ad4c63f1dcd4921ae620eb62432d5fda54bf8e3be2b1c98ddc56efe6367e86cd20e0338b7f3af5645164e10b0774ab
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ spec/dummy/
data/.travis.yml ADDED
@@ -0,0 +1,27 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ before_script:
4
+ - "sh -e /etc/init.d/xvfb start"
5
+ - "bundle exec rake refinery:testing:dummy_app"
6
+ script:
7
+ - "DISPLAY=:99.0 bundle exec rspec spec"
8
+ notifications:
9
+ email: true
10
+ irc:
11
+ use_notice: true
12
+ skip_join: true
13
+ channels:
14
+ - "irc.freenode.org#refinerycms"
15
+ campfire:
16
+ on_success: always
17
+ on_failure: always
18
+ rooms:
19
+ - secure: "X5X39BTgXacSdc32F8mIjJKPqm5dZzmgZfJ14qYpJeMETTdA5JfByt2uCfU8\njJkkxT+XGWta0bSSlRIHQJO6pK26U94A95VYDX0jNuneKEnsoAsqJ6U0VY6v\nH5oxXMAZ2perP/FH9ZsPNR+ulyFfbMQCeGPJw5AXKZQqzf6qPOI="
20
+ env:
21
+ - DB=postgresql
22
+ - DB=mysql
23
+ rvm:
24
+ - 2.0.0
25
+ - 1.9.3
26
+ - rbx-19mode
27
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,41 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'refinerycms', '~> 2.1.0'
6
+ gem 'refinerycms-testing', '~> 2.1.0', :group => :test
7
+
8
+ # Database Configuration
9
+ unless ENV['TRAVIS']
10
+ gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
11
+ gem 'sqlite3', :platform => :ruby
12
+ end
13
+
14
+ if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
15
+ gem 'activerecord-jdbcmysql-adapter', :platform => :jruby
16
+ gem 'jdbc-mysql', '= 5.1.13', :platform => :jruby
17
+ gem 'mysql2', :platform => :ruby
18
+ end
19
+
20
+ if !ENV['TRAVIS'] || ENV['DB'] == 'postgresql'
21
+ gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby
22
+ gem 'pg', :platform => :ruby
23
+ end
24
+
25
+ gem 'jruby-openssl', :platform => :jruby
26
+
27
+ group :test do
28
+ gem 'poltergeist'
29
+ end
30
+
31
+ # Refinery/rails should pull in the proper versions of these
32
+ group :assets do
33
+ gem 'sass-rails'
34
+ gem 'coffee-rails'
35
+ gem 'uglifier'
36
+ end
37
+
38
+ # Load local gems according to Refinery developer preference.
39
+ if File.exist? local_gemfile = File.expand_path('../.gemfile', __FILE__)
40
+ eval File.read(local_gemfile)
41
+ end
data/Rakefile ADDED
@@ -0,0 +1,21 @@
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__)
20
+
21
+ task :default => :spec
@@ -0,0 +1,190 @@
1
+ <%# encoding: utf-8 %>
2
+ var image_added; // Global callback
3
+ (function($) {
4
+ var reset_functionality, open_image_caption, reindex_images,
5
+ template_li, wysiwyg_enabled, input_type;
6
+ $(document).ready(function(){
7
+ var picker = $('#page_image_picker');
8
+ input_type = picker.data('input-type');
9
+ wysiwyg_enabled = input_type == 'wym';
10
+
11
+ $('#custom_images_tab a').click(function(){
12
+ if (!picker.data('size-applied') && wysiwyg_enabled){
13
+ var wym_box = $('.page_part:first .wym_box'),
14
+ iframe = $('.page_part:first iframe');
15
+ picker.css({
16
+ height: wym_box.height()
17
+ , width: wym_box.width()
18
+ }).data('size-applied', true).corner('tr 5px').corner('bottom 5px').find('.wym_box').css({
19
+ backgroundColor: 'white'
20
+ , height: iframe.height() + $('.page_part:first .wym_area_top').height() - parseInt($('.wym_area_top .label_inline_with_link a').css('lineHeight'))
21
+ , width: iframe.width() - 20
22
+ , 'border-color': iframe.css('border-top-color')
23
+ , 'border-style': iframe.css('border-top-style')
24
+ , 'border-width': iframe.css('border-top-width')
25
+ , padding: '0px 10px 0px 10px'
26
+ });
27
+ }
28
+ });
29
+
30
+ // Webkit browsers don't like the textarea being moved around the DOM,
31
+ // they ignore the new contents. This is fixed below by adding a hidden
32
+ // field that stays in place.
33
+ $('#page_images li textarea:hidden').each(function(index) {
34
+ var old_name = $(this).attr('name'),
35
+ $this = $(this);
36
+ $this.attr('data-old-id', $this.attr('id'));
37
+ $this.attr('name', 'ignore_me_' + index);
38
+ $this.attr('id', 'ignore_me_' + index);
39
+
40
+ var hidden = $('<input>')
41
+ .addClass('caption')
42
+ .attr('type', 'hidden')
43
+ .attr('name', old_name)
44
+ .attr('id', $this.attr('data-old-id'))
45
+ .val($this.val());
46
+
47
+ $this.parents('li').first().append(hidden);
48
+ });
49
+
50
+ reset_functionality();
51
+
52
+
53
+ // Once the plugin has init'd everything, remove the template UI
54
+ $('.page-images-caption-modal').hide();
55
+ template_li = $('#page_images .js-page-images-template').detach();
56
+ });
57
+
58
+ reset_functionality = function() {
59
+ if(wysiwyg_enabled) {
60
+ WYMeditor.onload_functions.push(function(){
61
+ $('.wym_box').css({'width':null});
62
+ });
63
+ }
64
+
65
+ $("#page_images").sortable({
66
+ 'tolerance': 'pointer'
67
+ , 'placeholder': 'placeholder'
68
+ , 'cursor': 'drag'
69
+ , 'items': 'li'
70
+ , stop: reindex_images
71
+ });
72
+
73
+ $('#page_images').on('mouseenter mouseleave', 'li', function(e) {
74
+ var $this = $(this),
75
+ image_actions = $this.find('.image_actions');
76
+ if (e.type == 'mouseenter') {
77
+ if (image_actions.length == 0) {
78
+ image_actions = $("<div class='image_actions'></div>");
79
+ var img_delete = $("<img src='<%= image_path('refinery/icons/delete.png') %>' width='16' height='16' />");
80
+ img_delete.appendTo(image_actions);
81
+ img_delete.click(function() {
82
+ $(this).parents('li').first().remove();
83
+ reindex_images();
84
+ });
85
+
86
+ if ($this.find('textarea.page_caption').length > 0) {
87
+ var img_caption = $("<img src='<%= image_path('refinery/icons/user_comment.png') %>' width='16' height='16' class='caption' />");
88
+ img_caption.appendTo(image_actions);
89
+ img_caption.click(open_image_caption);
90
+ } else {
91
+ image_actions.addClass('no_captions');
92
+ }
93
+
94
+ image_actions.appendTo($this);
95
+ }
96
+
97
+ image_actions.show();
98
+ } else if (e.type == 'mouseleave') {
99
+ image_actions.hide();
100
+ }
101
+ });
102
+
103
+ reindex_images();
104
+ };
105
+
106
+ image_added = function(image) {
107
+ var current_list_item = template_li.clone(),
108
+ image_id = $(image).attr('id').replace('image_', '');
109
+ current_list_item.find('input:hidden:first').val(image_id);
110
+
111
+ $("<img />").attr({
112
+ title: $(image).attr('title')
113
+ , alt: $(image).attr('alt')
114
+ , src: $(image).attr('data-grid') // use 'grid' size that is built into Refinery CMS (135x135#c).
115
+ }).appendTo(current_list_item);
116
+
117
+ current_list_item.attr('id', 'image_' + image_id).removeClass('empty');
118
+
119
+ current_list_item.appendTo($('#page_images'));
120
+ reset_functionality();
121
+ };
122
+
123
+ open_image_caption = function(e) {
124
+ var list_item = $(this).closest('li'),
125
+ textarea = list_item.find('.page-images-caption-modal > textarea'),
126
+ textarea_wrapper = textarea.parent(),
127
+ modal_size = {
128
+ textarea: { width: 400, height: 'auto' },
129
+ wym: { width: 928, height: 530 }
130
+ };
131
+
132
+ textarea_wrapper.find('.js-page-images-done').on('click', function() {
133
+ textarea_wrapper.dialog("close");
134
+ });
135
+
136
+ var close_handler = function() {
137
+ if(wysiwyg_enabled) {
138
+ textarea.data('wymeditor').update();
139
+ }
140
+
141
+ $('li.current_caption_list_item').removeClass('current_caption_list_item');
142
+ $('#' + textarea.attr('data-old-id')).val(textarea.val());
143
+ textarea_wrapper.dialog('destroy');
144
+ };
145
+
146
+ // move the textarea out of the list item, and then move the textarea back into it when we click done.
147
+ list_item.addClass('current_caption_list_item');
148
+ textarea_wrapper.dialog({
149
+ title: "<%= I18n.t('refinery.js.admin.page_images.add_caption') %>"
150
+ , modal: true
151
+ , resizable: false
152
+ , autoOpen: true
153
+ , width: modal_size[input_type].width
154
+ , height: modal_size[input_type].height
155
+ , close: close_handler
156
+ });
157
+
158
+ if(wysiwyg_enabled) {
159
+ textarea.addClass('wymeditor active_rotator_wymeditor widest').wymeditor(wymeditor_boot_options);
160
+ }
161
+ else {
162
+ textarea.show();
163
+ }
164
+ };
165
+
166
+ reindex_images = function() {
167
+ $('#page_images li textarea:hidden').each(function(i, input){
168
+ // make the image's name consistent with its position.
169
+ var parts = $(input).attr('name').split('_');
170
+ parts[2] = ('' + i);
171
+ $(input).attr('name', parts.join('_'));
172
+
173
+ // make the image's id consistent with its position.
174
+ $(input).attr('id', $(input).attr('id').replace(/_\d/, '_' + i));
175
+ $(input).attr('data-old-id', $(input).attr('data-old-id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_' + i));
176
+ });
177
+ $('#page_images li').each(function(i, li){
178
+ $('input:hidden', li).each(function() {
179
+ var $this = $(this);
180
+ // make the image's name consistent with its position.
181
+ var parts = $this.attr('name').split(']');
182
+ parts[1] = ('[' + i);
183
+ $this.attr('name', parts.join(']'));
184
+
185
+ // make the image's id consistent with its position.
186
+ $this.attr('id', $this.attr('id').replace(/_\d_/, '_'+i+'_').replace(/_\d/, '_'+i));
187
+ });
188
+ });
189
+ }
190
+ })(jQuery);
@@ -0,0 +1,13 @@
1
+ (
2
+ function($) {
3
+ $(document).ready(function () {
4
+ $('.add_options').on('click', function (e) {
5
+ var time = new Date().getTime(),
6
+ regex = new RegExp($(this).data('id'), 'g');
7
+
8
+ $(this).before($(this).data('fields').replace(regex, time));
9
+ e.preventDefault();
10
+ });
11
+ });
12
+ }
13
+ )(jQuery);
@@ -0,0 +1,63 @@
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
+ }
58
+
59
+ .page-images-caption-modal.plain {
60
+ textarea {
61
+ width: 400px;
62
+ }
63
+ }
@@ -0,0 +1,5 @@
1
+ module Refinery
2
+ module PageOptionsHelper
3
+
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module Refinery
2
+ class PageOption < Refinery::Core::BaseModel
3
+
4
+ belongs_to :page
5
+
6
+ attr_accessible :name, :value, :position
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ <%= f.label :name %> <%= f.text_field :name %>
2
+ <%= f.label :value %> <%= f.text_field :value %>
3
+ <%= f.label :_destroy, "Remove" %> <%= f.check_box :_destroy %>
@@ -0,0 +1,25 @@
1
+ <%
2
+ def link_to_add_options(title, builder)
3
+ new_page_option = builder.object.send('page_options').klass.new
4
+ id = new_page_option.object_id
5
+ fields = builder.fields_for('page_options', new_page_option, :child_index => id) do |f|
6
+ render '/refinery/admin/pages/tabs/option_fields', :f => f
7
+ end
8
+ link_to title, '#', :class => 'add_options', :id => 'add_image_link', :data => {
9
+ :id => id,
10
+ :fields => fields.gsub("\n", "")
11
+ }
12
+ end
13
+ %>
14
+ <div class='wym_skin_refinery page_part' id='page_option_picker'
15
+ data-input-type="<%#= Refinery::PageImages.config.wysiwyg ? 'wym' : 'textarea'%>">
16
+ <%= f.fields_for :page_options do |po| %>
17
+ <%= render '/refinery/admin/pages/tabs/option_fields', :f => po %>
18
+ <%= link_to_add_options t('refinery.admin.pages.tabs.options_bar.add'), f %>
19
+ <% end %>
20
+ <%#= render '/refinery/admin/pages/tabs/images_bar', :f => f %>
21
+ <%#= render '/refinery/admin/pages/tabs/images_field', :f => f %>
22
+ </div>
23
+
24
+ <%# content_for :stylesheets, stylesheet_link_tag('refinery/page-options-picker') %>
25
+ <% content_for :javascripts, javascript_include_tag('refinery/page-options') %>
@@ -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,7 @@
1
+ <% form_actions = capture do %>
2
+ <div class='form-actions'>
3
+ <div class='form-actions-left'>
4
+ <a class='button js-page-options-add'><%= I18n.t('refinery.js.admin.page_options.done') %></a>
5
+ </div>
6
+ </div>
7
+ <% end %>
@@ -0,0 +1,17 @@
1
+ bg:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Изображения на страница
6
+ title: Изображения на страница
7
+ description: Чрез добавката "Изображения на страница" имате възможност да свържите едно или повече изображения с всяка страница в Refinery. Така лесно ще можете да създавате опростени галерии с изображения, които се отварят в изкачащ прозорец като при lightbox.
8
+ js:
9
+ admin:
10
+ page_images:
11
+ add_caption: Добавяне на заглавие
12
+ done: Готово
13
+ admin:
14
+ pages:
15
+ tabs:
16
+ images_bar:
17
+ add: Добавяне на изображение
@@ -0,0 +1,17 @@
1
+ cs:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Obrázky stránek
6
+ title: Obrázky stránek
7
+ 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.
8
+ js:
9
+ admin:
10
+ page_images:
11
+ add_caption: Přidat titulek
12
+ done: Hotovo
13
+ admin:
14
+ pages:
15
+ tabs:
16
+ images_bar:
17
+ add: Přidat obrázek
@@ -0,0 +1,12 @@
1
+ de:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Seitenbilder
6
+ title: Seitenbilder
7
+ description: Das Seitenbilder-Plugin erlaubt dir ein oder mehrere Bilder einer Seite zuzuordnen. Damit ist es möglich Bildergalerien in der Frontendansicht darzustellen.
8
+ admin:
9
+ pages:
10
+ tabs:
11
+ images_bar:
12
+ add: Bild hinzufügen
@@ -0,0 +1,18 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_options:
5
+ tab_name: Page Options
6
+ title: Page Options
7
+ tab_name: Options
8
+ description: Page Options allows you to add key/value pairs for use in the frontend.
9
+ js:
10
+ admin:
11
+ page_options:
12
+ add_options: Add Options
13
+ done: Done
14
+ admin:
15
+ pages:
16
+ tabs:
17
+ options_bar:
18
+ add: Add Option
@@ -0,0 +1,19 @@
1
+ es:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Imágenes de Página
6
+ title: Imágenes de Página
7
+ tab_name: Imágenes
8
+ description: Imágenes de página te permite relacionar una o más imagenes a cualquier página en Refinery lo que hace realmente fácil crear galerías de imágenes con diferentes estilos
9
+ js:
10
+ admin:
11
+ page_images:
12
+ add_caption: Añadir Imagen
13
+ done: Hecho
14
+ admin:
15
+ pages:
16
+ tabs:
17
+ images_bar:
18
+ add: Añadir Imagen
19
+
@@ -0,0 +1,17 @@
1
+ fr:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Page Images
6
+ title: Page Images
7
+ 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"
8
+ js:
9
+ admin:
10
+ page_images:
11
+ add_caption: Ajouter une légende
12
+ done: Terminé
13
+ admin:
14
+ pages:
15
+ tabs:
16
+ images_bar:
17
+ add: Ajouter une image
@@ -0,0 +1,18 @@
1
+ ja:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: ページ画像
6
+ title: ページ画像
7
+ tab_name: 画像
8
+ description: 一つのページに対して、複数または一つの画像を設定することが出来ます。
9
+ js:
10
+ admin:
11
+ page_images:
12
+ add_caption: キャプションを追加
13
+ done: 保存
14
+ admin:
15
+ pages:
16
+ tabs:
17
+ images_bar:
18
+ add: 画像を追加
@@ -0,0 +1,12 @@
1
+ nl:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Pagina Afbeeldingen
6
+ title: Pagina Afbeeldingen
7
+ description: Pagina Afbeeldingen stelt u in staat op afbeeldingen te koppelen aan een specifieke pagina.
8
+ admin:
9
+ pages:
10
+ tabs:
11
+ images_bar:
12
+ add: Afbeelding toevoegen.
@@ -0,0 +1,17 @@
1
+ pt-BR:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Imagens da Página
6
+ title: Imagens da Página
7
+ 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.
8
+ js:
9
+ admin:
10
+ page_images:
11
+ add_caption: Adicionar Legenda
12
+ done: Feito
13
+ admin:
14
+ pages:
15
+ tabs:
16
+ images_bar:
17
+ add: Adicionar Imagem
@@ -0,0 +1,12 @@
1
+ ru:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Изображения страницы
6
+ title: Изображения страницы
7
+ description: Плагин работы с изображениями страницы "Page Images" позволяет связывать одно или несколько изображений с любой страницей в Refinery. С помощью плагина можно с легкостью создавать простые галереи изображений с поддержкой всплывающих полноразмерных изображений в стиле lightbox.
8
+ admin:
9
+ pages:
10
+ tabs:
11
+ images_bar:
12
+ add: Добавить
@@ -0,0 +1,17 @@
1
+ sk:
2
+ refinery:
3
+ plugins:
4
+ refinery_page_images:
5
+ tab_name: Obrázky stránok
6
+ title: Obrázky stránok
7
+ 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.
8
+ js:
9
+ admin:
10
+ page_images:
11
+ add_caption: Pridať titulok
12
+ done: Hotovo
13
+ admin:
14
+ pages:
15
+ tabs:
16
+ images_bar:
17
+ add: Pridať obrázok
@@ -0,0 +1,10 @@
1
+ class CreatePageOptions < ActiveRecord::Migration
2
+ def change
3
+ create_table Refinery::PageOption.table_name do |t|
4
+ t.integer :page_id
5
+ t.string :name
6
+ t.string :value
7
+ t.integer :position
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ module Refinery
2
+ class PageOptionsGenerator < Rails::Generators::Base
3
+
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def rake_db
7
+ rake("refinery_page_options:install:migrations")
8
+ end
9
+
10
+ def generate_page_options_initializer
11
+ template "config/initializers/refinery/page_options.rb.erb", File.join(destination_root, "config", "initializers", "refinery", "page_options.rb")
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ Refinery::PageOptions.configure do |config|
2
+ end
@@ -0,0 +1,27 @@
1
+ module Refinery
2
+ module PageOptions
3
+ include ActiveSupport::Configurable
4
+
5
+ config_accessor :enable_for
6
+
7
+ self.enable_for = [
8
+ { :model => 'Refinery::Page', :tab => 'Refinery::Pages::Tab' },
9
+ ]
10
+
11
+ config.instance_eval do
12
+ def enabled_tabs
13
+ extract_enabled_option(:tab)
14
+ end
15
+
16
+ def enabled_models
17
+ extract_enabled_option(:model)
18
+ end
19
+
20
+ private
21
+ def extract_enabled_option(key)
22
+ enable_for.map { |enable_for| enable_for[key] }.compact
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ require 'refinery/page_options/configuration'
2
+
3
+ module Refinery
4
+ module PageOptions
5
+ class Engine < Rails::Engine
6
+ include Refinery::Engine
7
+
8
+ isolate_namespace Refinery
9
+
10
+ engine_name :refinery_page_options
11
+
12
+ def self.register(tab)
13
+ tab.name = ::I18n.t(:'refinery.plugins.refinery_page_options.tab_name')
14
+ tab.partial = "/refinery/admin/pages/tabs/options"
15
+ end
16
+
17
+ def self.initialize_tabs!
18
+ PageOptions.config.enabled_tabs.each do |tab_class_name|
19
+ unless (tab_class = tab_class_name.safe_constantize)
20
+ Rails.logger.warn "PageOptions is unable to find tab class: #{tab_class_name}"
21
+ next
22
+ end
23
+ tab_class.register { |tab| register tab }
24
+ end
25
+ end
26
+
27
+ initializer "register refinery_page_options plugin" do
28
+ Refinery::Plugin.register do |plugin|
29
+ plugin.name = "page_options"
30
+ plugin.hide_from_menu = true
31
+ end
32
+ end
33
+
34
+ config.to_prepare do
35
+ Refinery::PageOptions.attach!
36
+ end
37
+
38
+ config.after_initialize do
39
+ initialize_tabs!
40
+ Refinery.register_engine Refinery::PageOptions
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,15 @@
1
+ module Refinery
2
+ module PageOptions
3
+ module Extension
4
+ def has_many_page_options
5
+ has_many :page_options
6
+ accepts_nested_attributes_for :page_options, :allow_destroy => true
7
+ include Refinery::PageOptions::Extension::InstanceMethods
8
+
9
+ attr_accessible :page_options_attributes
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveRecord::Base.send(:extend, Refinery::PageOptions::Extension)
@@ -0,0 +1,33 @@
1
+ require 'refinerycms-core'
2
+
3
+ module Refinery
4
+ autoload :PageOptionsGenerator, 'generators/refinery/page_options_generator'
5
+
6
+ module PageOptions
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
+
17
+ def attach!
18
+ require 'refinery/page'
19
+ require 'refinery/page_options/extension'
20
+
21
+ config.enabled_models.each do |model_class_name|
22
+ unless (model_class = model_class_name.safe_constantize)
23
+ Rails.logger.warn "PageOptions is unable to find model class: #{model_class_name}"
24
+ next
25
+ end
26
+ model_class.send :has_many_page_options
27
+ end
28
+ end
29
+ end
30
+
31
+ require 'refinery/page_options/engine'
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require 'refinery/page_options'
data/readme.md ADDED
@@ -0,0 +1,55 @@
1
+ # Page Options Engine for Refinery CMS
2
+
3
+ ## About
4
+
5
+ Page options allows you to add key/value pairs to a refinery page
6
+
7
+ ## Requirements
8
+
9
+ * refinerycms >= 2.0.0
10
+
11
+ ## Features
12
+
13
+ * Ability to add key/value pairs
14
+
15
+ ## Install
16
+
17
+ Add this line to your applications `Gemfile`
18
+
19
+ ```ruby
20
+ gem 'refinerycms-page-options', '~> 2.0.0'
21
+ ```
22
+
23
+ Next run
24
+
25
+ ```bash
26
+ bundle install
27
+ rails generate refinery:page_options
28
+ rake db:migrate
29
+ ```
30
+
31
+ Now when you start up your Refinery application, edit a page and there should be a new "Options" tab.
32
+
33
+ ## Usage
34
+
35
+ `app/views/refinery/pages/show.html.erb`
36
+
37
+ If you don't have this file then Refinery will be using its default. You can override this with
38
+
39
+ ```bash
40
+ rake refinery:override view=refinery/pages/show
41
+ ```
42
+
43
+ ```erb
44
+ <% content_for :body_content_right do %>
45
+ <ul id='specification'>
46
+ <% @page.page_options.each do |option| %>
47
+ <li>
48
+ <%= option.key %> - <%= option.value >
49
+ </li>
50
+ <% end %>
51
+ </ul>
52
+ <% end %>
53
+ <%= render :partial => "/refinery/content_page" %>
54
+ ```r :partial => "/refinery/content_page" %>
55
+ ```
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{refinerycms-page-options}
3
+ s.version = %q{2.1.0}
4
+ s.description = %q{Add key/value options to pages}
5
+ s.summary = %q{Page options extension for Refinery CMS}
6
+ s.email = %q{matt@crazypanda.co.uk}
7
+ s.homepage = %q{http://github.com/}
8
+ s.authors = ['Matthew Crouch']
9
+ s.require_paths = %w(lib)
10
+ s.license = %q{MIT}
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'
16
+ end
data/script/rails ADDED
@@ -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 << FactoryGirl.create(:image) }
4
+ end
5
+
6
+ factory :blog_post_with_image, :parent => :blog_post do
7
+ after(:create) { |b| b.images << FactoryGirl.create(:image) }
8
+ end if defined? Refinery::Blog::Post
9
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+
3
+ describe "attach page images" do
4
+ refinery_login_with :refinery_user
5
+
6
+ # No-op block : use default configuration by default
7
+ let(:configure) {}
8
+ let(:create_page) { FactoryGirl.create(:page) }
9
+ let(:navigate_to_edit) { click_link "Edit this page" }
10
+ let(:page_images_tab_id) { "#custom_#{::I18n.t(:'refinery.plugins.refinery_page_images.tab_name')}_tab" }
11
+
12
+ let(:setup_and_visit) do
13
+ configure
14
+ create_page
15
+ visit refinery.admin_pages_path
16
+ navigate_to_edit
17
+ end
18
+
19
+ it "shows images tab" do
20
+ setup_and_visit
21
+ within page_images_tab_id do
22
+ page.should have_content("Images")
23
+ end
24
+ end
25
+
26
+ # This spec actually is broken in a way because Add Image link would
27
+ # be visible to capybara even if we don't click on Images tab.
28
+ it "shows add image link" do
29
+ setup_and_visit
30
+ within page_images_tab_id do
31
+ click_link "Images"
32
+ end
33
+
34
+ page.should have_content("Add Image")
35
+ end
36
+
37
+ context "with caption and WYSIWYG disabled" do
38
+ let(:configure) do
39
+ Refinery::PageImages.config.wysiwyg = false
40
+ Refinery::PageImages.config.captions = true
41
+ end
42
+
43
+ let(:create_page) { FactoryGirl.create(:page_with_image) }
44
+ let(:navigate_to_edit) { page.find('a[tooltip="Edit this page"]').click }
45
+
46
+ it "shows a plain textarea when editing caption", js: true do
47
+ setup_and_visit
48
+ page.find("#{page_images_tab_id} a").click
49
+ image_li_tag = page.find("#page_images li:first-child")
50
+
51
+ image_li_tag.hover
52
+ within(image_li_tag) { page.find('img.caption').click }
53
+
54
+ page.find('.ui-dialog textarea').should be_visible
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Refinery::PageImages::Engine do
4
+ before(:all) do
5
+ class Refinery::PageImages::EnableForMock
6
+ class Model; end
7
+ class Tab; end
8
+ end
9
+ end
10
+
11
+ after(:all) do
12
+ Refinery::PageImages.instance_eval { remove_const(:EnableForMock) }
13
+ end
14
+
15
+ before(:each) do
16
+ Refinery::PageImages.config.stub(:enable_for).and_return(enable_for_config)
17
+ end
18
+
19
+ def enable_for_config
20
+ [{ :model => 'Refinery::PageImages::EnableForMock::Model',
21
+ :tab => 'Refinery::PageImages::EnableForMock::Tab' }]
22
+ end
23
+
24
+ describe "attach initializer" do
25
+ it "calls attach on all configured model" do
26
+ Refinery::PageImages.config.stub(:enable_for).and_return(enable_for_config)
27
+
28
+ Refinery::PageImages::EnableForMock::Model.should_receive(:has_many_page_images).once
29
+ Refinery::Page.should_not_receive(:has_many_page_images)
30
+ ActionDispatch::Reloader.prepare!
31
+ end
32
+ end
33
+
34
+ describe "attach_initialize_tabs!" do
35
+ it "registers tabs for all configured engine" do
36
+ Refinery::PageImages::EnableForMock::Tab.should_receive(:register).once
37
+ Refinery::Pages::Tab.should_not_receive(:register)
38
+ Refinery::PageImages::Engine.initialize_tabs!
39
+ end
40
+ end
41
+
42
+ 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 = FactoryGirl.create(:blog_post)
7
+ blog.images.count.should == 0
8
+ end
9
+
10
+ it "should have images" do
11
+ blog = FactoryGirl.create(:blog_post_with_image)
12
+ blog.images.count.should == 1
13
+ end
14
+ end
15
+ end if defined?(Refinery::Blog::Post)
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ module Refinery
4
+ describe Page do
5
+ it "can have images added" do
6
+ page = FactoryGirl.create(:page)
7
+ page.images.count.should eq(0)
8
+
9
+ page.images << FactoryGirl.create(:image)
10
+ page.images.count.should eq(1)
11
+ end
12
+
13
+ describe "#images_attributes=" do
14
+ it "adds images" do
15
+ page = FactoryGirl.create(:page)
16
+ image = FactoryGirl.create(: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 = FactoryGirl.create(:page)
26
+ images = [FactoryGirl.create(:image), FactoryGirl.create(:image)]
27
+ page.images = images
28
+
29
+ page_image_to_keep = page.image_pages.find do |image_page|
30
+ image_page.image_id == images.first.id
31
+ end
32
+ page.update_attributes(:images_attributes => {
33
+ "0" => {
34
+ "id" => page_image_to_keep.image_id.to_s,
35
+ "image_page_id" => page_image_to_keep.id
36
+ },
37
+ })
38
+
39
+ page.images.should eq([images.first])
40
+ end
41
+
42
+ it "deletes all images" do
43
+ page = FactoryGirl.create(:page)
44
+ images = [FactoryGirl.create(:image), FactoryGirl.create(:image)]
45
+ page.images = images
46
+
47
+ page.update_attributes(:images_attributes => {"0" => {"id"=>""}})
48
+
49
+ page.images.should be_empty
50
+ end
51
+
52
+ it "reorders images" do
53
+ page = FactoryGirl.create(:page)
54
+ images = [FactoryGirl.create(:image), FactoryGirl.create(:image)]
55
+ page.images = images
56
+
57
+ first_page_image = page.image_pages.find do |image_page|
58
+ image_page.image_id == images.first.id
59
+ end
60
+ second_page_image = page.image_pages.find do |image_page|
61
+ image_page.image_id == images.second.id
62
+ end
63
+
64
+ page.update_attributes(:images_attributes => {
65
+ "0" => {
66
+ "id" => second_page_image.image_id,
67
+ "image_page_id" => second_page_image.id,
68
+ },
69
+ "1" => {
70
+ "id" => first_page_image.image_id,
71
+ "image_page_id" => first_page_image.id,
72
+ },
73
+ })
74
+
75
+ page.images.should eq([images.second, images.first])
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+
3
+ # Configure Rails Environment
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ require File.expand_path("../dummy/config/environment", __FILE__)
7
+
8
+ require 'rspec/rails'
9
+ require 'capybara/rspec'
10
+ require 'factory_girl_rails'
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :rspec
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.filter_run :focus => true
18
+ config.run_all_when_everything_filtered = true
19
+ end
20
+
21
+ # set javascript driver for capybara
22
+ require 'capybara/poltergeist'
23
+ Capybara.javascript_driver = :poltergeist
24
+
25
+ # Requires supporting files with custom matchers and macros, etc,
26
+ # in ./support/ and its subdirectories including factories.
27
+ ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p|
28
+ Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
29
+ }.flatten.sort.each do |support_file|
30
+ require support_file
31
+ end
data/tasks/rspec.rake ADDED
@@ -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-options
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Crouch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: refinerycms-pages
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ description: Add key/value options to pages
28
+ email: matt@crazypanda.co.uk
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - .travis.yml
35
+ - Gemfile
36
+ - Rakefile
37
+ - app/assets/javascripts/refinery/page-image-picker.js.erb
38
+ - app/assets/javascripts/refinery/page-options.js.erb
39
+ - app/assets/stylesheets/refinery/page-image-picker.css.scss
40
+ - app/helpers/refinery/page_options_helper.rb
41
+ - app/models/refinery/page_option.rb
42
+ - app/views/refinery/admin/pages/tabs/_option_fields.erb
43
+ - app/views/refinery/admin/pages/tabs/_options.html.erb
44
+ - app/views/refinery/admin/pages/tabs/_options_bar.html.erb
45
+ - app/views/refinery/admin/pages/tabs/_options_field.html.erb
46
+ - config/locales/bg.yml
47
+ - config/locales/cs.yml
48
+ - config/locales/de.yml
49
+ - config/locales/en.yml
50
+ - config/locales/es.yml
51
+ - config/locales/fr.yml
52
+ - config/locales/ja.yml
53
+ - config/locales/nl.yml
54
+ - config/locales/pt-BR.yml
55
+ - config/locales/ru.yml
56
+ - config/locales/sk.yml
57
+ - db/migrate/20101014230041_create_page_options.rb
58
+ - lib/generators/refinery/page_options_generator.rb
59
+ - lib/generators/refinery/templates/config/initializers/refinery/page_options.rb.erb
60
+ - lib/refinery/page_options.rb
61
+ - lib/refinery/page_options/configuration.rb
62
+ - lib/refinery/page_options/engine.rb
63
+ - lib/refinery/page_options/extension.rb
64
+ - lib/refinerycms-page-options.rb
65
+ - readme.md
66
+ - refinerycms-page-options.gemspec
67
+ - script/rails
68
+ - spec/factories/page-images.rb
69
+ - spec/features/attach_page_images_spec.rb
70
+ - spec/lib/refinery/initializer_spec.rb
71
+ - spec/models/refinery/blog_spec.rb
72
+ - spec/models/refinery/page_spec.rb
73
+ - spec/spec_helper.rb
74
+ - tasks/rspec.rake
75
+ homepage: http://github.com/
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.14
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Page options extension for Refinery CMS
99
+ test_files:
100
+ - spec/factories/page-images.rb
101
+ - spec/features/attach_page_images_spec.rb
102
+ - spec/lib/refinery/initializer_spec.rb
103
+ - spec/models/refinery/blog_spec.rb
104
+ - spec/models/refinery/page_spec.rb
105
+ - spec/spec_helper.rb