Sha256: 947bac9c7f1cf9ccf51c8921aa44edf51736263026097a116afb18c7a2d32485

Contents?: true

Size: 1.25 KB

Versions: 14

Compression:

Stored size: 1.25 KB

Contents

# encoding: utf-8
module Prismic
  module Fragments
    class Image < Fragment
      attr_accessor :main, :views

      def initialize(main, views)
        @main = main
        @views = views
      end

      def as_html(link_resolver=nil)
        main.as_html(link_resolver)
      end

      def get_view(key)
        if key == 'main'
          main
        elsif @views.has_key?(key)
          views[key]
        else
          raise ViewDoesNotExistException
        end
      end

      class ViewDoesNotExistException < Error ; end

      class View < Fragment
        attr_accessor :url, :width, :height, :alt, :copyright, :link_to

        def initialize(url, width, height, alt, copyright, link_to)
          @url = url
          @width = width
          @height = height
          @alt = alt
          @copyright = copyright
          @link_to = link_to
        end

        def ratio
          return @width / @height
        end

        def as_html(link_resolver=nil)
          html = []
          html << (link_to.nil? ? '' : link_to.start_html(link_resolver))
          html << %(<img src="#@url" alt="#@alt" width="#@width" height="#@height" />)
          html << (link_to.nil? ? '' : link_to.end_html)
          html.join
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
prismic.io-1.2.1 lib/prismic/fragments/image.rb
prismic.io-1.2.0 lib/prismic/fragments/image.rb
prismic.io-1.1.1 lib/prismic/fragments/image.rb
prismic.io-1.1.0 lib/prismic/fragments/image.rb
prismic.io-1.0.9 lib/prismic/fragments/image.rb
prismic.io-1.0.8 lib/prismic/fragments/image.rb
prismic.io-1.0.7 lib/prismic/fragments/image.rb
prismic.io-1.0.6 lib/prismic/fragments/image.rb
prismic.io-1.0.5 lib/prismic/fragments/image.rb
prismic.io-1.0.4 lib/prismic/fragments/image.rb
prismic.io-1.0.3 lib/prismic/fragments/image.rb
prismic.io-1.0.2 lib/prismic/fragments/image.rb
prismic.io-1.0.1 lib/prismic/fragments/image.rb
prismic.io-1.0.0.rc10 lib/prismic/fragments/image.rb