Sha256: 33ec4c18e010858fa11edf5d574c0b4d5f142f732b29fc37d4daf7d3d60913e3

Contents?: true

Size: 994 Bytes

Versions: 11

Compression:

Stored size: 994 Bytes

Contents

module Onebox
  module Engine
    class TypeformOnebox
      include Engine

      matches_regexp(/^https?:\/\/[a-z0-9]+\.typeform\.com\/to\/[a-zA-Z0-9]+/)
      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
      alias placeholder_html to_html

      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

11 entries across 11 versions & 1 rubygems

Version Path
onebox-1.8.89 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.88 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.87 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.86 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.85 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.84 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.83 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.82 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.80 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.79 lib/onebox/engine/typeform_onebox.rb
onebox-1.8.78 lib/onebox/engine/typeform_onebox.rb