Sha256: 33d183c75f61c050c06d9f2f52e9dbd77e419e8b7d2127f015adf12f63393b5a

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Onebox
  module Engine
    class TypeformOnebox
      include Engine

      matches_regexp(/^https?:\/\/[a-z0-9\-_]+\.typeform\.com\/to\/[a-zA-Z0-9]+/)
      requires_iframe_origins "https://*.typeform.com"
      always_https

      def to_html
        typeform_src = build_typeform_src

        <<~HTML
          <iframe src="#{typeform_src}"
                  width="100%"
                  height="600px"
                  scrolling="no"
                  frameborder="0">
          </iframe>
        HTML
      end

      def placeholder_html
        ::Onebox::Helpers.generic_placeholder_html
      end

      private

      def build_typeform_src
        escaped_src = ::Onebox::Helpers.normalize_url_for_output(@url)
        query_params = CGI::parse(URI::parse(escaped_src).query || '')

        return escaped_src if query_params.has_key?('typeform-embed')

        if query_params.empty?
          escaped_src += '?' unless escaped_src.end_with?('?')
        else
          escaped_src += '&'
        end

        escaped_src += 'typeform-embed=embed-widget'
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
onebox-2.2.12 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.11 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.10 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.9 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.8 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.6 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.5 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.4 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.2 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.1 lib/onebox/engine/typeform_onebox.rb
onebox-2.2.0 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.9 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.8 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.7 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.6 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.5 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.4 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.3 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.2 lib/onebox/engine/typeform_onebox.rb
onebox-2.1.1 lib/onebox/engine/typeform_onebox.rb