samvera / iiif_manifest

Other
10 stars 10 forks source link

Custom Builders #26

Open travisLilleberg opened 6 years ago

travisLilleberg commented 6 years ago

Hello, this is more of a question than a issue, but is there any way to cleanly add a builder to this process?

I need to add thumbnail support to the manifest and I know I can overwrite things and all that, but I was hoping there was a place where I could just insert my own builder and let the code run as intended.

I'm happy to clarify, if I'm not being clear. Thanks.

cjcolvar commented 5 years ago

@travisLilleberg I'm not sure if there is an easy/clean way to add a builder other than overriding ManifestServiceLocator#manifest_builders and adding in your builder. I'm going to be working on adding thumbnail (and posterCanvas in V3 manifests) soon. Did you figure out a better solution?

travisLilleberg commented 5 years ago

@cjcolvar

I ended up overriding the Hyrax::WorksControllerBehavior#manifest method in our Image controller - building the json, and then attaching the thumbnail info at the end before rendering it.

module Hyrax
  class ImagesController < CatalogController
    include Hyrax::WorksControllerBehavior
    self.curation_concern_type = ::Image
    self.show_presenter = Hyrax::ImagePresenter

    ###
    # Adds thumbnails to the IIIF Manifest for images.
    def manifest
      headers['Access-Control-Allow-Origin'] = '*'

      manifest_json = manifest_builder.to_h
      manifest_json['thumbnail'] = { '@id' => thumbnail }
      render json: manifest_json
    end

    private

      ###
      # Gets the external thumbnail path of a resource.
      def thumbnail
        thumbnail_path = Hyrax::ThumbnailPathService.call(@presenter).slice(1..-1)
        root_url + thumbnail_path
      end
  end
end

I'm open to better ways of doing this, if you can think of any! I hope this helps.