Class: RGhost::Callback

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

Overview

Callbacks are custom code blocks defined inside of Document. All callbacks received implicitly a instance of PsFacade can be creates any PsObject. The callbacks’s execution depend of the algorithims predefined in Postscript core library. There are two kind of callbacks, Statics and Dynamics callbacks. A Static callback there aren’t parameters to control of the inclusion and exception on current scope, usually applied for events which happen one time, for example after_document_create, “after document create” always will execute one time for each document. Otherwise Dynamic callbacks there is control of scope using conditional :only or :except, this is only difference in relation the static callbacks. The parameters of a Dynamic callbak must be one integer or one array of integer. Example: For all pages except page 3

doc.before_page_create :except => 3 do |b|
    # do something
end

For just 2 and 4 pages

doc.before_page_create :only => [2,4] do |b|
    # do something
end

The most of callbacks are defined in facades such as DocumentCallbackFacade and Grid::CallbackFacade

Instance Attribute Summary collapse

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(name, options = {}, &block) ⇒ Callback

Returns a new instance of Callback.



27
28
29
30
31
32
33
34
# File 'lib/rghost/callback.rb', line 27

def initialize(name,options={},&block)
  
  super(""){}
  set RGhost::PsFacade.new(&block) if block
  @name=name
  @options=options
  
end

Instance Attribute Details

#exceptObject

Returns the value of attribute except.



24
25
26
# File 'lib/rghost/callback.rb', line 24

def except
  @except
end

#nameObject

Returns the value of attribute name.



24
25
26
# File 'lib/rghost/callback.rb', line 24

def name
  @name
end

#onlyObject

Returns the value of attribute only.



24
25
26
# File 'lib/rghost/callback.rb', line 24

def only
  @only
end

Instance Method Details

#psObject



36
37
38
39
40
41
42
43
# File 'lib/rghost/callback.rb', line 36

def ps
  
  @only=num_to_array(@options[:only]) 
  @except=num_to_array(@options[:except])

  "\n/#{@name} 3 dict def #{@name} begin \n/proc { #{super} } bind def \n/except #{to_array(@except)} def \n/only #{to_array(@only)} def \nend "
  
end