Class: RGhost::VirtualPages

Inherits:
PsObject show all
Includes:
RubyToPs
Defined in:
lib/rghost/virtual_pages.rb

Overview

Defines virtual pages for the Document by method virtual_pages

Constant Summary collapse

DEFAULT_OPTIONS =
{:width => 5, :margin_left => 0}

Instance Method Summary collapse

Methods included from RubyToPs

#array_to_stack, #hash_to_array, #pack_string, #ps_escape, #string_eval, #to_array, #to_bool, #to_string, #to_string_array

Methods inherited from PsObject

#<<, #call, #graphic_scope, #raw, #set, #to_s

Constructor Details

#initialize(&block) ⇒ VirtualPages

Returns a new instance of VirtualPages.



6
7
8
9
10
11
# File 'lib/rghost/virtual_pages.rb', line 6

def initialize(&block)
  super(''){}
  @pages=[]
  instance_eval(&block) if block

end

Instance Method Details

#new_page(options = RGhost::VirtualPages::DEFAULT_OPTIONS) ⇒ Object



13
14
15
16
17
# File 'lib/rghost/virtual_pages.rb', line 13

def new_page(options=RGhost::VirtualPages::DEFAULT_OPTIONS)
  options.merge(RGhost::VirtualPages::DEFAULT_OPTIONS)
  
  @pages << options
end

#psObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rghost/virtual_pages.rb', line 19

def ps
  first=true
  all_pages=@pages.map do |p| 
    w=RGhost::Units::parse(p[:width]) 
    if first
      first=false
      "[#{w}]"
    else
      m=RGhost::Units::parse(p[:margin_left])
      
      "[#{w} #{m}]"
      
    end
    #"[#{m} #{w}]"
  end
  o=RGhost::PsObject.new
  o.set RGhost::Variable.new(:has_vp?, true)
  o.raw "/vp_params [ #{all_pages.join('')} ] def "
  o.call :vp_proc
  o
  
end