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_the_curve-1.4.6 lib/caracal/core/tables.rb
caracal_the_curve-1.4.5 lib/caracal/core/tables.rb
caracal_the_curve-1.4.4 lib/caracal/core/tables.rb
caracal_the_curve-1.4.3 lib/caracal/core/tables.rb
caracal_the_curve-1.4.2 lib/caracal/core/tables.rb
caracal_the_curve-1.4.1 lib/caracal/core/tables.rb
caracal-1.4.1 lib/caracal/core/tables.rb
caracal-1.4.0 lib/caracal/core/tables.rb
caracal-1.3.0 lib/caracal/core/tables.rb
caracal-1.2.0 lib/caracal/core/tables.rb
caracal-1.1.2 lib/caracal/core/tables.rb
caracal-1.1.1 lib/caracal/core/tables.rb
caracal-1.1.0 lib/caracal/core/tables.rb
caracal-1.0.13 lib/caracal/core/tables.rb
caracal-1.0.12 lib/caracal/core/tables.rb
caracal-1.0.11 lib/caracal/core/tables.rb
caracal-1.0.10 lib/caracal/core/tables.rb
caracal-1.0.9 lib/caracal/core/tables.rb
caracal-1.0.8 lib/caracal/core/tables.rb
caracal-1.0.7 lib/caracal/core/tables.rb