writer

package
v0.0.0-...-475bae7 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

writer package contains Writer struct to write out gorilla css token stream.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dumps

func Dumps(tokens []*scanner.Token) (string, error)

Dump token slice to string

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer to write gorilla css token stream to a io.Writer.

Example
package main

import (
	"bytes"
	"fmt"

	"github.com/redforks/css-1/scanner"
	"github.com/redforks/css/writer"
)

func main() {
	css := `
		// comment
		.foo {
			color: white;
		}
		`
	s, buf := scanner.New(css), bytes.Buffer{}
	w := writer.New(&buf)
	for to := s.Next(); to.Type != scanner.TokenEOF; to = s.Next() {
		w.Write(to)
	}
	if err := w.Close(); err != nil {
		fmt.Print(err)
	} else {
		fmt.Print((string)(buf.Bytes()))
	}
}
Output:


		// comment
		.foo {
			color: white;
		}

func New

func New(w io.Writer) *Writer

Create a new Writer instance, must call .Close() after write out all tokens.

func (*Writer) Close

func (w *Writer) Close() error

Close() close the writer if it support io.Closer interface.

Must call .Close() even the writer do not need Close(). Because Writer.Write() method do not report error, the error returned when calling .Close().

func (*Writer) Write

func (w *Writer) Write(token *scanner.Token)

Write token out. Any error occurred will report on calling .Close() method. .Write() itself always succeed.

Jump to

Keyboard shortcuts

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