gofakeit
gofakeit copied to clipboard
Add html
Add ability to add random html elements.
Yo! I'm back after a week+ off. What's the deal with this? Would this be like generating individual <p>
, <h1>
, <div>
, <li>
, etc. elements with fake info inside of them? Nesting? They wouldn't be styled at all, would they? Is this similar to xml.go?
Hey buddy! Ready for round 2?
So my thought for this is to start with a simple function. Something like HtmlElement() string. and returns a random html element. Just like you described in your previous comment <p>
, <h1>
, <div>
And then next function would take that a step further and do a random complete element <div>random sentence</div>
<h1>random sentence</h1>
And then take that another step further and do a group of element that could be randomly nested
<div>
<p>random sentence</p>
<h1>
<li>random something</li>
</h1>
</div>
Those were just my thoughts. Not sure if anyone would actually use it but I thought it would be interesting to add. Eventually my thoughts were to see how far I could take the idea of generating html to resemble at least something that looks like a website.
So if I'm correctly understanding, we have one function that basically just generates an HTML stub (nothing in-between), another function that generates single HTML elements with some fake text inside of them, and then another function that generates nested HTML elements with fake data inside of them?
ya that was my thoughts. each proceeding can use the previous function to get data it needs.
Cool! I started work on a new branch, see html.go. So far I have stubs and single elements with fields being generated, next I'll do nesting.
Should we be able to pass in multiple fields for single elements, or just one?
Also, something I think may be cool is if there are also functions for populating specific elements with fake data, for example, perhaps we have a P()
func that will always output a <p>
element, populated with whatever fields specified.
What do you think?
ya thats a pretty good idea. maybe one function that takes in the element. cause otherwise we would have soooo many function to get all the primary html elements that exist
Sorry! It's been a bit. Finals week and all that good stuff. I am having some trouble right now comprehending exactly how nested HTML would work. I am looking at json.go
, and it is not really clear to me based on the tests written nor the code how exactly you handle nested objects.
For example, I don't understand how this:
func ExampleFaker_JSON_object() {
f := New(11)
value, err := f.JSON(&JSONOptions{
Type: "object",
Fields: []Field{
{Name: "first_name", Function: "firstname"},
{Name: "last_name", Function: "lastname"},
{Name: "address", Function: "address"},
{Name: "password", Function: "password", Params: MapParams{"special": {"false"}}},
},
Indent: true,
})
if err != nil {
fmt.Println(err)
}
fmt.Println(string(value))
// Output: {
// "first_name": "Markus",
// "last_name": "Moen",
// "address": {
// "address": "4599 Dale ton, Norfolk, New Jersey 36906",
// "street": "4599 Dale ton",
// "city": "Norfolk",
// "state": "New Jersey",
// "zip": "36906",
// "country": "Tokelau",
// "latitude": 23.058758,
// "longitude": 89.022594
// },
// "password": "qjXy56JHcVlZ"
// }
}
Produces the output there.
Hey! No problem! So instead of looking at the json functions, the more similar one to look at in this situation would be the sentence and paragraph functions. If that makes sense.
Gotcha, in that case, do we not care about what is inside each HTML element? Will we just generate stubs? Do we want nested HTML as a feature?
https://github.com/brianvoe/gofakeit/issues/194#issuecomment-1102723787
So I think this one best explains the 3 functions I was thinking about. Let me know if I need to better describe it.
Are the random things within the HTML elements user-specified or arbitrary? I.e. sentences?
arbitrary
Add input fields and svg generators
I have been having a play around with the HTML generator Just testing out ideas. Generating random elements based on element groups Generating elements with random attributes, I need to add a random elements Generator Generating page elements or a full HTML page.
https://github.com/Mrpye/gofakeit/blob/experimental/html_elements.go https://github.com/Mrpye/gofakeit/blob/experimental/html_elements_test.go
I might be overkill, got a bit carried away.
Ill take a look at those as soon as we finalize the template stuff.