Module: EmbedMe::CodeGenerator
- Includes:
- LinkHelper
- Defined in:
- lib/embed_me/code_generator.rb
Instance Method Summary collapse
-
#embed_code(options = {}) ⇒ Object
Generates some HTML code that allows embedding of the resource of the current request.
-
#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.
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):
()
# => "<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/" frameborder="0"
sandbox=""></iframe>"
(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/" 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 ( = {}) # get embed link or return if not present = return nil unless .present? # set values fallback = .delete(:fallback) || "Your Browser does not support HTML iFrame Element." default_html = {width: 560, height: 315, src: , frameborder: 0, sandbox: ''} default_html.merge!() # create element element = content_tag(: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 ( = {}) render "embed_me/embed_frontend" end |