Started working on IntrinsicHtml.

This commit is contained in:
JesseBrault0709 2024-05-05 21:09:44 +02:00
parent 7e2e176e6a
commit 9c64a42038
2 changed files with 59 additions and 4 deletions

View File

@ -10,7 +10,7 @@ class Echo extends DelegatingWebViewComponent {
static final ComponentFactory<Echo> FACTORY = new EchoFactory()
private static final class EchoFactory implements ComponentFactory<Echo> {
protected static class EchoFactory implements ComponentFactory<Echo> {
Echo doCreate(String typeName) {
doCreate(typeName, [:], true)
@ -91,9 +91,14 @@ class Echo extends DelegatingWebViewComponent {
while (iter.hasNext()) {
def entry = iter.next()
writer << entry.key
def value = entry.value
if (value instanceof Boolean) {
// no-op, because we already wrote the key
} else {
writer << '="'
writer << entry.value
writer << value
writer << '"'
}
if (iter.hasNext()) {
writer << ' '
}

View File

@ -0,0 +1,50 @@
package groowt.view.web.lib
import groowt.view.component.context.ComponentContext
import groowt.view.component.factory.ComponentFactory
import groowt.view.web.WebViewChildComponentRenderer
class IntrinsicHtml extends Echo {
// TODO: check type name for HTML 5 validity
protected static class IntrinsicHtmlFactory implements ComponentFactory<IntrinsicHtml> {
IntrinsicHtml doCreate(String typeName) {
new IntrinsicHtml([:], typeName, false)
}
IntrinsicHtml doCreate(String typeName, boolean selfClose) {
new IntrinsicHtml([:], typeName, selfClose)
}
IntrinsicHtml doCreate(String typeName, Map<String, Object> attr) {
new IntrinsicHtml(attr, typeName, false)
}
IntrinsicHtml doCreate(String typeName, Map<String, Object> attr, boolean selfClose) {
new IntrinsicHtml(attr, typeName, selfClose)
}
IntrinsicHtml doCreate(String typeName, Map<String, Object> attr, List<WebViewChildComponentRenderer> children) {
def intrinsicHtml = new IntrinsicHtml(attr, typeName, false)
intrinsicHtml.childRenderers = children
intrinsicHtml
}
@Override
IntrinsicHtml create(String typeName, ComponentContext componentContext, Object... args) {
return this.doCreate(typeName, componentContext, *args)
}
@Override
IntrinsicHtml create(Class<?> type, ComponentContext componentContext, Object... args) {
throw new UnsupportedOperationException('Cannot create an IntrinsicHtml component with a class type.')
}
}
IntrinsicHtml(Map<String, Object> attr, String elementName, boolean selfClose) {
super(attr, elementName, selfClose)
}
}