Module: Glib::DynamicTextsHelper

Defined in:
app/helpers/glib/dynamic_texts_helper.rb

Instance Method Summary collapse

Instance Method Details

#dt(key, default_value = '', **args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/glib/dynamic_texts_helper.rb', line 3

def dt(key, default_value = '', **args)
  new_key = key
  options = {
    scope: args.fetch(:scope, 'itinerarybuilder'),
    lang: args.fetch(:lang, 'en')
  }

  if key.starts_with?('.')
    new_key = "#{controller_name}.#{action_name}#{key}"
  end

  content, text_object = Glib::Text.get_content(new_key, default_value, options: options)
  content.gsub(/\{\{(\w+)\}\}/) { args.fetch($1.to_sym, "{{#{$1}}}") }

  if text_object.images.attached?
    content.gsub(/\{\{image(\d)\}\}/) {
      if image = text_object.images[$1.to_i - 1]
        image_server_url(image.blob.key)
      else
        "{{image#{$1}}}"
      end
    }
  end
end

#dt_json(key, default_value = '', **args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/glib/dynamic_texts_helper.rb', line 28

def dt_json(key, default_value = '', **args)
  new_key = key

  if key.starts_with?('.')
    new_key = "#{controller_name}.#{action_name}#{key}"
  end

  {
    dt_key: new_key
  }.merge(args)
end

#image_server_url(blob_key, w: 100, h: 100) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/glib/dynamic_texts_helper.rb', line 40

def image_server_url(blob_key, w: 100, h: 100)
  return unless blob_key.present?

  uri = URI::HTTPS.build(
    host: 'imageserver-demo.herokuapp.com',
    path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
    query: { w: w, h: h }.to_param
  )

  uri.to_s
end