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
27
28
# 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 = content.gsub(/\{\{(\w+)\}\}/) { args.fetch($1.to_sym, "{{#{$1}}}") }

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

  content
end

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



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

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