Sha256: e026d0ccd4385a73372112309a48c08ba6b22c273b03b1850ee656975b15c26b

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module DynamicScaffold
  module Form
    module Item
      class CarrierWaveImage < Base
        attr_reader :options
        def initialize(config, type, name, options = {})
          super(config, type, name, {})
          @options = options
          @options[:removable] = true if @options[:removable].nil?
        end

        def cropper
          return nil unless @options.key? :cropper
          return {} if @options[:cropper] == true
          @options[:cropper]
        end

        def preview_image_style
          max_size = @options[:preview_max_size]
          return '' unless max_size

          ''.tap do |s|
            s << "max-width: #{max_size[:width]};" if max_size[:width]
            s << "max-height: #{max_size[:height]};" if max_size[:height]
          end
        end

        def render(_view, _form, classnames = nil)
          html_attributes = build_html_attributes(classnames)
          yield(html_attributes)
        end

        def extract_parameters(permitting)
          # If you do not permit before the image body you can not use cropper value in uploader.
          permitting << "cropper_#{@name}" unless cropper.nil?
          permitting << "remove_#{@name}" if @options[:removable]
          permitting.concat(["#{@name}_cache", @name])
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamic_scaffold-0.9.1 lib/dynamic_scaffold/form/item/carrier_wave_image.rb
dynamic_scaffold-0.9.0 lib/dynamic_scaffold/form/item/carrier_wave_image.rb