scarlet

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 8 Imported by: 1

README

scarlet

Godoc Report Tests Coverage Sponsor

Generates CSS from .scarlet files. Very similar to Stylus, but with higher compression.

Installation

go get -u github.com/aerogo/scarlet/...

CLI

If you're looking for the official compiler, please install pack.

The CLI tool included in this repo offers a check to see if your classes are referenced or not via scarlet -check.

Basic usage

body
	color black
	font-size 100%
	padding 1rem

State

a
	color blue

	:hover
		color red

Classes

a
	color blue

	// "active" elements inside a link
	.active
		color red

	// links that have the "active" class
	&.active
		color red

Multiple selectors

// All in one line
h1, h2, h3
	color orange

// Split over multiple lines
h4,
h5,
h6
	color purple

Variables

text-color = black
transition-speed = 200ms

body
	font-size 100%
	color text-color

a
	color blue
	transition color transition-speed ease
	
	:hover
		color red

Mixins

mixin horizontal
	display flex
	flex-direction row

mixin vertical
	display flex
	flex-direction column

Mixins can be used like this:

#sidebar
	vertical

Animations

animation rotate
	0%
		transform rotateZ(0)
	100%
		transform rotateZ(360deg)

animation pulse
	0%, 100%
		transform scale3D(0.4, 0.4, 0.4)
	50%
		transform scale3D(0.9, 0.9, 0.9)

Quick media queries

body
	vertical

> 800px
	body
		horizontal

Style

Please take a look at the style guidelines if you'd like to make a pull request.

Sponsors

Cedric Fung Scott Rayapoullé Eduard Urbach
Cedric Fung Scott Rayapoullé Eduard Urbach

Want to see your own name here?

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(reader io.Reader, pretty bool) (string, error)

Compile compiles the given scarlet code to a CSS string.

Types

type Animation

type Animation struct {
	Name      string
	Keyframes []*CSSRule
}

Animation ...

func (*Animation) Render

func (anim *Animation) Render(output *strings.Builder, pretty bool)

Render renders the animation to the output stream.

type CSSRule

type CSSRule struct {
	Selector   string
	Statements []*CSSStatement
	Duplicates []*CSSRule
	Parent     *CSSRule
}

CSSRule ...

func (*CSSRule) Copy

func (rule *CSSRule) Copy() *CSSRule

Copy ...

func (*CSSRule) Render

func (rule *CSSRule) Render(output *strings.Builder, pretty bool)

Render renders the CSS rule into the output stream.

func (*CSSRule) Root

func (rule *CSSRule) Root() *CSSRule

Root ...

func (*CSSRule) SelectorPath

func (rule *CSSRule) SelectorPath(pretty bool) string

SelectorPath returns the selector string for the rule (recursive, returns absolute path).

func (*CSSRule) StatementsHash

func (rule *CSSRule) StatementsHash() uint64

StatementsHash returns a hash of all the statements which is used to find duplicate CSS rules.

type CSSStatement

type CSSStatement struct {
	Property string
	Value    string
}

CSSStatement ...

type MediaGroup

type MediaGroup struct {
	Operator string
	Size     string
	Property string
	Rules    []*CSSRule
}

MediaGroup ...

func (*MediaGroup) Render

func (media *MediaGroup) Render(output *strings.Builder, pretty bool)

Render renders the media group to the output stream.

type MediaQuery

type MediaQuery struct {
	Selector string
	Rules    []*CSSRule
}

MediaQuery ...

func (*MediaQuery) Render

func (media *MediaQuery) Render(output *strings.Builder, pretty bool)

Render renders the media query to the output stream.

type Mixin

type Mixin struct {
	Root  *CSSRule
	Rules []*CSSRule
}

Mixin is a collection of CSS rules.

func (*Mixin) Apply

func (mixin *Mixin) Apply(parent *CSSRule) []*CSSRule

Apply ...

type Renderable

type Renderable interface {
	Render(*strings.Builder, bool)
}

Renderable represents anything that can be rendered into final output.

type State

type State struct {
	Variables map[string]string
	Constants map[string]string
	Mixins    map[string]*Mixin

	// To preserve the order of appearance, save the names in correct order
	VariableNames []string
}

State represents the whole compiler state.

func NewState

func NewState() *State

NewState creates a new compiler state.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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