Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support for Mobility #149

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ env:
- DB=postgresql
- DB=mysql
rvm:
- 2.4.2
- 2.3.5
- 2.2.8
- 2.5.0
- 2.4.3
- 2.3.6
- 2.2.9
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
if defined?(Refinery::Blog)
Refinery::Blog::Admin::PostsController.prepend(
Module.new do
def permitted_post_params
params[:post][:images_attributes]={} if params[:post][:images_attributes].nil?
super << [images_attributes: [:id, :caption, :image_page_id]]
end
end
)
end
module RefineryPageImagesAddRefineryBlogAdminPostsCrontrollerParams
def permitted_post_params
params[:post][:images_attributes]={} if params[:post][:images_attributes].nil?
super << [images_attributes: [:id, :caption, :image_page_id]]
end
end

Refinery::Blog::Admin::PostsController.prepend(RefineryPageImagesAddRefineryBlogAdminPostsCrontrollerParams) rescue NameError
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Refinery::Admin::PagesController.prepend(
Module.new do
def permitted_page_params
params[:page][:images_attributes]={} if params[:page][:images_attributes].nil?
super << [images_attributes: [:id, :caption, :image_page_id]]
end
module RefineryPageImagesAddRefineryAdminPagesControllerParams
def permitted_page_params
params[:page][:images_attributes]={} if params[:page][:images_attributes].nil?
super << [images_attributes: [:id, :caption, :image_page_id]]
end
)
end

Refinery::Admin::PagesController.prepend(RefineryPageImagesAddRefineryAdminPagesControllerParams) rescue NameError
19 changes: 18 additions & 1 deletion app/decorators/models/refinery/page_images_page_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern
require 'ostruct'

module RefineryPageImagesAddImagesWithCaptions
def self.prepended(base)
base.attr_accessor :images_with_captions
end

def images_with_captions
@images_with_captions = image_pages.map do |ref|
OpenStruct.new(
{
image: Refinery::Image.find(ref.image_id),
caption: ref.caption || ''
}
)
end
end
end

Refinery::Page.prepend(RefineryPageImagesAddImagesWithCaptions) rescue NameError

This file was deleted.

7 changes: 3 additions & 4 deletions app/models/refinery/image_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module Refinery
class ImagePage < Refinery::Core::BaseModel

belongs_to :image
belongs_to :page, polymorphic: true, touch: true
belongs_to :page, polymorphic: true, touch: true, optional: true

extend Mobility
translates :caption

attribute :caption
end
end
end
2 changes: 1 addition & 1 deletion db/migrate/20101014230041_create_page_images.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreatePageImages < ActiveRecord::Migration[4.2]
def change
create_table Refinery::ImagePage.table_name, :id => false do |t|
create_table Refinery::ImagePage.table_name do |t|
t.integer :image_id
t.integer :page_id
t.integer :position
Expand Down
25 changes: 10 additions & 15 deletions db/migrate/20110511215016_translate_page_image_captions.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
class TranslatePageImageCaptions < ActiveRecord::Migration[4.2]
def up
add_column Refinery::ImagePage.table_name, :id, :primary_key

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this causes an Unknown primary key for table refinery_image_pages in model Refinery::ImagePage. error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def change
create_table :refinery_image_page_translations do |t|

Refinery::ImagePage.reset_column_information
unless defined?(Refinery::ImagePage::Translation) && Refinery::ImagePage::Translation.table_exists?
Refinery::ImagePage.create_translation_table!({
:caption => :text
}, {
:migrate_data => true
})
end
end
# Translated attribute(s)
t.text :caption

def down
Refinery::ImagePage.reset_column_information
t.string :locale, null: false
t.integer :refinery_image_page_id, null: false

Refinery::ImagePage.drop_translation_table! :migrate_data => true
t.timestamps null: false
end

remove_column Refinery::ImagePage.table_name, :id
add_index :refinery_image_page_translations, :locale, name: :index_refinery_image_page_translations_on_locale
add_index :refinery_image_page_translations, [:refinery_image_page_id, :locale], name: :index_114aab0bbdedc79d0ec4f4b, unique: true
end
end
1 change: 0 additions & 1 deletion lib/refinery/page_images.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'refinerycms-core'
require 'globalize'

module Refinery
autoload :PageImagesGenerator, 'generators/refinery/page_images_generator'
Expand Down
5 changes: 2 additions & 3 deletions refinerycms-page-images.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/*`.split("\n")

s.add_dependency 'refinerycms-pages', ['~> 4.0', '>= 4.0.0']
s.add_dependency 'decorators', '~> 2.0'
s.add_dependency 'globalize', '~> 5.1.0'
s.add_dependency 'refinerycms-core', ['~> 4.0', '>= 4.0.0']
s.add_dependency 'refinerycms-images', ['~> 4.0', '>= 4.0.0']

s.cert_chain = [File.expand_path("../certs/parndt.pem", __FILE__)]
if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__)
Expand Down
3 changes: 1 addition & 2 deletions spec/features/attach_page_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# No-op block : use default configuration by default
let(:configure) {}
let(:create_page) { FactoryBot.create(:page_with_page_part) }
let(:navigate_to_edit) { click_link "Edit this page" }
let(:navigate_to_edit) { page.find('.edit_icon', match: :first).click }
let(:page_images_tab_id) { "#custom_#{::I18n.t(:'refinery.plugins.refinery_page_images.tab_name')}_tab" }

let(:setup_and_visit) do
Expand Down Expand Up @@ -41,7 +41,6 @@
end

let(:create_page) { FactoryBot.create(:page_with_image) }
let(:navigate_to_edit) { page.find('a[tooltip="Edit this page"]').click }

it "shows a plain textarea when editing caption", js: true do
setup_and_visit
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

require 'rspec/rails'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'

Rails.backtrace_cleaner.remove_silencers!

Expand Down
Empty file added spec/support/refinery_login.rb
Empty file.