Sha256: 80e48df8966188df30c2a0cfeed513a041360c5a3d4a4ddcbba0f6936ba9a3d5

Contents?: true

Size: 941 Bytes

Versions: 2

Compression:

Stored size: 941 Bytes

Contents

module Prawn
  class Document
    def span(width, options={})
      Prawn.verify_options [:position], options
      original_position = self.y      
      
      # FIXME: How many effing times do I want to write this same code?
      left_boundary = case(options[:position] || :left)
      when :left
        margin_box.absolute_left
      when :center
        margin_box.absolute_left + margin_box.width / 2.0 - width /2.0
      when :right
        margin_box.absolute_right - width
      when Numeric
        margin_box.absolute_left + options[:position]
      else
        raise ArgumentError, "Invalid option for :position"
      end
      
      # we need to bust out of whatever nested bounding boxes we're in.
      canvas do
        bounding_box([left_boundary, 
                      margin_box.absolute_top], :width => width) do
          self.y = original_position
          yield
        end
      end          
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
satoko-prawn-0.2.99.6 lib/prawn/document/span.rb
prawn-0.2.1 lib/prawn/document/span.rb