Class: PrawndownExt::Interface::CommandInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/prawndown-ext.rb

Constant Summary collapse

COMMAND =
{
	"text" => -> (args, pdf) { cl_text(args, pdf) },
	"img" => -> (args, pdf) { cl_img(args, pdf) },
	"quote" => -> (args,pdf) { cl_text_box(args, pdf) },
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cl_img(args, pdf) ⇒ Object



33
34
35
36
37
# File 'lib/prawndown-ext.rb', line 33

def self.cl_img args, pdf
	pdf.image(args["path"],
						width: pdf.bounds.width,
						position: :center)
end

.cl_text(args, pdf) ⇒ Object



18
19
20
21
22
# File 'lib/prawndown-ext.rb', line 18

def self.cl_text args, pdf

	pdf.text args["text"], inline_format: true
	
end

.cl_text_box(args, pdf) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/prawndown-ext.rb', line 24

def self.cl_text_box args, pdf
	pdf.pad args["margin"] do
		pdf.indent args["margin"], args["margin"] do
			pdf.text args["text"], inline_format: true
		end
	end
	
end

Instance Method Details

#exec(args, pdf) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/prawndown-ext.rb', line 40

def exec  args, pdf

	if args.key?("command")
		if COMMAND.include?(args["command"])
			COMMAND[args["command"]].call(args, pdf)
		end
	end
	
end