-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use more fine-grained automatic conjugation generation.
- Loading branch information
1 parent
a285df9
commit c279194
Showing
13 changed files
with
223 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
package ankihelperconf | ||
|
||
import "text/template" | ||
import ( | ||
"encoding/json" | ||
"github.com/joomcode/errorx" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
const ( | ||
templateOpen = "$$" | ||
templateClose = "$$" | ||
) | ||
|
||
func ParseTextTemplate(name string, text string) (*template.Template, error) { | ||
return template.New(name).Delims(templateOpen, templateClose).Parse(text) | ||
return template.New(name).Delims(templateOpen, templateClose). | ||
Funcs(template.FuncMap{ | ||
"to_json": ToJson, | ||
}). | ||
Parse(text) | ||
} | ||
|
||
func ToJson(value any) (string, error) { | ||
var marshalled strings.Builder | ||
if err := json.NewEncoder(&marshalled).Encode(value); err != nil { | ||
return "", errorx.IllegalState.Wrap(err, "failed to marshal to JSON value %+v", value) | ||
} | ||
return marshalled.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.