sprite

package module
v0.0.0-...-6e9173d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2019 License: MIT Imports: 4 Imported by: 0

README

sprite

A library that takes in Icon interfaces and generates a sprite-map for them.

All go-icon libraries support the required interface.

Usage

package main

import "fmt"

import "gitea.com/go-icon/octicon"
import "gitea.com/go-icon/sprite"

func main() {
    m := sprite.New()
    
    for _, name := range octicon.Icons {
        m.Add(name, octicon.Icon(name))
    }
    
    if err := m.Parse(); err != nil {
        panic(err)
    }
    
    fmt.Println(m.XML())

}

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(icons map[string]Icon) (string, error)

Parse returns a sprite-map for a map of names->icons

Types

type Icon

type Icon interface {
	XML() string
}

An Icon represents any SVG icon Sprite can handle

type Map

type Map struct {
	URL   string
	Icons map[string]Icon
	// contains filtered or unexported fields
}

Map represents an SVG sprite-map

func New

func New() *Map

New returns a new Map

func (*Map) Add

func (m *Map) Add(name string, icon Icon)

Add adds an Icon to the Map

func (*Map) AddAll

func (m *Map) AddAll(icons map[string]Icon)

AddAll adds all icons in a map to the Map

func (*Map) Parse

func (m *Map) Parse() error

Parse attempts to parse the sprite-map's icons

func (m *Map) XLink(name string) *XLink

XLink returns a usable XLink for this Map

func (*Map) XML

func (m *Map) XML() string

XML returns parse xml if present, otherwise a text SVG with "No Icons"

type XLink struct {
	URL   string
	Name  string
	Class string
	Id    string
	Style string
}

XLink represents an XLink object for easy xlink generation

func (XLink) HTML

func (x XLink) HTML() template.HTML

HTML returns the XML in a template.HTML

func (XLink) XML

func (x XLink) XML() string

XML returns the formatted xlink

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL