-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Added Template feature so documents can be generated using the built in functions #266
Conversation
Wow! I really like the direction of your thought process on this. I definitely think this idea is something we can get in. Im going to try to do my best to describe my thoughts on adjustments I think you should make that would get this integrated the best.
I added some comments in your files to start off. We can keep going back and fourth on adjustments and ideas and well see where we end on this. Thanks again and nice job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First quick round of comments.
I am glad you like the idea, I thought it would be useful I'll take a look and make changes I like the idea of separate functions for each template type. Thanks for the feed back and ill get to work |
Sounds good. Good luck! |
And make sure tests are passing too. :) |
The FixedFormat name, how about 'Fixed Width' seems to be an official name for that format. |
That template is tricky, I dont know if i fully see the benefit of that one. My thought with that one is instead of fixed with in the main template function you would have an option of fixed width and header. And with that I feel like it should tackle what the fixedformat one was trying to accomplish. Not sure if that makes sense but we can always swing back around to that one and figure something out. |
I have removed the fixed width for now, will revisit yes it perhaps should work similar to the csv function. |
I am just adding better html template data. I have basic page and multiple content items that get randomly generated depending on how many sections you pass. Unfortunately I managed to injury myself, so lost a few days in hospital but back on it now. |
Hi @brianvoe, How did you feel about using the go:embed? I am only asking because it feels messy adding templates as code, having them as files means keeping the code clean and it's easier to manage and edit files. I thought I would ask the question, but I am happy to go with what you feel is best. Andrew |
Glad to see your doing well. Welcome back. Lets start by getting it cleaned up and perfected on a simple scale then it makes it easier when you want to add more. Lets stay away from go:embed. Just makes it more difficult to use the package. String templates in a Go file are perfectly fine. Let me know if you need anything. Thanks! |
Made recommended changes
Fixed a space in the files section
Summary of updates Split the Template function into individual functions Template(template string, lines int) ([]byte, error) // Custom templates Moved the Template functions in the readme to its own Template section Added a couple of different templates to the data Added Unit tests for each function and also a big test to make sure all the templates compile properly Several other changes |
Ok that was a good round of changes. Lets talk about the next set of updates. I like your ambition for having "full" template but the templates you have are really bloated. Think MUCH simpler. Try to remove all the extra stuff. The goal is to get as broad amount of normal usage as possible and leave it open for others to build upon if they have more demanding situations(hence why just template where they can add there own and generate the amount of lines is a nice one) For email just have your basic title, message, signature and get really creative in those locations.
Markdown looks a little better but instead of multiple "templates" think one template and randomly generating certain areas to fill out. The html is a tricky one. I would say leave that out for now as I have a ticket for the one specifically and that will need a different level of heaving building to get that one right. Hopefully that helps and look forward to your updates |
Good Morning, I had an ah ha moment this morning. Im going to layout my thoughts and you let me know what you think. // Templates We can get rid of the word Template in front of the function name. They are all still in the category of template but just dont need to say it. I dont know why i didnt realize it sooner, but most other functions dont need to preceed the function name with the category. For the main template let them define the lines if they want to in there own template. I think the issue I have with lines being a param is I can think of a bunch of scenarios that I would want to output a template that dont require lines. That being said I feel like it should take in a second param for options and if they want to pass in lines as a dataset to be used in there template they can. type TemplateOptions struct {
Data interface{}
Funcs template.FuncMap
} I want to get your fixed width back in and i think the original issue is we were the ones defining the template instead of just letting them pass in the functions they want to use. type FixedWidthOptions struct {
Header []string
Funcs []string
Count int
}
opts := {
Header: {"Name", "Email"}
Funcs: {"{firstname} {lastname}", "{email}"} // Same as struct tags
Count: 3
}
FixedWidth(opts)
I think this gets your FixedWidth function back in with the most versatility possible. Let me know your thoughts. If your burnt out just let me know I can always wrap things up if you want. |
Sorry for the slowness in my response, I had an op on my hand so was out of action for a bit. While waiting for pre-op, I was also thinking about the Implementation of the options (Waiting for an op and thinking about code :-}), It just felt a bit messy and confusing for the user with the lines in the TemplateOption. I came to the same conclusion having a data field and making the FuncMap public. Regarding the FixedWidth function, It's funny because generating FixedWidth data was the reason I started down the route with Templates, so happy to put it back in. Another thing we need to consider is how to pass the width, alignment, and padding char of each field.
I'll get started with the first lot of changes and wait for your thoughts on the extra options. |
We are on the same page! Agree with the first two parts and the third, just wanted to add my two cents to the fixed width part. Totally agree with adding spacing, align and padding. I dont understand the align part but Im sure that makes sense to you. Is there a reason to have an array for those values instead of just a single value? and i just want to make sure those are optional and we have a default for those if they dont pass any in. P.S. If you code this thing with one hand you are a badass! Super duper close! |
Just a little update
Made loads of progress yesterday and got the fixed width working.
Just doing a bit of refinement and hardening.
Also got all the other changes in just need to update the docs.
I'll try to get some done today, but life getting in the way :-)
…On Mon, 13 Nov 2023, 17:08 Brian Voelker, ***@***.***> wrote:
We are on the same page! Agree with the first two parts and the third,
just wanted to add my two cents to the fixed width part.
Totally agree with adding spacing, align and padding. I dont understand
the align part but Im sure that makes sense to you. Is there a reason to
have an array for those values instead of just a single value? and i just
want to make sure those are optional and we have a default for those if
they dont pass any in.
P.S. If you code this thing with one hand you are a badass!
Super duper close!
—
Reply to this email directly, view it on GitHub
<#266 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDIAXPATDO2KITZVJKJDNTYEJHZ3AVCNFSM6AAAAAA6Z75PFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBYGYYDINBSGU>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
No worries take your time. |
Added Fixed Width
Hi, So a summary of the latest push. The FixedWidth has been added. You can hide the header, footer // Output:
// name************last_nameEmail********************password****Account No.**Money
// Markus Moen Daniel [email protected] W8DAkpLjYoBW364599489953 35
// Amie Feil Kuvalis [email protected] 16
// Trystan GislasonKeebler [email protected] J41S7H76KwYZ323202027613 61
// 112.00 |
Looking good! Make sure to think super simple, a lot of the times if something has too many options people are less prone to use it. Less is more type mentality. The separator per column and the footer are two examples of that. Let me know when your done and ill review it then. Thanks |
Ok, I have stripped it down to just spacing and alignment. |
So much cleaner!!! Nice job. Sorry i dont mean to poo poo on your ideas I am just trying to give it the best possible success it can be. Cause i really want people to use this. |
I do get carried away :-), You have a vision and it is quite a task making sure random people keep to it, I respect that. |
sounds good. let me know when your ready so we can get this in!!! |
I am ready |
ok im gonna merge this into develop and play around with it. Maybe find some way to simplify stuff. |
Ok first round I did cleanup and simplification of your fixed width function. Let me know what you think |
Ok i did a bunch of cleanup and get things in line with the rest of the package. Take a look at the commit. What i need from you is to basically just get the test working again and get a decent amount of additional tests in so we know we are covering our bases. Take note that i have to use the rand that is passed to them. The rand they pass in need to be the bases for for how things are generated. I tried building the FuncMap based upon the lookup setup but I think what you originally had by using reflect to pull the methods might be the better option. I ran out of time today so ill let you run the finish line. Just make sure you do a pr into the develop branch. |
Hi
I am working on the updates, I am nearly there, just have not had much time
this week.
Andrew
…On Tue, Nov 21, 2023 at 10:56 PM Brian Voelker ***@***.***> wrote:
@Mrpye <https://github.com/Mrpye> 082638f
<082638f>
Ok i did a bunch of cleanup and get things in line with the rest of the
package. Take a look at the commit.
What i need from you is to basically just get the test working again and
get a decent amount of additional tests in so we know we are covering our
bases.
Take note that i have to use the rand that is passed to them. The rand
they pass in need to be the bases for for how things are generated.
I tried building the FuncMap based upon the lookup setup but I think what
you originally had by using reflect to pull the methods might be the better
option.
I ran out of time today so ill let you run the finish line.
Just make sure you do a pr into the develop branch.
—
Reply to this email directly, view it on GitHub
<#266 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDIAXPP6F7VI3SZ3WXGTQTYFUWSTAVCNFSM6AAAAAA6Z75PFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRRHAZDQNJTG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
no worries just let me know when your done |
@Mrpye I submitted it to golang weekly newsletter and you made it first link!!! |
Wicked very exciting 😀. It been learning experience. And thanks for
letting me contribute.
…On Tue, 28 Nov 2023, 18:10 Brian Voelker, ***@***.***> wrote:
@Mrpye <https://github.com/Mrpye> I submitted it to golang weekly
newsletter and you made it first link!!!
https://golangweekly.com/issues/486
—
Reply to this email directly, view it on GitHub
<#266 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDIAXOJSU7E2FBFEWN3Y2TYGYSLFAVCNFSM6AAAAAA6Z75PFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZQGQYTKMBUGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Not sure if this is something you want to add, but I have found it a very useful feature, so spent the time making it a feature.
example
I have created unit tests for the template and functions.
To make the functions available to the template engine there is a function called BuildFunctionMap, that gets the methods from globalFaker and checks that the parameters are compatible with GO's template engine, and then adds them to a function map.
See what you think,
Thanks Andrew