Module: Spotlight::CropHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/spotlight/crop_helper.rb

Overview

iiif-crop options helpers

Instance Method Summary collapse

Instance Method Details

#form_prefix(f) ⇒ Object



29
30
31
32
33
34
35
# File 'app/helpers/spotlight/crop_helper.rb', line 29

def form_prefix(f)
  if Rails::VERSION::MAJOR >= 5
    f.object_name.parameterize(separator: '_')
  else
    f.object_name.parameterize('_')
  end
end

#iiif_cropper_tag(f, initial_crop_selection:) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/helpers/spotlight/crop_helper.rb', line 16

def iiif_cropper_tag(f, initial_crop_selection:)
   :div, '', id: "#{form_prefix(f)}_iiif_cropper", data: {
    behavior: 'iiif-cropper',
    cropper_key: f.object.model_name.singular_route_key,
    'crop-width': initial_crop_selection.first,
    'crop-height': initial_crop_selection.last
  }
end

#iiif_cropper_tags(f, initial_crop_selection:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/spotlight/crop_helper.rb', line 5

def iiif_cropper_tags(f, initial_crop_selection:)
  (:div) do
    concat f.hidden_field(:iiif_manifest_url)
    concat f.hidden_field(:iiif_canvas_id)
    concat f.hidden_field(:iiif_image_id)
    concat f.hidden_field(:iiif_region)
    concat f.hidden_field(:iiif_tilesource)
    concat iiif_cropper_tag(f, initial_crop_selection: initial_crop_selection)
  end
end

#iiif_upload_tag(f) ⇒ Object



25
26
27
# File 'app/helpers/spotlight/crop_helper.rb', line 25

def iiif_upload_tag(f)
  f.file_field_without_bootstrap :file, name: 'featured_image[image]', data: { endpoint: polymorphic_path(f.object.model_name.route_key) }
end