diff --git a/app/models/cmtool/image.rb b/app/models/cmtool/image.rb index b0de23f..1a8de69 100644 --- a/app/models/cmtool/image.rb +++ b/app/models/cmtool/image.rb @@ -2,6 +2,10 @@ module Cmtool class Image include SimplyStored::Couch include Paperclip::Glue + # TODO: Replace Paperclip with SimplyStored::HasAttachment + # 1. Change `include Paperclip::Glue` to `include SimplyStored::HasAttachment` + # 2. Replace `has_attached_file :file, styles: {...}` with `has_attachment :file, styles: {...}` + # 3. Replace `validates_attachment` with standard Rails validations property :file_file_name property :file_content_type diff --git a/app/models/cmtool/news.rb b/app/models/cmtool/news.rb index 12cd732..2a94160 100644 --- a/app/models/cmtool/news.rb +++ b/app/models/cmtool/news.rb @@ -2,6 +2,9 @@ module Cmtool class News include SimplyStored::Couch include Paperclip::Glue + # TODO: Replace Paperclip with SimplyStored::HasAttachment + # 1. Change `include Paperclip::Glue` to `include SimplyStored::HasAttachment` + # 2. Replace `has_attached_file :image, styles: {...}` with `has_attachment :image, styles: {...}` property :title property :active, type: :boolean, default: true diff --git a/app/models/cmtool/quote.rb b/app/models/cmtool/quote.rb index 0be0358..2523b88 100644 --- a/app/models/cmtool/quote.rb +++ b/app/models/cmtool/quote.rb @@ -2,6 +2,9 @@ module Cmtool class Quote include SimplyStored::Couch include Paperclip::Glue + # TODO: Replace Paperclip with SimplyStored::HasAttachment + # 1. Change `include Paperclip::Glue` to `include SimplyStored::HasAttachment` + # 2. Replace `has_attached_file :image, styles: {...}` with `has_attachment :image, styles: {...}` property :owner property :function diff --git a/lib/cmtool.rb b/lib/cmtool.rb index db915b3..881e86f 100644 --- a/lib/cmtool.rb +++ b/lib/cmtool.rb @@ -7,5 +7,11 @@ require 'cmtool/includes/pages_controller' require 'cmtool/menu' require 'email_validator' +# Paperclip replacement — stores file metadata as CouchDB properties, +# handles thumbnail generation via MiniMagick. +# Replace `include Paperclip::Glue` + `has_attached_file` with +# `include SimplyStored::HasAttachment` + `has_attachment` +require 'simply_stored/has_attachment' + module Cmtool end diff --git a/lib/simply_stored/has_attachment.rb b/lib/simply_stored/has_attachment.rb new file mode 100644 index 0000000..57ca797 --- /dev/null +++ b/lib/simply_stored/has_attachment.rb @@ -0,0 +1,225 @@ +# frozen_string_literal: true + +module SimplyStored + # Drop-in replacement for Paperclip in SimplyStored/CouchDB models. + # + # Usage (replaces `include Paperclip::Glue` + `has_attached_file`): + # + # class Image + # include SimplyStored::Couch + # include SimplyStored::HasAttachment + # + # has_attachment :file, styles: { + # medium: "354x1000>", + # thumb: "160x1250>" + # } + # + # # Validations (standard Rails, replaces validates_attachment) + # validate :file_content_type_must_be_image + # + # private + # + # def file_content_type_must_be_image + # return if file.blank? + # unless %w[image/jpeg image/gif image/png].include?(file_content_type) + # errors.add(:file, :invalid_content_type) + # end + # end + # end + # + # The module auto-declares CouchDB properties for: + # _file_name, _content_type, _file_size, _updated_at + # + # Files are stored on disk at: + # public/system///original. + # public/system///