File: virtual_pages.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 (38 lines) | stat: -rw-r--r-- 881 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
32
33
34
35
36
37
38
# Defines virtual pages for the Document by method virtual_pages
class RGhost::VirtualPages < RGhost::PsObject
  DEFAULT_OPTIONS = {width: 5, margin_left: 0}
  include RGhost::RubyToPs
  def initialize(&block)
    super("") {}
    @pages = []
    instance_eval(&block) if block
  end

  def new_page(options = RGhost::VirtualPages::DEFAULT_OPTIONS)
    options.merge(RGhost::VirtualPages::DEFAULT_OPTIONS)

    @pages << options
  end

  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
end