Sha256: c6d54b8ae3f7948551d2b2b0296cfdd2cdf62f8848bce8f2819d7e936bd6551b

Contents?: true

Size: 1.59 KB

Versions: 16

Compression:

Stored size: 1.59 KB

Contents

if Enjoy.mongoid?
  module Enjoy::MongoidPaperclip
    extend ActiveSupport::Concern

    include Mongoid::Paperclip

    module ClassMethods
      def enjoy_cms_mongoid_attached_file(name, opts = {})
        name = name.to_sym
        unless opts.blank?
          content_type = opts.delete(:content_type)
          jcrop_options = opts.delete(:jcrop_options)
        end

        opts[:processors] ||= []
        opts[:processors] << :paperclip_optimizer
        opts[:processors].flatten!
        opts[:processors].uniq!

        opts[:convert_options] = {all: "-quality 75 -strip"} if opts[:convert_options].blank?

        has_mongoid_attached_file name, opts
        validates_attachment name, content_type: content_type unless content_type.blank?
        class_eval <<-EVAL
          def #{name}_file_name=(val)
            return self[:#{name}_file_name] = ""  if val == ""
            return self[:#{name}_file_name] = nil if val == nil
            val = val.to_s
            extension = File.extname(val)[1..-1]
            file_name = val[0..val.size-extension.size-1]
            self[:#{name}_file_name] = "\#{file_name.filename_to_slug}.\#{extension.filename_to_slug}"
          end

          before_#{name}_post_process do
            p_o = self.#{name}.processors.delete :paperclip_optimizer
            self.#{name}.processors << p_o if p_o
            true
          end
        EVAL
        jcrop_options ||= {}
        if jcrop_options
          class_eval <<-EVAL
            def #{name}_jcrop_options
              #{jcrop_options}
            end
          EVAL
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
enjoy_cms-0.3.7.4 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.7.3 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.7.2 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.7.1 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.7 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.6.2 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.6.1 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.6 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.5 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.4 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.3 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.2.1 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.2 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.1.2 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.1.1 app/models/concerns/enjoy/mongoid_paperclip.rb
enjoy_cms-0.3.1 app/models/concerns/enjoy/mongoid_paperclip.rb