Class: Typst::Png
Instance Attribute Summary collapse
-
#pages ⇒ Object
Returns the value of attribute pages.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(input, root: ".", font_paths: []) ⇒ Png
constructor
A new instance of Png.
- #write(output) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(input, root: ".", font_paths: []) ⇒ Png
Returns a new instance of Png.
118 119 120 121 |
# File 'lib/typst.rb', line 118 def initialize(input, root: ".", font_paths: []) super(input, root: root, font_paths: font_paths) @pages = Typst::_to_png(self.input, self.root, self.font_paths, File.dirname(__FILE__), false, {}).collect{ |page| page.pack("C*").to_s } end |
Instance Attribute Details
#pages ⇒ Object
Returns the value of attribute pages.
116 117 118 |
# File 'lib/typst.rb', line 116 def pages @pages end |
Instance Method Details
#write(output) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/typst.rb', line 123 def write(output) if pages.size > 1 pages.each_with_index do |page, i| if output.include?("{{n}}") file_name = output.gsub("{{n}}", (i+1).to_s) else file_name = File.basename(output, File.extname(output)) + "_" + i.to_s file_name = file_name + File.extname(output) end File.open(file_name, "w"){ |f| f.write(page) } end elsif pages.size == 1 File.open(output, "w"){ |f| f.write(pages[0]) } else end end |