Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 13 additions & 14 deletions filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion filters/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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},
Expand Down