-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Casting to a specific type or exposing an interface with HTML element functions #897
Comments
The closest would be i.e. app.Div() and app.A() are both If you're looking for a common interface for the Body() method, there is not one, since each html element returns a it's own interface to allow method chaining. package app
// HTMLA is the interface that describes a "a" HTML element.
type HTMLA interface {
UI
// Body set the content of the element.
Body(elems ...UI) HTMLA
}
// HTMLDiv is the interface that describes a "div" HTML element.
type HTMLDiv interface {
UI
// Body set the content of the element.
Body(elems ...UI) HTMLDiv
} |
ok yep. |
You can only add a single component inside of body. So you could add |
Ok thanks I'll have to be very explicit for the goals I want then. |
Without breaking the contract of existing methods on each element type by removing the return value, there cannot be a common interface as mentioned earlier. Likewise, adding additional methods to meet a common interface would be confusing - there would be two differently named methods that do the same thing.
and
This sounds to me like building go-app elements from json or similar. Instead of chaining calls to go-app typed elements, you want a simplified way instantiate elements without using method chaining? I inferred this from the two quotes so I could be way off. {
"div":{
"class":"myClass",
"id":"myId"
}
} passed to func ElemFromJson(json string) app.UI {
// get root, determine type
e := app.Div()
// call methods for id, body, etc
return e
} |
@mlctrez yes that is basically what I want. I actually want to (and am currently doing) parse an HTML template that builds go-app elements. I am using the golang standard html library to parse the html doc and recursively running through it replacing elements with go-app elements. It works great for instance if I have But your example is the same principle yes, i.e json to elements hence why I was hoping to be able to have a generic interface. However I cant use Thanks for support guys! |
@amlwwalker We wrote an HTML to go-app code converter (others did too, our one is proprietary, sorry) and I still think that there should be a possibility to compile these to WASM and load them as extension. I do wonder why you want to do that in the frontend, where you simply can add the raw HTML anyway? |
I don't want to do it in the frontend @oderwat. I am attempting to build a sort of site-generator using go-app (at this point for my own education/enjoyment). Loading them via wasm as start would be cool too (esp as it allows for more elements to be added without recompiling) but for now I am just trying to make it straight forward to define the layout from HTML and then the elements are compiled into the app that are available 🙂 Do you have a link to an open source HTML to go-app converter that could then be inspiration, or could you tell me the approach you took? Did you do a big switch case - just so I know the route I am taking is correct? |
@amlwwalker I think it was: https://github.com/pojntfx/html2goapp |
We made a tool that generates go-app code and understands TailwindCSS with a live preview. But it is more for HTML-wizards, so you can quickly design some component using HTML using TailwindCSS and then copy the generated go-app code into the real source code. The first thing and what the converter actually was created for was using it to translate large amounts of HTML pages (mostly template site examples) info go-app declarative code, to check if we actually can use go-app in production without writing a lot of manually code. |
Kinda. We use |
OK thanks this is interesting. I'm going to look through that link you posted as I want to call existing go-app elements I've created based on custom html elements as explained above. I think I can use this inspiration to parse the HTML and then maybe extrapolate the jennifer work to do a sort of hopefully anyway 😂 |
I want to generate a go-app type, (say
app.Div
) from the stringdiv
. I believe that all functions like this have similar functions likeIs there an interface that I can use to store a map of
map[string]app.Interface
and store"div":app.Div
in there so that I can then populate whatever is returned? I can't find an interface that they are adhering to?The text was updated successfully, but these errors were encountered: