Class: Typst::Svg

Inherits:
Base
  • Object
show all
Defined in:
lib/typst.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#font_paths, #input, #root

Instance Method Summary collapse

Methods inherited from Base

from_s, from_zip

Constructor Details

#initialize(input, root: ".", font_paths: []) ⇒ Svg

Returns a new instance of Svg.



92
93
94
95
# File 'lib/typst.rb', line 92

def initialize(input, root: ".", font_paths: [])
  super(input, root: root, font_paths: font_paths)
  @pages = Typst::_to_svg(self.input, self.root, self.font_paths, File.dirname(__FILE__))
end

Instance Attribute Details

#pagesObject

Returns the value of attribute pages.



90
91
92
# File 'lib/typst.rb', line 90

def pages
  @pages
end

Instance Method Details

#write(output) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/typst.rb', line 97

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