diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-02-08 19:57:23 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-02-10 10:42:05 +0100 |
commit | 40ba7e6d63c1a0734f257a642e46eb1572116a32 (patch) | |
tree | 353656e6abe8fd3be064fe74bd9cd55ff2c108b8 /resources | |
parent | 4f43c9022a5bd0e7ac4af6b989c9af0ff3659708 (diff) |
Update to LibSass v3.6.3
Fixes #6862
Diffstat (limited to 'resources')
-rw-r--r-- | resources/resource.go | 22 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/scss/client.go | 40 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/scss/client_extended.go | 58 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/scss/client_notavailable.go (renamed from resources/resource_transformers/tocss/scss/tocss_notavailable.go) | 12 | ||||
-rw-r--r-- | resources/resource_transformers/tocss/scss/tocss.go | 29 |
5 files changed, 104 insertions, 57 deletions
diff --git a/resources/resource.go b/resources/resource.go index d206c17b5..acdf2d744 100644 --- a/resources/resource.go +++ b/resources/resource.go @@ -22,6 +22,10 @@ import ( "path/filepath" "sync" + "github.com/gohugoio/hugo/resources/internal" + + "github.com/gohugoio/hugo/common/herrors" + "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/media" @@ -95,6 +99,24 @@ type Transformer interface { Transform(...ResourceTransformation) (ResourceTransformer, error) } +func NewFeatureNotAvailableTransformer(key string, elements ...interface{}) ResourceTransformation { + return transformerNotAvailable{ + key: internal.NewResourceTransformationKey(key, elements...), + } +} + +type transformerNotAvailable struct { + key internal.ResourceTransformationKey +} + +func (t transformerNotAvailable) Transform(ctx *ResourceTransformationCtx) error { + return herrors.ErrFeatureNotAvailable +} + +func (t transformerNotAvailable) Key() internal.ResourceTransformationKey { + return t.key +} + type baseResourceResource interface { resource.Cloner resource.ContentProvider diff --git a/resources/resource_transformers/tocss/scss/client.go b/resources/resource_transformers/tocss/scss/client.go index ddf51f7fe..9309e3fe5 100644 --- a/resources/resource_transformers/tocss/scss/client.go +++ b/resources/resource_transformers/tocss/scss/client.go @@ -14,17 +14,16 @@ package scss import ( - "github.com/bep/go-tocss/scss" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugolib/filesystems" "github.com/gohugoio/hugo/resources" - "github.com/gohugoio/hugo/resources/internal" - "github.com/gohugoio/hugo/resources/resource" "github.com/spf13/afero" "github.com/mitchellh/mapstructure" ) +const transformationName = "tocss" + type Client struct { rs *resources.Spec sfs *filesystems.SourceFilesystem @@ -61,41 +60,6 @@ type Options struct { EnableSourceMap bool } -type options struct { - // The options we receive from the end user. - from Options - - // The options we send to the SCSS library. - to scss.Options -} - -func (c *Client) ToCSS(res resources.ResourceTransformer, opts Options) (resource.Resource, error) { - internalOptions := options{ - from: opts, - } - - // Transfer values from client. - internalOptions.to.Precision = opts.Precision - internalOptions.to.OutputStyle = scss.OutputStyleFromString(opts.OutputStyle) - - if internalOptions.to.Precision == 0 { - // bootstrap-sass requires 8 digits precision. The libsass default is 5. - // https://github.com/twbs/bootstrap-sass/blob/master/README.md#sass-number-precision - internalOptions.to.Precision = 8 - } - - return res.Transform(&toCSSTransformation{c: c, options: internalOptions}) -} - -type toCSSTransformation struct { - c *Client - options options -} - -func (t *toCSSTransformation) Key() internal.ResourceTransformationKey { - return internal.NewResourceTransformationKey("tocss", t.options.from) -} - func DecodeOptions(m map[string]interface{}) (opts Options, err error) { if m == nil { return diff --git a/resources/resource_transformers/tocss/scss/client_extended.go b/resources/resource_transformers/tocss/scss/client_extended.go new file mode 100644 index 000000000..2265e455e --- /dev/null +++ b/resources/resource_transformers/tocss/scss/client_extended.go @@ -0,0 +1,58 @@ +// Copyright 2018 The Hugo Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +build extended + +package scss + +import ( + "github.com/bep/golibsass/libsass" + "github.com/gohugoio/hugo/resources" + "github.com/gohugoio/hugo/resources/internal" + "github.com/gohugoio/hugo/resources/resource" +) + +type options struct { + // The options we receive from the end user. + from Options + + // The options we send to the SCSS library. + to libsass.Options +} + +func (c *Client) ToCSS(res resources.ResourceTransformer, opts Options) (resource.Resource, error) { + internalOptions := options{ + from: opts, + } + + // Transfer values from client. + internalOptions.to.Precision = opts.Precision + internalOptions.to.OutputStyle = libsass.ParseOutputStyle(opts.OutputStyle) + + if internalOptions.to.Precision == 0 { + // bootstrap-sass requires 8 digits precision. The libsass default is 5. + // https://github.com/twbs/bootstrap-sass/blob/master/README.md#sass-number-precision + internalOptions.to.Precision = 8 + } + + return res.Transform(&toCSSTransformation{c: c, options: internalOptions}) +} + +type toCSSTransformation struct { + c *Client + options options +} + +func (t *toCSSTransformation) Key() internal.ResourceTransformationKey { + return internal.NewResourceTransformationKey(transformationName, t.options.from) +} diff --git a/resources/resource_transformers/tocss/scss/tocss_notavailable.go b/resources/resource_transformers/tocss/scss/client_notavailable.go index ad6b42b98..a73280ccc 100644 --- a/resources/resource_transformers/tocss/scss/tocss_notavailable.go +++ b/resources/resource_transformers/tocss/scss/client_notavailable.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Hugo Authors. All rights reserved. +// Copyright 2020 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ package scss import ( - "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/resources" + "github.com/gohugoio/hugo/resources/resource" ) +func (c *Client) ToCSS(res resources.ResourceTransformer, opts Options) (resource.Resource, error) { + return res.Transform(resources.NewFeatureNotAvailableTransformer(transformationName, opts)) +} + // Used in tests. func Supports() bool { return false } - -func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx) error { - return herrors.ErrFeatureNotAvailable -} diff --git a/resources/resource_transformers/tocss/scss/tocss.go b/resources/resource_transformers/tocss/scss/tocss.go index ad581d681..a776b9f3b 100644 --- a/resources/resource_transformers/tocss/scss/tocss.go +++ b/resources/resource_transformers/tocss/scss/tocss.go @@ -22,9 +22,7 @@ import ( "path/filepath" "strings" - "github.com/bep/go-tocss/scss" - "github.com/bep/go-tocss/scss/libsass" - "github.com/bep/go-tocss/tocss" + "github.com/bep/golibsass/libsass" "github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/hugofs" "github.com/gohugoio/hugo/media" @@ -67,6 +65,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx // We add the entry directories for both project and themes to the include paths list, but // that only work for overrides on the top level. options.to.ImportResolver = func(url string, prev string) (newUrl string, body string, resolved bool) { + // We get URL paths from LibSASS, but we need file paths. url = filepath.FromSlash(url) prev = filepath.FromSlash(prev) @@ -74,6 +73,7 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx var basePath string urlDir := filepath.Dir(url) var prevDir string + if prev == "stdin" { prevDir = baseDir } else { @@ -121,18 +121,18 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx if options.from.EnableSourceMap { - options.to.SourceMapFilename = outName + ".map" - options.to.SourceMapRoot = t.c.rs.WorkingDir + options.to.SourceMapOptions.Filename = outName + ".map" + options.to.SourceMapOptions.Root = t.c.rs.WorkingDir // Setting this to the relative input filename will get the source map // more correct for the main entry path (main.scss typically), but // it will mess up the import mappings. As a workaround, we do a replacement // in the source map itself (see below). //options.InputPath = inputPath - options.to.OutputPath = outName - options.to.SourceMapContents = true - options.to.OmitSourceMapURL = false - options.to.EnableEmbeddedSourceMap = false + options.to.SourceMapOptions.OutputPath = outName + options.to.SourceMapOptions.Contents = true + options.to.SourceMapOptions.OmitURL = false + options.to.SourceMapOptions.EnableEmbedded = false } res, err := t.c.toCSS(options.to, ctx.To, ctx.From) @@ -161,18 +161,21 @@ func (t *toCSSTransformation) Transform(ctx *resources.ResourceTransformationCtx return nil } -func (c *Client) toCSS(options scss.Options, dst io.Writer, src io.Reader) (tocss.Result, error) { - var res tocss.Result +func (c *Client) toCSS(options libsass.Options, dst io.Writer, src io.Reader) (libsass.Result, error) { + var res libsass.Result transpiler, err := libsass.New(options) if err != nil { return res, err } - res, err = transpiler.Execute(dst, src) + in := helpers.ReaderToString(src) + res, err = transpiler.Execute(in) if err != nil { return res, errors.Wrap(err, "SCSS processing failed") } - return res, nil + _, err = io.WriteString(dst, res.CSS) + + return res, err } |