Class: Glib::Json::DynamicText::TextSpec
- Inherits:
-
Struct
- Object
- Struct
- Glib::Json::DynamicText::TextSpec
- Defined in:
- app/controllers/concerns/glib/json/dynamic_text.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#prop ⇒ Object
Returns the value of attribute prop.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
-
#image_server_url(blob_key) ⇒ Object
TODO: Reuse method from DynamicTextsHelper.
- #substitute_image_with(images) ⇒ Object
- #substitute_with(text) ⇒ Object
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args
98 99 100 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 98 def args @args end |
#prop ⇒ Object
Returns the value of attribute prop
98 99 100 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 98 def prop @prop end |
#view ⇒ Object
Returns the value of attribute 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 |