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
205 stars 28 forks source link

Pass options to the libsass #42

Closed iamajoe closed 8 years ago

iamajoe commented 8 years ago

New function accepts options but I don't know how to pass options to the libsass. Is it something supported already?

drewwells commented 8 years ago

https://godoc.org/github.com/wellington/go-libsass#New ?

New accepts anything that returns Option as well like Path https://godoc.org/github.com/wellington/go-libsass#Path

Here's how it is used in the wellington project https://github.com/wellington/wellington/blob/master/build.go#L254-L267

iamajoe commented 8 years ago

Awesome, thanks for the example :) I'll try to figure it out now.

drewwells commented 8 years ago

These optional arguments follow the functional options pattern. There's a good rundown of it works here: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

iamajoe commented 8 years ago

I just can't figure out the SourceMap. Here is my code:

func (obj cssWriter) Write(p []byte) (n int, err error) {
    err = FileRemove(RemoveStruct{Src: obj.Dest})
    if err != nil {
        return
    }

    file, err := os.Create(obj.Dest)
    file.Write(p)
    return
}

comp, err := libsass.New(cssWriter{dest}, data,
        libsass.SourceMap(true, cssWriter{dest + ".map"}),
    )

Ideas on why?

drewwells commented 8 years ago

looks okay, I would check errors on file.Write()

any reason you don't pass a plain os.File?

df, _ := os.Create(dest)
mf, _ := os.Create(dest+".map")
comp, err := libsass.New(df, data,
        libsass.SourceMap(true, mf),
    )
iamajoe commented 8 years ago

Noobiness I guess. That is way better than what I have! Regarding the source map, now it creates the file (obviously) but nothing inside