Module: AttacheClient::ViewHelper

Defined in:
lib/attache_client.rb

Constant Summary collapse

ATTACHE_UPLOAD_URL =
ENV.fetch('ATTACHE_UPLOAD_URL')   { 'http://localhost:9292/upload' }
ATTACHE_DOWNLOAD_URL =
ENV.fetch('ATTACHE_DOWNLOAD_URL') { 'http://localhost:9292/view' }

Instance Method Summary collapse

Instance Method Details

#attache_options(geometry, current_value) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/attache_client.rb', line 19

def attache_options(geometry, current_value)
  {
    class: 'enable-attache',
    data: {
      geometry: geometry,
      value: [*current_value],
      uploadurl: ATTACHE_UPLOAD_URL,
      downloadurl: ATTACHE_DOWNLOAD_URL,
    },
  }
end

#attache_urls(json, geometry) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/attache_client.rb', line 8

def attache_urls(json, geometry)
  array = json.kind_of?(Array) ? json : [*json]
  array.collect do |path|
    download_url = ATTACHE_DOWNLOAD_URL
    prefix, basename = File.split(path)
    [download_url, prefix, CGI.escape(geometry), basename].join('/').tap do |url|
      yield url if block_given?
    end
  end
end