Class: AskAwesomely::Embeddable

Inherits:
Object
  • Object
show all
Defined in:
lib/ask_awesomely/embeddable.rb

Constant Summary collapse

EMBED_TYPES =
%i(
  modal
  drawer
  widget
  fullscreen
)
DEFAULT_OPTIONS =
{
  width: 800,
  height: 600,
  button_text: "Launch me!"
}

Instance Method Summary collapse

Constructor Details

#initialize(embed_type) ⇒ Embeddable

Returns a new instance of Embeddable.



17
18
19
20
21
22
23
# File 'lib/ask_awesomely/embeddable.rb', line 17

def initialize(embed_type)
  unless EMBED_TYPES.include?(embed_type)
    raise AskAwesomely::EmbedTypeError, "embed type must be one of: #{EMBED_TYPES.join(', ')}"
  end

  @embed_type = embed_type
end

Instance Method Details

#render(typeform, options = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/ask_awesomely/embeddable.rb', line 25

def render(typeform, options = {})
  locals = DEFAULT_OPTIONS
           .merge(options)
           .merge(public_url: typeform.public_url, title: typeform.title)
  Erubis::Eruby.new(template).result(locals)
end