Module: Assetable::Uploaders

Included in:
GalleryInput, UploaderInput
Defined in:
lib/assetable/inputs/uploaders.rb

Instance Method Summary collapse

Instance Method Details

#acObject



27
28
29
30
31
32
# File 'lib/assetable/inputs/uploaders.rb', line 27

def ac
  return @c if @c.present?
  @c = ActionController::Base.new
  @c.request = OpenStruct.new()
  @c
end

#asset_preview(asset, type = :asset, fieldname = nil) ⇒ Object



19
20
21
# File 'lib/assetable/inputs/uploaders.rb', line 19

def asset_preview asset, type=:asset, fieldname=nil
  ac.send(:render_to_string, partial: "assetable/shared/templates/#{type.downcase.to_s}_item", locals: { asset: asset, fieldname: fieldname })
end

#directions_html(directions, fieldname = nil) ⇒ Object



23
24
25
# File 'lib/assetable/inputs/uploaders.rb', line 23

def directions_html(directions, fieldname=nil)
  ac.send(:render_to_string, :partial => 'assetable/assets/directions', locals: {directions: directions, fieldname: fieldname})
end

Gallery preview is a set of assets. Let’s loop over the assets in the gallery and create a preview for each.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/assetable/inputs/uploaders.rb', line 5

def gallery_preview fieldname
  if modal_gallery = object.send("#{attribute_name}")
    gallery = ""

    # modal_gallery.assets.each do |asset|
    modal_gallery.asset_attachments.each_with_index do |asset_attachment, index|
      # gallery += asset_preview(asset, :gallery, fieldname) 
      gallery += ac.send(:render_to_string, partial: "assetable/shared/templates/gallery_item", locals: { asset: asset_attachment.asset, asset_attachment: asset_attachment, fieldname: fieldname, index: index })
    end

    gallery
  end
end