module Onebox module Engine class GoogleDocsOnebox include Engine class << self def supported_endpoints %w(spreadsheets document forms presentation) end def embed_widths @embed_widths ||= { spreadsheets: 800, document: 800, presentation: 960, forms: 760, } end def embed_heights @embed_heights ||= { spreadsheets: 600, document: 600, presentation: 749, forms: 500, } end def short_types @shorttypes ||= { spreadsheets: :sheets, document: :docs, presentation: :slides, forms: :forms, } end end matches_regexp /^(https?:)?\/\/(docs\.google\.com)\/(?(#{supported_endpoints.join('|')}))\/d\/((?[\w-]*)).+$/ always_https def to_html if document? "" elsif spreadsheet? "" elsif presentation? "" elsif forms? "" end end def placeholder_html <

Google #{shorttype.capitalize}

#{key}

HTML end protected def doc_type @doc_type ||= match[:endpoint].to_sym end def shorttype GoogleDocsOnebox.short_types[doc_type] end def width GoogleDocsOnebox.embed_widths[doc_type] end def height GoogleDocsOnebox.embed_heights[doc_type] end def spreadsheet? doc_type == :spreadsheets end def document? doc_type == :document end def presentation? doc_type == :presentation end def forms? doc_type == :forms end def key match[:key] end def match @match ||= @url.match(@@matcher) end end end end