Sha256: 21edc5fe8ff4ad057451e8f269bc22cbc9e2b34972288ac532377eef5f7e2ec8

Contents?: true

Size: 595 Bytes

Versions: 3

Compression:

Stored size: 595 Bytes

Contents

require "savagery/spriter/image"

module Savagery
  class Spriter
    def initialize path
      self.path = path
    end

    attr_accessor :path

    def sprite!
      File.write sprite_path, sprite
    end

    private

    def sprite_path
      path + ".svg"
    end

    def sprite
      %(<svg data-savagery-path="#{sprite_path.split("/assets/svgs/").last}" style="display: none"><defs>\n\n#{symbols.join("\n")}\n</defs></svg>\n)
    end

    def symbols
      Image.from_paths(image_paths).map(&:symbol)
    end

    def image_paths
      Dir.glob(path + "/*.svg").sort
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
savagery-0.6.1 lib/savagery/spriter.rb
savagery-0.6.0 lib/savagery/spriter.rb
savagery-0.5.0 lib/savagery/spriter.rb