Class: PrawndownExt::Interface::CommandInterface
- Inherits:
-
Object
- Object
- PrawndownExt::Interface::CommandInterface
- 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, ) }, "header1" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header2" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header3" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header4" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header5" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "header6" => -> (args,pdf, ) { cl_text_box(args, pdf, ) }, "newpage" => -> (args,pdf, ) { cl_newline(args, pdf, ) } }
Class Method Summary collapse
- .cl_img(args, pdf, options) ⇒ Object
- .cl_newline(args, pdf, options) ⇒ Object
- .cl_text(args, pdf, options) ⇒ Object
- .cl_text_box(args, pdf, options) ⇒ Object
Instance Method Summary collapse
Class Method Details
.cl_img(args, pdf, options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/prawndown-ext.rb', line 48 def self.cl_img args, pdf, if .key?("no_image") if ["no_image"] return end end if args["path"][0] == "/" args["path"] = args["path"][1..-1] end file = ["image_dir"] + "/" + args["path"] if !File.file?(file) file = "." + ["image_dir"] + "/" + args["path"] end if File.extname(file) != ".gif" pdf.image(file, width: pdf.bounds.width, position: :center) end end |
.cl_newline(args, pdf, options) ⇒ Object
72 73 74 |
# File 'lib/prawndown-ext.rb', line 72 def self.cl_newline args, pdf, pdf.start_new_page() end |
.cl_text(args, pdf, options) ⇒ Object
25 26 27 28 29 |
# File 'lib/prawndown-ext.rb', line 25 def self.cl_text args, pdf, pdf.text args["text"], inline_format: true, leading: ["default_line_spacing"].to_f end |
.cl_text_box(args, pdf, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/prawndown-ext.rb', line 31 def self.cl_text_box args, pdf, if !.key?(args["command"] + "_line_spacing") [args["command"] + "_line_spacing"] = 0 end if !.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: [args["command"] + "_line_spacing"].to_f end end end |
Instance Method Details
#exec(args, pdf, options) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/prawndown-ext.rb', line 77 def exec args, pdf, if args.key?("command") if COMMAND.include?(args["command"]) COMMAND[args["command"]].call(args, pdf, ) end end end |