File: document_callback_facade.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 (63 lines) | stat: -rw-r--r-- 2,022 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# This module is included inside of Document class. It will creates methods to easy the use.
#===Callback execution order
# Example for a document with 4 pages, looking at the picture you can see the order in which the callbacks are executed
#
# link:images/pages_rghost.png

module RGhost::DocumentCallbackFacade
  # Executes before page create. Respond to :only and :except options
  def before_page_create(options = {}, &)
    new_dynamic_callback(:before_page_create, options, &)
  end

  # Executes after page create. Respond to :only and :except options
  def after_page_create(options = {}, &)
    new_dynamic_callback(:after_page_create, options, &)
  end

  # Executes on odd pages create. Respond to :only and :except options
  def odd_pages(options = {}, &)
    new_dynamic_callback(:odd_pages, options, &)
  end

  # Executes on even pages create. Respond to :only and :except options
  def even_pages(options = {}, &)
    new_dynamic_callback(:even_pages, options, &)
  end

  # Executes one time before document create.
  def before_document_create(&)
    new_static_callback(:before_document_create, &)
  end

  # Executes one time on first page.
  def first_page(&)
    new_static_callback(:first_page, &)
  end

  # Executes one time on last page(end of document).
  def last_page(&)
    new_static_callback(:last_page, &)
  end

  # Executes before virtual page create. Respond to :only and :except options
  def before_virtual_page_create(options = {}, &)
    new_dynamic_callback(:before_virtual_page_create, options, &)
  end

  # Executes after virtual page create. Respond to :only and :except options
  def after_virtual_page_create(options = {}, &)
    new_dynamic_callback(:after_virtual_page_create, options, &)
  end

  private

  def new_dynamic_callback(name, options = {}, &)
    @callbacks.set RGhost::Callback.new(name, options, &)
  end

  def new_static_callback(name, &)
    callback_body = RGhost::PsFacade.new(&)
    @callbacks.set RGhost::Function.new(name, callback_body)
  end
end