Module: Openseadragon::OpenseadragonHelper

Defined in:
app/helpers/openseadragon/openseadragon_helper.rb

Instance Method Summary collapse

Instance Method Details

#openseadragon_picture_tag(*sources) ⇒ Object

Generate a <picture> tag ready to be parsed by the openseadragon/rails javascript and transformed into an openseadragon viewer. Openseadragon tile source options are passed as a JSON encoded hash on the data-openseadragon attribute.

Parameters:

  • sources (Array<String>, Array<Hash>)
  • source_tag_options (Hash)
  • picture_tag_options (Hash)

See Also:

  • Openseadragon::OpenseadragonHelper.[[#picture_tag]


46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/openseadragon/openseadragon_helper.rb', line 46

def openseadragon_picture_tag(*sources)
  picture_options = sources.extract_options!.symbolize_keys
  source_options = sources.extract_options!.symbolize_keys
  sources.flatten!

  tile_sources = sources.map { |thing| extract_openseadragon_picture_tilesource(thing) }
  
  picture_options[:data] ||= {}
  picture_options[:data][:openseadragon] = osd_asset_defaults.merge(picture_options[:data][:openseadragon] || {}).to_json

  picture_tag [tile_sources], { media: 'openseadragon' }.merge(source_options), picture_options
end

#picture_tag(*sources) ⇒ Object

Generate a <picture> tag containing the given sources. A source can be a simple string, or a hash with the key for the value of the src attribute and the value as the arguments for the tag options.

The last hash is intepreted as optional arguments for the <picture> tag. The second to last hash is optional arguments to all <source> tags.

Parameters:

  • sources (Array<String>, Array<Hash>)
  • source_tag_options (Hash)
  • picture_tag_options (Hash)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/openseadragon/openseadragon_helper.rb', line 16

def picture_tag *sources
  picture_options = sources.extract_options!.symbolize_keys
  source_options = sources.extract_options!.symbolize_keys
  sources.flatten!
   :picture, picture_options do
    safe_join(sources.map do |source|
      tag_options =  if source.is_a? Hash
        src, src_options = source.first
        src_options ||= {}
        source_options.merge(src_options.merge(src: src))
      else  
        source_options.merge(src: source)
      end
      
      yield tag_options if block_given?
      tag :source, tag_options
    end)
  end
end