Sha256: 2cc3399210d5c5ca13ceba4054319892e6a9288cced2bc650fcdde9be056311f

Contents?: true

Size: 1.87 KB

Versions: 9

Compression:

Stored size: 1.87 KB

Contents

module Onebox
  module Engine
    class GooglePhotosOnebox
      include Engine
      include StandardEmbed

      matches_regexp(/^https?:\/\/(photos)\.(app\.goo\.gl|google\.com)/)
      always_https

      def to_html
        og = get_opengraph
        return video_html(og) if !og.video_secure_url.nil?
        return album_html(og) if !og.type.nil? && og.type == "google_photos:photo_album"
        return image_html(og) if !og.image.nil?
        nil
      end

      private

      def video_html(og)
        <<-HTML
            <video width='#{og.video_width}' height='#{og.video_height}' #{og.title_attr} poster="#{og.get_secure_image}" controls loop>
              <source src='#{og.video_secure_url}' type='video/mp4'>
            </video>
          HTML
      end

      def album_html(og)
        escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)
        album_title = og.description.nil? ? og.title : "[#{og.description}] #{og.title}"

        <<-HTML
            <div class='onebox google-photos-album'>
              <a href='#{escaped_url}' target='_blank'>
                <span class='outer-box' style='width:#{og.image_width}px'>
                  <span class='inner-box'>
                    <span class='album-title'>#{Onebox::Helpers.truncate(album_title, 80)}</span>
                  </span>
                </span>
                <img src='#{og.get_secure_image}' #{og.title_attr} height='#{og.image_height}' width='#{og.image_width}'>
              </a>
            </div>
          HTML
      end

      def image_html(og)
        escaped_url = ::Onebox::Helpers.normalize_url_for_output(url)

        <<-HTML
            <a href='#{escaped_url}' target='_blank' class="onebox">
              <img src='#{og.get_secure_image}' #{og.title_attr} alt='Google Photos' height='#{og.image_height}' width='#{og.image_width}'>
            </a>
          HTML
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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