From d9d4735c64af7394112a6121084b48a959103659 Mon Sep 17 00:00:00 2001 From: Test User Date: Sun, 23 Nov 2025 07:47:30 +0800 Subject: [PATCH] feat: Implement sassify filter for indented Sass syntax Adds support for the `sassify` Liquid filter to convert indented Sass syntax to CSS, complementing the existing `scssify` filter. Implementation: - Added sassifyFilter function using Dart Sass with SourceSyntaxSASS - Reuses existing Sass transpiler singleton for efficiency - Removed now-unused unimplementedFilter helper and logger import - Added test case with proper indented Sass syntax - Updated README to remove sassify from missing features list Addresses #10 --- README.md | 1 - filters/filters.go | 27 +++++++++++++-------------- filters/filters_test.go | 3 ++- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 822cd734..2c7c6151 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 20b96006..b506bb92 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 acd24c91..8972acfb 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},