Module: EmbedMe::CodeGenerator

Includes:
LinkHelper
Defined in:
lib/embed_me/code_generator.rb

Instance Method Summary collapse

Methods included from LinkHelper

#current_page_embed_url, #embeddable_link_to, #embedded_link_available?, #merged_embedded

Instance Method Details

#embed_code(options = {}) ⇒ Object

Generates some HTML code that allows embedding of the resource of the current request. Creates an iframe element with the embed link as src attribute. HTML options can be customized. Returns a string.

Examples

Assuming the current request is ‘/’ (root):

embed_code()
# => "<iframe width="560" height="315" src="http://localhost:3000/embed" frameborder="0"
    sandbox="">Your Browser does not support HTML iFrame Element.</iframe>"

embed_code(fallback: "")
# => "<iframe width="560" height="315" src="http://localhost:3000/embed" frameborder="0"
    sandbox=""></iframe>"

embed_code(width: 760, height: 500)
# => "<iframe width="760" height="500" src="http://localhost:3000/embed" frameborder="0"
    sandbox="">Your Browser does not support HTML iFrame Element.</iframe>"

embed_code(width: nil, height: nil)
# => "<iframe src="http://localhost:3000/embed" frameborder="0" sandbox="">Your Browser
    does not support HTML iFrame Element.</iframe>"


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/embed_me/code_generator.rb', line 27

def embed_code(options = {})
  # get embed link or return if not present
  embed_url = current_page_embed_url
  return nil unless embed_url.present?

  # set values
  fallback = options.delete(:fallback) || "Your Browser does not support HTML iFrame Element."
  default_html = {width: 560, height: 315, src: embed_url, frameborder: 0, sandbox: ''}
  default_html.merge!(options)

  # create element
  element = (:iframe, fallback, default_html)
  "#{element}"
end

#embed_frontend(options = {}) ⇒ Object

Returns an HTML button to open a basic pop-up that allows the user of the web page to copy the embedding code. The default design can be overridden with a file at app/views/embed_me/_embed_frontend.html.erb.



45
46
47
# File 'lib/embed_me/code_generator.rb', line 45

def embed_frontend(options = {})
  render "embed_me/embed_frontend"
end