Sha256: 9b368a6a106b4a9f4bfca026dde6c27dc7cc68ff82d42a42b91e5900a16887fa

Contents?: true

Size: 1010 Bytes

Versions: 1

Compression:

Stored size: 1010 Bytes

Contents

require 'caracal/core/models/image_model'
require 'caracal/errors'


module Caracal
  module Core
    
    # This module encapsulates all the functionality related to adding
    # images to the document.
    #
    module Images
      def self.included(base)
        base.class_eval do
          
          #-------------------------------------------------------------
          # Public Methods
          #-------------------------------------------------------------
          
          def img(*text, **options, &block)
            text.flatten!            
            options.merge!( { url: text[0] })  unless text[0].nil?
            
            model = Caracal::Core::Models::ImageModel.new(options, &block)
            if model.valid?
              contents << model
            else
              raise Caracal::Errors::InvalidModelError, 'Images require an URL and positive size/margin values.'
            end
            model
          end
          
        end
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caracal-0.1.0 lib/caracal/core/images.rb