wellington / go-libsass

Go wrapper for libsass, the only Sass 3.5 compiler for Go
http://godoc.org/github.com/wellington/go-libsass
Apache License 2.0
206 stars 29 forks source link

Simple example of using go-libsass to compile SCSS to CSS #32

Open drewwells opened 8 years ago

drewwells commented 8 years ago

Should include simple examples of how to use go-libsass in custom projects

drewwells commented 8 years ago

@tboerger I saw your post on c6. If you're interested in compiling scss to css maybe check out go-libsass.

To compile scss to css with go-libsass

package main

import (
    "bytes"
    "log"
    "os"

    libsass "github.com/wellington/go-libsass"
)

func main() {
    buf := bytes.NewBufferString(`div { p { color: red; } }`)
    comp, _ := libsass.New(os.Stdout, buf)
    err := comp.Run()
    if err != nil {
        log.Fatal(err)
    }
}

There are many options for altering the compiler behavior listed here: https://github.com/wellington/go-libsass/blob/master/compiler.go#L56-L192

drewwells commented 8 years ago

@jpillora you seemed to have a similar desire to compile scss. This example of go-libsass may be helpful for you

tboerger commented 8 years ago

go-libsass is a nice library, but I really like the principle of c6 to be a pure go implementation :)

drewwells commented 8 years ago

Sure, it's a nice idea but sass is not a simple language to implement. Which is why c6 has stalled for so long. On the other side, there's a very good implementation in C to start from. Not to say it can't be implemented in Go eventually!

tboerger commented 8 years ago

I know that it's not simple... I'm using and following sass already for years :).

Maybe I can integrate go-libsass into Gogs.

drewwells commented 8 years ago

Watching libsass integrate every nook and cranny of Sass is a challenge. Though with the years of maintaining a go wrapper to the c library, I probably could have written a decent Sass parser by now.

I'm a fan of the attempts to implement partial language Sass (Sass the good parts?). Sadly, these seemed to have been abandoned and it's unlikely they'll support most of the common Sass frameworks due to corner cases in Sass.

Speaking of, there's a project in this repo with a working Scss/Sass lexer. I started off this project by working on a Sass lexer before fully switching to libsass https://github.com/wellington/sass/. If you're interested in working on a Sass parser, I could use help there. There's a yacc based parser, but the ambiguities in the language will prevent it from doing much. Bison's generalized grammar might get somewhere, but I think invariably Sass will require a parser built by hand.

drewwells commented 8 years ago

Feel free to reach out if you need help with gogs integration. There's also a cli tool which has examples of how to use go-libsass and adds additional functionality to Sass (like spriting).

tboerger commented 8 years ago

Sounds great, we will see how I can do it :)

drewwells commented 7 years ago

@tboerger I've begun work on a Pure Go compiler, it's nowhere near completion but can handle simple Sass compilation: https://github.com/wellington/sass

tboerger commented 7 years ago

@tboerger I've begun work on a Pure Go compiler, it's nowhere near completion but can handle simple Sass compilation: https://github.com/wellington/sass

That's really interesting!