You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
551B

  1. require 'builder'
  2. module DHE
  3. class SvgFile
  4. attr_reader :has_text, :path, :content
  5. def initialize(path:, width:, height:, has_text: false, **options)
  6. @path = path.sub_ext('.svg')
  7. @has_text = has_text
  8. @content = Builder::XmlMarkup.new(indent: 2).svg(version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: width, height: height, **options) {|svg| yield(svg)}
  9. end
  10. def write(dir)
  11. file_path = dir / path
  12. file_path.parent.mkpath
  13. file_path.open('w') {|file| file.write @content}
  14. end
  15. end
  16. end