Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds ability to define custom funcs in LocalizeConfig #99 #100

Merged
merged 4 commits into from
Apr 27, 2018

Conversation

Seklfreak
Copy link
Contributor

This PR adds the ability to define custom template engine funcs. It adds a Funcs field to the LocalizeConfig struct and passes this parameter to gotemplate.Funcs.

@codecov
Copy link

codecov bot commented Apr 27, 2018

Codecov Report

Merging #100 into master will not change coverage.
The diff coverage is 60%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #100   +/-   ##
=======================================
  Coverage   63.93%   63.93%           
=======================================
  Files          28       28           
  Lines        2271     2271           
=======================================
  Hits         1452     1452           
  Misses        745      745           
  Partials       74       74
Impacted Files Coverage Δ
v2/internal/message_template.go 61.53% <0%> (ø) ⬆️
v2/internal/template.go 77.77% <100%> (ø) ⬆️
v2/i18n/localizer.go 79.51% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 072fa6e...306150f. Read the comment docs.

Copy link
Owner

@nicksnyder nicksnyder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, thanks!

func TestParseWithFunc(t *testing.T) {
tmpl := &Template{Src: "hello"}
funcs := template.FuncMap{
"foo": func() string {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to actually use the "foo" func. Can you add a test that does that?

@Seklfreak
Copy link
Contributor Author

forgot to change Src, done! :)

tmpl := &Template{Src: "{{foo}}"}
funcs := template.FuncMap{
"foo": func() string {
return "bar"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also check that the value produced by the template is actually “bar”

@Seklfreak
Copy link
Contributor Author

there we go 👍

@nicksnyder nicksnyder merged commit 142c04a into nicksnyder:master Apr 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants