Pure Go CSS Preprocessor

GCSS - Pure Go CSS Preprocessor

wercker status Build status Coverage Status GoDoc ![Gitter](https://badges.gitter.im/Join Chat.svg)

Overview

GCSS is a pure Go CSS preprocessor. This is inspired by Sass and Stylus.

Syntax

Variables

$base-font: Helvetica, sans-serif
$main-color: blue

body
  font: 100% $base-font
  color: $main-color

Nesting

nav
  ul
    margin: 0
    padding: 0

a
  color: blue
  &:hover
    color: red

Mixins

$border-radius($radius)
  -webkit-border-radius: $radius
  -moz-border-radius: $radius
  -ms-border-radius: $radius
  border-radius: $radius

.box
  $border-radius(10px)

Installation

$ go get -u github.com/yosssi/gcss/...

Compile from the Command-Line

$ gcss /path/to/gcss/file

or

$ cat /path/to/gcss/file | gcss > /path/to/css/file

Compile from Go programs

You can compile a GCSS file from Go programs by invoking the gcss.CompileFile function.

cssPath, err := gcss.CompileFile("path_to_gcss_file")

if err != nil {
	http.Error(w, err.Error(), http.StatusInternalServerError)
	return
}

http.ServeFile(w, r, cssPath)

You can invoke the gcss.Compile function instead of the gcss.CompileFile function. The gcss.Compile function takes io.Writer and io.Reader as a parameter, compiles the GCSS data which is read from the io.Reader and writes the result CSS data to the io.Writer. Please see the GoDoc for the details.

f, err := os.Open("path_to_gcss_file")

if err != nil {
	panic(err)
}

defer func() {
	if err := f.Close(); err != nil {
		panic(err)
	}
}()

n, err := gcss.Compile(os.Stdout, f)

Documentation

Syntax Highlightings

  • vim-gcss - Vim syntax highlighting for GCSS
Owner
Comments
  • But why...?

    But why...?

    I don't get it... is this some project to show that Go can be used to do such things or was this really solving a pain point...? Why not just use execute an external program like lessc? Usually compiling from the sever side is done just once.. so am I missing something?

  • Allow variables in the middle of a statement

    Allow variables in the middle of a statement

    Using the following GCSS I have a $base-fonts variable I have some common fonts defined, and I have custom fonts before and after the variable. The problem is when the variable is surrounded by static items the variable seems to get skipped.

    GCSS file (surrounded variable)

    $color1: #2e6580
    $color2: #3a83a7
    $color3: #509ec4
    $color4: #75b3d2
    $color5: #9bc9df
    $base-fonts: 'Helvetica Neue', Helvetica, Arial
    
    h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6
      font-family: 'Droid Serif', $base-fonts, serif
      color: $color1
      a,a:hover,u
        color: $color1
        text-decoration: none
      small
        color: $color2
    
    body
      font-family: 'Roboto', $base-fonts, sans-serif
    
    footer
      margin-top: 10px
    

    Produces

    h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6 {
        font-family: 'Droid Serif', serif;
        color: #2e6580;
    }
    
    h1 a,h1 a:hover,h1 u,h2 a,h2 a:hover,h2 u,h3 a,h3 a:hover,h3 u,h4 a,h4 a:hover,h4 u,h5 a,h5 a:hover,h5 u,h6 a,h6 a:hover,h6 u,.h1 a,.h1 a:hover,.h1 u,.h2 a,.h2 a:hover,.h2 u,.h3 a,.h3 a:hover,.h3 u,.h4 a,.h4 a:hover,.h4 u,.h5 a,.h5 a:hover,.h5 u,.h6 a,.h6 a:hover,.h6 u {
        color: #2e6580;
        text-decoration: none;
    }
    
    h1 small,h2 small,h3 small,h4 small,h5 small,h6 small,.h1 small,.h2 small,.h3 small,.h4 small,.h5 small,.h6 small {
        color: #3a83a7;
    }
    
    body {
        font-family: 'Roboto', sans-serif;
    }
    
    footer {
        margin-top: 10px;
    }
    

    Removing the serif and sans-serif the $base-fonts works as expected.

  • include using text/templates.

    include using text/templates.

    Hello,

    Thanks for the great work. I have been using it for production for a while. However, I was wondering if you would consider introducing a way to import/include other gcss files, it will come extremely handy with Mixins specially.

    I think compiling/preprocessing* every gcss file first as text/template would be a good solution, so you can just basically do {{ template "mixinCollection" }}.

    Of course, using text/template would allow not only just including other templates but brings the complete power of Go templates in gcss. A bit of a madness be extremely powerful nonetheless.

    Preprocessing before preprocessing

  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

  • Todo

    Todo

    • [x] Create the command-line tool
    • [x] Create the syntax highlighters
      • [x] Vim
      • [x] ~~TextMate & SublimeText~~ //-> put off
    • [x] ~~Create the website of GCSS~~ //-> put off
    • [x] Implement the selector
    • [x] Implement the declaration
    • [x] Implement the at-rule
    • [x] Implement the mixin
    • [x] Implement the assignment
    • [x] Edit CompileBytes & check its comment
    • [x] Handling of the error return by bytes.Buffer.WriteString()
    • [x] Check the Sass's functions
    • [x] Comment
    • [x] ~~GCSS for a Web server~~ //-> canceled
    • [x] Add the race detector to the test
    • [x] Add e2e tests
    • [x] Return an error if a selector has a suffix of "{", "}" or a declaration has a suffix of ";"
    • [x] assign a variable to a mixin parameter
    • [x] selector has a single mixin
    • [x] font: 100% $font-stack
    • [x] at-rule, mixin
    • [x] Fix Compile: See http://www.reddit.com/r/golang/comments/2gkofb/yosssigcss_pure_go_css_preprocessor/
    • [x] CI which runs tests on Windows
  • Can't use media queries?!

    Can't use media queries?!

    Has anyone gotten media queries working with gcss? Any '@' rules I try to use just get striped.

    I've tried it with variables, nesting, and even just good'ol css.

  • Allow variables within parenthesis

    Allow variables within parenthesis

    Without space padding variables don't work within parentheses. If I pad them with spaces like this ( $url ) they work though.

    GCSS:

    $image-url: ../image/svg/footer.svg
    
    $background-mixin($url)
      background-image: url($url)
    
    #background
      $background-mixin($image-url)
    

    EXPECTED: #background{background-image:url(../image/svg/footer.svg);}

    ACTUAL: #background{background-image:url($url);}

  • Various parsing bugs.

    Various parsing bugs.

    max-width: 100% will not parse and produces: max-width: 100%! (MISSING).

    display:block will not parse and produces no output. spaces should not necessarily be required between rules but if they are, surely this should throw an error.

  • Allow use of @apply in gcss

    Allow use of @apply in gcss

    I'm trying to use Gcss with polymer and some of the components require the use @apply in the CSS. Currently gcss strips these tags out when compiled. It would be helpful if when compiling gcss would ignore such tags.

    To see an example of how these are used see https://github.com/PolymerElements/iron-flex-layout/blob/master/demo/x-app.html

    Example gcss file

    html, body
      height: 100%
    
    body
      margin: 0
    
    :host
      @apply(--layout-horizontal)
      @apply(--paper-font-body2)
    
    [nav]
      @apply(--layout-vertical)
      width: 200px
      background-color: var(--paper-grey-300)
    

    Generated css

    html,body{height:100%;}body{margin:0;}[nav]{width:200px;background-color:var(--paper-grey-300);}
    
  • @import external stylesheets

    @import external stylesheets

    Hi,

    I'm trying to reference an external stylesheet from GCSS. Can it be done? Is there a way?

    $font: 'Lato'
    @import url("//fonts.googleapis.com/css?family=" + $font)
    
    body
      font-family: $font, sans-serif
    

    Best regards, Aleander Rødseth

Related tags
Simple in Pure Go in Browser Interactive Interpreter
Simple in Pure Go in Browser Interactive Interpreter

GoBook This project is a PoC Don't take it seriously The main point of this project is the use of the library: github.com/brendonmatos/golive Maybe th

Feb 22, 2022
A pure Golang implementation of Rockchip rknand vendor storage interface.

go-rkvendorstorage A pure Golang implementation of Rockchip rknand vendor storage interface. Usage package main import ( "fmt" "github.com/jamesits

Nov 8, 2022
HTML, CSS and SVG static renderer in pure Go

Web render This module implements a static renderer for the HTML, CSS and SVG formats. It consists for the main part of a Golang port of the awesome W

Apr 19, 2022
A simple CSS parser and inliner in Go

douceur A simple CSS parser and inliner in Golang. Parser is vaguely inspired by CSS Syntax Module Level 3 and corresponding JS parser. Inliner only p

Dec 12, 2022
Super fast static photo and video gallery generator (written in Go and HTML/CSS/native JS)

fastgallery Fast static photo and video gallery generator Super fast (written in Go and C, concurrent, uses fastest image/video libraries, 4-8 times f

Dec 4, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electr

Jan 9, 2023
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Go bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Attention The ownership of project is tra

Dec 23, 2022
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)
Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs)

gowd Build cross platform GUI apps with GO and HTML/JS/CSS (powered by nwjs) How to use this library: Download and install nwjs Install this library g

Dec 11, 2022
go.rice is a Go package that makes working with resources such as html,js,css,images,templates, etc very easy.

go.rice go.rice is a Go package that makes working with resources such as html,js,css,images and templates easy. During development go.rice will load

Dec 29, 2022
Package damsel provides html outlining via css-selectors and common template functionality.

Damsel Markup language featuring html outlining via css-selectors, extensible via pkg html/template and others. Library This package expects to exist

Oct 23, 2022
A simple CSS parser and inliner in Go

douceur A simple CSS parser and inliner in Golang. Parser is vaguely inspired by CSS Syntax Module Level 3 and corresponding JS parser. Inliner only p

Dec 12, 2022
:link: Generate HTML and CSS together, on the fly
:link: Generate HTML and CSS together, on the fly

On The Fly Package for generating HTML and CSS together, on the fly. Can also be used for generating HTML, XML or CSS (or templates). HTML and CSS can

Oct 12, 2022
Frongo is a Golang package to create HTML/CSS components using only the Go language.

Frongo Frongo is a Go tool to make HTML/CSS document out of Golang code. It was designed with readability and usability in mind, so HTML objects are c

Jul 29, 2021
VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients
VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients

VMail - check the markup (HTML, CSS) of HTML email template compatibility with email clients Email clients use different rendering standards. This is

Dec 17, 2022
Minimal bundling for projects that require generation (e.g. SASS to CSS)

staticgen staticgen is a tool that generates file bundles and watches directories for changes. Configuration Project configurations are specified in t

Dec 14, 2021
Cascadia package implements CSS selectors
Cascadia package implements CSS selectors

cascadia The Cascadia package implements CSS selectors for use with the parse tr

Jan 2, 2023
A hello world project with NES.css and Netlify Functions

A hello world project powered by NES.css and Netlify Functions. The frontend part is a simple HTML page showing a progress bar. The input is received

Jan 9, 2022
Remarkable css - Remarkable Changing Suspend Screen Service
Remarkable css - Remarkable Changing Suspend Screen Service

Remarkable Changing Suspend Screen Service reMarkable service to automatically d

Jan 30, 2022
Pure Go line editor with history, inspired by linenoise

Liner Liner is a command line editor with history. It was inspired by linenoise; everything Unix-like is a VT100 (or is trying very hard to be). If yo

Jan 3, 2023
Pure Go termbox implementation

IMPORTANT This library is somewhat not maintained anymore. But I'm glad that it did what I wanted the most. It moved people away from "ncurses" mindse

Dec 28, 2022