Class: Glib::Json::DynamicText::TextSpec

Inherits:
Struct
  • Object
show all
Defined in:
app/controllers/concerns/glib/json/dynamic_text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args

Returns:

  • (Object)

    the current value of args



98
99
100
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 98

def args
  @args
end

#propObject

Returns the value of attribute prop

Returns:

  • (Object)

    the current value of prop



98
99
100
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 98

def prop
  @prop
end

#viewObject

Returns the value of attribute view

Returns:

  • (Object)

    the current value of view



98
99
100
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 98

def view
  @view
end

Instance Method Details

#image_server_url(blob_key) ⇒ Object

TODO: Reuse method from DynamicTextsHelper



114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 114

def image_server_url(blob_key)
  return unless blob_key.present?

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

  uri.to_s
end

#substitute_image_with(images) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 103

def substitute_image_with(images)
  view[prop] = view[prop].gsub(/\{\{image(\d)\}\}/) {
    if image = images[$1.to_i - 1]
      image_server_url(image.blob.key)
    else
      "{{image#{$1}}}"
    end
  }
end

#substitute_with(text) ⇒ Object



99
100
101
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 99

def substitute_with(text)
  view[prop] = text.gsub(/\{\{(\w+)\}\}/) { args.fetch($1, "{{#{$1}}}") }
end