Sha256: c5812ea78d7e33f925782c7d03ed6c0dbce680c1f4dfd3c4cd1230e787762168

Contents?: true

Size: 1.19 KB

Versions: 37

Compression:

Stored size: 1.19 KB

Contents

require 'caracal/core/models/table_model'
require 'caracal/errors'


module Caracal
  module Core
    
    # This module encapsulates all the functionality related to adding tables
    # to the document.
    #
    module Tables
      def self.included(base)
        base.class_eval do
          
          #-------------------------------------------------------------
          # Public Methods
          #-------------------------------------------------------------
          
          def table(*args, &block)
            options = Caracal::Utilities.extract_options!(args)
            options.merge!({ data: args.first }) if args.first
            
            model = Caracal::Core::Models::TableModel.new(options, &block)
            if respond_to?(:page_width)
              container_width = page_width - page_margin_left - page_margin_right
              model.calculate_width(container_width)
            end
            
            if model.valid?
              contents << model
            else
              raise Caracal::Errors::InvalidModelError, 'Table must be provided data for at least one cell.'
            end
            model
          end
          
        end
      end
    end
    
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
caracal-1.0.6 lib/caracal/core/tables.rb
caracal-1.0.5 lib/caracal/core/tables.rb
caracal-1.0.4 lib/caracal/core/tables.rb
caracal-1.0.3 lib/caracal/core/tables.rb
caracal-1.0.2 lib/caracal/core/tables.rb
caracal-1.0.1 lib/caracal/core/tables.rb
caracal-1.0.0 lib/caracal/core/tables.rb
caracal-0.3.0 lib/caracal/core/tables.rb
caracal-0.2.1 lib/caracal/core/tables.rb
caracal-0.2.0 lib/caracal/core/tables.rb
caracal-0.1.8 lib/caracal/core/tables.rb
caracal-0.1.7 lib/caracal/core/tables.rb
caracal-0.1.6 lib/caracal/core/tables.rb
caracal-0.1.5 lib/caracal/core/tables.rb
caracal-0.1.4 lib/caracal/core/tables.rb
caracal-0.1.3 lib/caracal/core/tables.rb
caracal-0.1.2 lib/caracal/core/tables.rb