Module: Infold::AttachmentFieldDecorator
- Defined in:
- app/decorators/infold/attachment_field_decorator.rb
Instance Method Summary collapse
- #file_display_code(object_name, indent, thumb: false) ⇒ Object
- #form_file_upload_code(ns_camel, form_object_char = 'form', nested_form: false) ⇒ Object
- #has_attached_code ⇒ Object
Instance Method Details
#file_display_code(object_name, indent, thumb: false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/decorators/infold/attachment_field_decorator.rb', line 16 def file_display_code(object_name, indent, thumb: false) code = "- if #{object_name}.#{name}.attached?\n" if kind_file? code += "#{indent} = link_to #{object_name}.#{name}.filename, rails_blob_url(#{object_name}.#{name}), target: '_blank'" else code += "#{indent} = link_to url_for(#{object_name}.#{name}), target: '_blank' do\n" code += "#{indent} - if #{object_name}.#{name}.blob.image?\n" code += "#{indent} = image_tag(#{object_name}.#{name}#{'.variant(:thumb)' if thumb}, class: 'img-fluid')\n" code += "#{indent} - else\n" code += "#{indent} = #{object_name}.#{name}.filename" end code end |
#form_file_upload_code(ns_camel, form_object_char = 'form', nested_form: false) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/decorators/infold/attachment_field_decorator.rb', line 30 def form_file_upload_code(ns_camel, form_object_char = 'form', nested_form: false) required = label = '' if nested_form label = ', label: false' else # required = ', required: true' if model_column.required_validate? end "= render #{ns_camel}::Form::FileUploadComponent.new(#{form_object_char}, :#{name}#{required}#{label})" end |
#has_attached_code ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/decorators/infold/attachment_field_decorator.rb', line 3 def has_attached_code code = "has_one_attached :#{name}" if thumbnail_fill? || thumbnail_fit? code += " do |attachable| attachable.variant :thumb, resize_to_#{thumbnail}: [#{thumb_width.presence || 480}, #{thumb_height.presence || 320}] end" end code + "\n attr_accessor :remove_#{name} before_validation do self.#{name} = nil if @remove_#{name}.to_s == '1' end" end |