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

Add html #194

Open
brianvoe opened this issue Jan 13, 2022 · 17 comments
Open

Add html #194

brianvoe opened this issue Jan 13, 2022 · 17 comments

Comments

@brianvoe
Copy link
Owner

Add ability to add random html elements.

@petergeorgas
Copy link
Contributor

petergeorgas commented Apr 19, 2022

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?

@brianvoe
Copy link
Owner Author

brianvoe commented Apr 19, 2022

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>

@brianvoe
Copy link
Owner Author

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.

@petergeorgas
Copy link
Contributor

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?

@brianvoe
Copy link
Owner Author

ya that was my thoughts. each proceeding can use the previous function to get data it needs.

@petergeorgas
Copy link
Contributor

petergeorgas commented Apr 19, 2022

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?

@petergeorgas
Copy link
Contributor

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?

@brianvoe
Copy link
Owner Author

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

@petergeorgas
Copy link
Contributor

petergeorgas commented May 1, 2022

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.

@brianvoe
Copy link
Owner Author

brianvoe commented May 2, 2022

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.

@petergeorgas
Copy link
Contributor

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?

@brianvoe
Copy link
Owner Author

brianvoe commented May 3, 2022

#194 (comment)

So I think this one best explains the 3 functions I was thinking about. Let me know if I need to better describe it.

@petergeorgas
Copy link
Contributor

petergeorgas commented May 3, 2022

Are the random things within the HTML elements user-specified or arbitrary? I.e. sentences?

@brianvoe
Copy link
Owner Author

brianvoe commented May 4, 2022

arbitrary

@brianvoe
Copy link
Owner Author

Add input fields and svg generators

@Mrpye
Copy link
Contributor

Mrpye commented Nov 17, 2023

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.

@brianvoe
Copy link
Owner Author

Ill take a look at those as soon as we finalize the template stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants