Skip to content

Commit

Permalink
Now use Module#prepend for decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
bricesanchez committed Aug 29, 2018
1 parent 1fe5866 commit 53a3a47
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 47 deletions.
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,10 +1,8 @@
if defined?(Refinery::Page)
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
end
)
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
23 changes: 20 additions & 3 deletions app/decorators/models/refinery/page_images_page_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
if defined?(Refinery::Page)
Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern
end
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.

0 comments on commit 53a3a47

Please sign in to comment.