Skip to content

Commit

Permalink
feature: empty compat macro
Browse files Browse the repository at this point in the history
  • Loading branch information
viperehonchuk committed Dec 6, 2023
1 parent 7688e25 commit 8edaf9e
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> 0.0001%
not dead
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# editorconfig-tools is unable to ignore longs strings or urls
max_line_length = null

[Makefile]
indent_style = tab
2 changes: 1 addition & 1 deletion original-content
Submodule original-content updated 106 files
1 change: 1 addition & 0 deletions revamp/preprocessors/src/helpers/render_html/div.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var tDiv *template.Template

type DivParams struct {
Class string
Data map[string]template.HTMLAttr
InnerHtml template.HTML
Text string
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<div class="{{.Class}}">{{if .InnerHtml}}{{.InnerHtml}}{{else}}{{.Text}}{{end}}</div>
<div class="{{.Class}}"
{{ range $key, $value := .Data }} data-{{ $key }}="{{ $value }}"{{ end }}
>{{if .InnerHtml}}{{.InnerHtml}}{{else}}{{.Text}}{{end}}</div>
39 changes: 39 additions & 0 deletions revamp/preprocessors/src/run-macros/macros/compat/compat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package compat

import (
"errors"
"html/template"
"strings"
renderhtml "webdoky3/revamp/preprocessors/src/helpers/render_html"
"webdoky3/revamp/preprocessors/src/run-macros/environment"
"webdoky3/revamp/preprocessors/src/run-macros/registry"
)

func Compat(env *environment.Environment, reg *registry.Registry, args string) (string, error) {
compatItems := []string{}
queries := env.Frontmatter.BrowserCompat
if len(queries) == 0 {
return "", errors.New("no browser compatibility queries found in frontmatter")
}
for _, query := range env.Frontmatter.BrowserCompat {
isMultiple := len(queries) > 1
multiple := ""
if isMultiple {
multiple = "multiple"
}
queryElement, err := renderhtml.RenderDiv(&renderhtml.DivParams{
Class: "bc-data",
Data: map[string]template.HTMLAttr{
"multiple": template.HTMLAttr(multiple),
"query": template.HTMLAttr(query),
"depth": template.HTMLAttr("1"),
},
Text: "If you're able to see this, something went wrong on this page.",
})
if err != nil {
return "", err
}
compatItems = append(compatItems, queryElement)
}
return strings.Join(compatItems, "\n"), nil
}
2 changes: 2 additions & 0 deletions revamp/preprocessors/src/run-macros/macros/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package macros

import (
"webdoky3/revamp/preprocessors/src/run-macros/environment"
"webdoky3/revamp/preprocessors/src/run-macros/macros/compat"
"webdoky3/revamp/preprocessors/src/run-macros/macros/cssinfo"
"webdoky3/revamp/preprocessors/src/run-macros/macros/cssxref"
"webdoky3/revamp/preprocessors/src/run-macros/macros/embedlivesample"
Expand All @@ -11,6 +12,7 @@ import (
)

var MacrosIndex = map[string]func(*environment.Environment, *registry.Registry, string) (string, error){
"compat": compat.Compat,
"cssinfo": cssinfo.Cssinfo,
"cssref": blank,
"cssxref": cssxref.Cssxref,
Expand Down

0 comments on commit 8edaf9e

Please sign in to comment.