Class: Roebe::AllInOneShowcasingPrawn

Inherits:
Object
  • Object
show all
Includes:
Colours, Esystem
Defined in:
lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb

Overview

require ‘all_in_one_showcasing_prawn’; AllInOneShowcasingPrawn.new

Constant Summary collapse

THIS_PDF_FILE =
'/hello.pdf'
MAIN_PDF =
#

MAIN_PDF

#
'/home/x/programming/ruby/src/roebe/lib/roebe/yaml/main_pdf.yml'
SLATEBLUE =
#

Colour-related constants - these are currently wrong.

#
'6A5ACD'
CRIMSON =
'DC143C'
RED =
'FF0000'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(run_already = true) ⇒ AllInOneShowcasingPrawn

#

initialize

#


46
47
48
49
50
51
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 46

def initialize(
    run_already = true
  )
  reset
  run if run_already
end

Class Method Details

.return_random_imageObject

#

AllInOneShowcasingPrawn.return_random_image

#


71
72
73
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 71

def self.return_random_image # Right now we just return a hardcoded entry.
  '/home/x/data/images/NJOY/Torrie_Wilson.jpg' 
end

Instance Method Details

#consider_deleting_old_pdf_fileObject

#

consider_deleting_old_pdf_file

#


121
122
123
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 121

def consider_deleting_old_pdf_file
  File.delete(pdf_file?) if File.exist? pdf_file?
end

#generate_the_pdf_document(path_to_image = '/home/x/data/images/NJOY/Susanne_01.jpg') ⇒ Object

#

generate_the_pdf_document

#


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 78

def generate_the_pdf_document(
    path_to_image = '/home/x/data/images/NJOY/Susanne_01.jpg'
  )
  Prawn::Document.generate(pdf_file?, page_size: 'A4') {
    font 'Times-Roman'
    text 'Hello Prawn!'
    # pdf.image(path_to_dir, :width => 197, :height => 91)
    image path_to_image
    draw_text 'Hello World 1', at: [200,720], size: 32
    draw_text 'Hello World 2', at: [400,920], size: 28
    text 'Ruby in Red', color: 'FF0000'
    text 'Ruby in Red', color: '#FF0000'
    text 'Test', align: :center, color: SLATEBLUE
    text 'Test', align: :center, color: CRIMSON
    text 'Test', align: :center, color: RED
    indent(20) { text('yo') }
    indent(50) { text('yo') }
    start_new_page
    text 'Test', align: :center, color: RED
    text 'Test', align: :center, color: RED
    move_down 70
    text 'Test', :align => :center, color: RED
    text_box 'Your Text Here', align: :right
    add_page
    text_box 'Your Text Here', align: :right
    image(AllInOneShowcasingPrawn.return_random_image, width: 100, height: 100)
    add_page layout: :portrait
    text_box 'Your Text Here', align: :right
    bounding_box [100, 600], :width => 200 do
      move_down 15
      text 'the rain in spain ' * 5
      move_down 15
      stroke {
        line bounds.top_left, bounds.top_right
        line bounds.bottom_left, bounds.bottom_right
      }
    end
  }
end

#open_in_pdf_viewerObject

#

open_in_pdf_viewer

#


128
129
130
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 128

def open_in_pdf_viewer
  esystem use_this_pdf_viewer+' '+@pdf_file+' &' if File.exist? pdf_file?
end

#pdf_file?Boolean

#

pdf_file?

#

Returns:

  • (Boolean)


146
147
148
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 146

def pdf_file?
  @pdf_file
end

#report_what_we_will_doObject

#

report_what_we_will_do

#


63
64
65
66
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 63

def report_what_we_will_do
  opn; e 'Now generating file `'+sfile(pdf_file?)+
         '` (Filesize: '+simp(File.size(pdf_file?).to_s)+' Bytes).'
end

#resetObject

#

reset

#


56
57
58
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 56

def reset
  @pdf_file = THIS_PDF_FILE
end

#runObject

#

run (run tag)

#


153
154
155
156
157
158
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 153

def run
  consider_deleting_old_pdf_file
  generate_the_pdf_document
  report_what_we_will_do
  open_in_pdf_viewer
end

#use_this_pdf_viewerObject

#

use_this_pdf_viewer

#


135
136
137
138
139
140
141
# File 'lib/roebe/pdf/prawn/all_in_one_showcasing_prawn.rb', line 135

def use_this_pdf_viewer
  _ = 'okular'
  if File.exist? MAIN_PDF
    _ = File.read(MAIN_PDF).chomp
  end
  return _
end