renderer

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaQuery

type MediaQuery struct {
	Condition     string     // The @media condition (e.g., "(max-width: 600px)")
	ParentSelName string     // The parent selector context
	Children      []dst.Node // The declarations within the media query
	Depth         int        // The nesting depth
}

MediaQuery represents an @media block with its selector context

type NodeContext

type NodeContext struct {
	Buf *strings.Builder

	Node dst.Node

	Stack *Stack

	// SelNames should update by depth, for the root:
	// [a, b, p] ; with &.active; [a.active, b.active, p.active].
	// any more nested block nodes. If we kept
	// a parent Block (and a chain of parents), then
	// [a, b, p] + [&.active] should produce the resulting
	// css tree in a simple loop:
	//
	// result := []*Node
	// for _, v := range node.Names() {
	//    for _, j := range node.Children() {
	//       for _, y := range j.Names() {
	//           ctx := NodeContext{
	//               Depth: parentCtx.Depth+1,
	//               SelName: selector(v, y),
	//           }
	//           err := x.renderNode(ctx, j) // eventually render block
	//           if err != nil { // bubble up errors
	//           }
	//           result = append(result, r)
	//       }
	//    }
	// }
	SelName string
	BaseDir string // Base directory for resolving relative file paths
}

func (*NodeContext) Depth

func (n *NodeContext) Depth() int

type RenderInterface

type RenderInterface interface {
	Eval(nodes []dst.Node) []NodeContext
	Render(nodes []NodeContext) []byte
}

RenderInterface separates the responsibility to render the syntax tree into two steps. In the `Eval` step, the nested structures are traversed and then produce dst.Nodes with flattened CSS. The Render function is thus much more simpler, as it doesn't have to consider depth, but just prints a series of flattened *dst.Node values.

type Renderer

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

Renderer converts a DST into CSS output

func NewRenderer

func NewRenderer() *Renderer

NewRenderer creates a new CSS renderer

func (*Renderer) Render

func (r *Renderer) Render(file *dst.File) (string, error)

Render converts a File into CSS output, resolving variables and expressions

func (*Renderer) RenderWithBaseDir

func (r *Renderer) RenderWithBaseDir(file *dst.File, baseDir string) (string, error)

RenderWithBaseDir converts a File into CSS output with a base directory for file resolution

type Resolver

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

Resolver resolves variables and expressions in declarations for rendering

func NewResolver

func NewResolver(file *dst.File) *Resolver

NewResolver creates a new resolver from a file's variable stack

func (*Resolver) InterpolateVariables

func (r *Resolver) InterpolateVariables(stack *Stack, text string) string

InterpolateVariables replaces @{varname} patterns with their values from the stack This handles LESS variable interpolation syntax like .@{prefix} and @{prop}: value

func (*Resolver) ResolveValue

func (r *Resolver) ResolveValue(stack *Stack, value string) (string, error)

ResolveValue resolves a value string by substituting variables and evaluating expressions

type Stack

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

Stack represents a variable scope stack for managing variable lifetimes

func NewStack

func NewStack() *Stack

NewStack creates a new variable stack with a global scope

func (*Stack) All

func (s *Stack) All() map[string]string

All returns all variables visible in the current scope (including parent scopes)

func (*Stack) Any

func (s *Stack) Any() map[string]any

AllAny

func (*Stack) Depth

func (s *Stack) Depth() int

Depth returns the current stack depth

func (*Stack) Get

func (s *Stack) Get(name string) (string, bool)

Get retrieves a variable by searching from the current scope up to global scope

func (*Stack) GetGlobal

func (s *Stack) GetGlobal(name string) (string, bool)

GetGlobal retrieves a variable only from the global scope

func (*Stack) Pop

func (s *Stack) Pop()

Pop removes the top scope level from the stack

func (*Stack) Push

func (s *Stack) Push()

Push creates a new scope level on the stack

func (*Stack) Set

func (s *Stack) Set(name, value string)

Set sets a variable in the current (topmost) scope

func (*Stack) SetGlobal

func (s *Stack) SetGlobal(name, value string)

SetGlobal sets a variable in the global scope

Jump to

Keyboard shortcuts

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