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

Export Funcs function to help enable usage of gomplate as library #372

Merged

Conversation

dcwangmit01
Copy link
Contributor

@dcwangmit01 dcwangmit01 commented Aug 16, 2018

Fixes #371

@dcwangmit01 dcwangmit01 changed the title Enable Usage of goemplate as library Enable Usage of gomplate as library Aug 16, 2018
@hairyhenderson
Copy link
Owner

@dcwangmit01 I wonder if all you need is to export initFuncs - then you could pass that to tmpl.Funcs 🤔

@dcwangmit01
Copy link
Contributor Author

@hairyhenderson Gosh darn I think you're right. I'll give it a go, and update this PR.

@hairyhenderson
Copy link
Owner

You should be good to go with:

diff --git a/funcs.go b/funcs.go
index 7d8fd3a..e8dd76f 100644
--- a/funcs.go
+++ b/funcs.go
@@ -7,8 +7,8 @@ import (
        "github.com/hairyhenderson/gomplate/funcs"
 )
 
-// initFuncs - The function mappings are defined here!
-func initFuncs(d *data.Data) template.FuncMap {
+// Funcs - The function mappings are defined here!
+func Funcs(d *data.Data) template.FuncMap {
        f := template.FuncMap{}
        funcs.AddDataFuncs(f, d)
        funcs.AWSFuncs(f)
diff --git a/gomplate.go b/gomplate.go
index 11a8ae8..bca66f7 100644
--- a/gomplate.go
+++ b/gomplate.go
@@ -70,7 +70,7 @@ func newGomplate(d *data.Data, leftDelim, rightDelim string) *gomplate {
        return &gomplate{
                leftDelim:  leftDelim,
                rightDelim: rightDelim,
-               funcMap:    initFuncs(d),
+               funcMap:    Funcs(d),
        }
 }

Note that I changed the name from initFuncs to Funcs - gomplate.Funcs(d) seems like a good enough function name...

* Exported the `Funcs` function by upcasing first letter
* Demo program found at:
  https://gist.github.com/dcwangmit01/e9e58dd123e0a8eb48c2f4e8ffa16d5a
@dcwangmit01 dcwangmit01 force-pushed the enable-gomplate-as-library branch from 2853f1d to fa4a51c Compare August 17, 2018 00:26
@dcwangmit01
Copy link
Contributor Author

dcwangmit01 commented Aug 17, 2018

@hairyhenderson Your changed worked perfectly. I've updated this PR with it 😅 , as well as the demo code in the gist.

@hairyhenderson hairyhenderson changed the title Enable Usage of gomplate as library Export Funcs function to help enable usage of gomplate as library Aug 17, 2018
@hairyhenderson hairyhenderson merged commit 357a8e0 into hairyhenderson:master Aug 17, 2018
@hairyhenderson
Copy link
Owner

Thanks for this, @dcwangmit01 - hope this is useful to you, and I'm sure it'll be useful to others 🙂

@dcwangmit01
Copy link
Contributor Author

Thanks for all the help @hairyhenderson, and the quick response. Makes contributing to this project a no-brainer.

@hairyhenderson
Copy link
Owner

🙇

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