Class: PrawndownExt::Interface::CommandInterface

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

Constant Summary collapse

COMMAND =
{
	"text" => -> (args, pdf, options) { cl_text(args, pdf, options) },
	"img" => -> (args, pdf, options) { cl_img(args, pdf, options) },
	"quote" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
	"header1" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
	"header2" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
	"header3" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
	"header4" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
	"header5" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
	"header6" => -> (args,pdf, options) { cl_text_box(args, pdf, options) },
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cl_img(args, pdf, options) ⇒ Object



47
48
49
50
51
# File 'lib/prawndown-ext.rb', line 47

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

.cl_text(args, pdf, options) ⇒ Object



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

def self.cl_text args, pdf, options

	pdf.text args["text"], inline_format: true, leading: options["default_line_spacing"].to_f
	
end

.cl_text_box(args, pdf, options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/prawndown-ext.rb', line 30

def self.cl_text_box args, pdf, options
	if !options.key?(args["command"] + "_line_spacing")
		options[args["command"] + "_line_spacing"] = 0
	end
	
	if !options.key?("margin")
		args["margin"] = 0
	end

	pdf.pad args["margin"] do
		pdf.indent args["margin"], args["margin"] do
			pdf.text args["text"], inline_format: true, leading: options[args["command"] + "_line_spacing"].to_f
		end
	end
	
end

Instance Method Details

#exec(args, pdf, options) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/prawndown-ext.rb', line 54

def exec args, pdf, options
	if args.key?("command")
		if COMMAND.include?(args["command"])

			COMMAND[args["command"]].call(args, pdf, options)
			
		end
	end
	
end