diff --git a/README.md b/README.md index 822cd73..2c7c615 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,6 @@ Missing features: - Pagination - Math - Plugin system. ([Some individual plugins](./docs/plugins.md) are emulated.) -- Liquid filter `sassify` is not implemented - Liquid is run in strict mode: undefined filters and variables are errors. - Missing markdown features: - [attribute lists](https://kramdown.gettalong.org/syntax.html#attribute-list-definitions) diff --git a/filters/filters.go b/filters/filters.go index 20b9600..b506bb9 100644 --- a/filters/filters.go +++ b/filters/filters.go @@ -17,7 +17,6 @@ import ( blackfriday "github.com/danog/blackfriday/v2" "github.com/osteele/gojekyll/config" "github.com/osteele/gojekyll/internal/sasserrors" - "github.com/osteele/gojekyll/logger" "github.com/osteele/gojekyll/utils" "github.com/osteele/liquid" "github.com/osteele/liquid/evaluator" @@ -122,7 +121,7 @@ func AddJekyllFilters(e *liquid.Engine, c *config.Config) { // string escapes e.RegisterFilter("cgi_escape", url.QueryEscape) - e.RegisterFilter("sassify", unimplementedFilter("sassify")) + e.RegisterFilter("sassify", sassifyFilter) e.RegisterFilter("scssify", scssifyFilter) e.RegisterFilter("smartify", smartifyFilter) e.RegisterFilter("uri_escape", func(s string) string { @@ -154,18 +153,6 @@ func requireNonEmptyArray(fn func([]interface{}) interface{}) func([]interface{} } } -func unimplementedFilter(name string) func(value interface{}) interface{} { - warned := false - log := logger.Default() - return func(value interface{}) interface{} { - if !warned { - log.Warn("unimplemented filter: %s", name) - warned = true - } - return value - } -} - // array filters func arrayToSentenceStringFilter(array []string, conjunction func(string) string) string { @@ -308,6 +295,18 @@ func getScssifyTranspiler() (*sass.Transpiler, error) { return scssifyTranspiler, scssifyTranspilerErr } +func sassifyFilter(s string) (string, error) { + comp, err := getScssifyTranspiler() + if err != nil { + return "", err + } + res, err := comp.Execute(sass.Args{ + Source: s, + SourceSyntax: sass.SourceSyntaxSASS, + }) + return res.CSS, err +} + func scssifyFilter(s string) (string, error) { comp, err := getScssifyTranspiler() if err != nil { diff --git a/filters/filters_test.go b/filters/filters_test.go index acd24c9..8972acf 100644 --- a/filters/filters_test.go +++ b/filters/filters_test.go @@ -60,7 +60,7 @@ var filterTests = []struct{ in, expected string }{ {`{{ "The _config.yml file" | slugify: 'default' }}`, "the-config-yml-file"}, {`{{ "The _config.yml file" | slugify: 'pretty' }}`, "the-_config.yml-file"}, - // {`{{ "nav\n\tmargin: 0" | sassify }}`, "nav {\n margin: 0; }"}, + {`{{ sass_code | sassify }}`, "nav {\n margin: 0;\n}"}, {`{{ "nav {margin: 0}" | scssify }}`, "nav {\n margin: 0;\n}"}, {`{{ "smartify single 'quotes' here" | smartify }}`, "smartify single ‘quotes’ here"}, @@ -86,6 +86,7 @@ var filterTestBindings = liquid.Bindings{ "page": map[string]interface{}{ "tags": []string{"Seattle", "Tacoma"}, }, + "sass_code": "nav\n margin: 0", "site": map[string]interface{}{ "members": []map[string]interface{}{ {"name": "Alonzo", "graduation_year": 2013},