repubmark/lib/repubmark/elems/iframe.rb

63 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Repubmark
module Elems
class Iframe < Base
parents :Canvas
attr_reader :title, :src, :url
def initialize(parent, title, src, url = nil)
super parent
self.title = title
self.src = src
self.url = url || src
end
#################
# Basic methods #
#################
def to_html
[
"<div#{html_class(:iframe_wrap)}>\n",
"<iframe\n",
%(title="#{title}"\n),
%(src="#{src}"\n),
%(allowfullscreen=""\n),
%(frameborder="0"\n),
%(sandbox="allow-same-origin allow-scripts allow-popups"\n),
"></iframe>\n",
"</div>\n",
].join.freeze
end
def to_gemtext = "=> #{url} #{title}\n"
private
def title=(title)
title = String(title).strip.freeze
raise 'Empty title' if title.empty?
@title = title
end
def src=(src)
src = String(src).strip.freeze
raise 'Empty src' if src.empty?
@src = src
end
def url=(url)
url = String(url).strip.freeze
raise 'Empty url' if url.empty?
@url = url
end
end
end
end