Sha256: 6124f09a7d252f6608e08fcaf02c3fdaa552522268eda4f436958cb77c255a69

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

require "builder"

module SVGen
  class SVG
    include Nestable

    def initialize(attrs = {}, &block)
      @children = []
      @attrs = attrs
      block.call(self) if block_given?
    end

    def generate
      builder = Builder::XmlMarkup.new(indent: 2)
      builder.svg(@attrs.merge({ xmlns: "http://www.w3.org/2000/svg" })) do |svg|
        @children.each { |child| child.generate(svg) }
      end
    end

    def method_missing(name, *args)
      case name.to_s
      when /^(.+)=$/
        super unless value = args.first
        @attrs.has_key?($1) ? @attrs[$1] = value : @attrs[$1.to_sym] = value
      else
        @attrs[name] || @attrs[name.to_sym]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
svgen-0.1.1 lib/svgen/svg.rb