cssmodules

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 8 Imported by: 1

README

CSS Modules in Go

With this library you can parse any CSS that you have and get some key-value pairs with your classes and the scoped classes

  • Installation:
  1. Create a new directory and initialize a go project with the following commands:
$ mkdir my-directory
$ cd my-directory
$ go mod init my-directory
go: creating new go.mod: module my-directory
  1. Execute this command in your terminal and you are ready to go with CSS Modules:
$ go get github.com/otaxhu/go-cssmodules
  • Quick usage:
package main

import (
    "log"
    "os"
    "strings"

    "github.com/otaxhu/go-cssmodules"
)

func main() {
    myCSS := strings.NewReader(
`.my-class {color: red;}`,
)
    // Now you have your cssScoped and you can access your classes throught 
    // the scopedClasses variable
    cssProcessed, scopedClasses, err := cssmodules.ProcessCSSModules(myCSS)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("your css processed: %s\nmy-class generated name: %s", cssProcessed, scopedClasses["my-class"])
    // Output in Stdout will be something like this:
    //
    // your css processed: .RANDOMCLASS{color: red;}
    // my-class generated name: RANDOMCLASS
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCSSModules = errors.New("go-cssmodules: the input css cannot be converted to css modules")

	ErrUnexpectedError = errors.New("go-cssmodules: appears to happen an unexpected error")
)

Functions

func ProcessCSSModules

func ProcessCSSModules(css io.Reader) ([]byte, map[string]string, error)

Process the CSS and returns the css processed, the key-value pair of the classes and scoped classes, and an error if there is one

Types

This section is empty.

Jump to

Keyboard shortcuts

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