File: function.rb

package info (click to toggle)
ruby-rghost 0.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,188 kB
  • sloc: ruby: 3,374; makefile: 6; sh: 1
file content (31 lines) | stat: -rw-r--r-- 600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require "rghost/ps_object"

# Creates postscript internal function. Example
# f=RGhost::Function.new :foo do
#  set Show.new("A Test")
# end
# In ps stack will be
# /foo (A Test) show def
class RGhost::Function < RGhost::PsObject
  attr_reader :name

  def initialize(name, body_function = nil, &block)
    if block
      super(&block)
    else
      super("")
    end
    @name = name
    @body_function = body_function
  end

  def use_template(function_name)
    call "_#{function_name}"
  end

  def ps
    @body_function ||= super

    "\n/#{@name}{\n#{@body_function}\n} bind def \n"
  end
end