Outlet and Render components.
This commit is contained in:
parent
0076ae6627
commit
389b0d072c
9
TODO.md
9
TODO.md
@ -22,12 +22,17 @@ For example:
|
|||||||
- fp
|
- fp
|
||||||
- [ ] Remove gradle plugins and whatnot until we actually build the whole framework
|
- [ ] Remove gradle plugins and whatnot until we actually build the whole framework
|
||||||
|
|
||||||
## 0.1.2
|
## 0.1.3
|
||||||
|
- [ ] refactor tools/gradle start scripts to use dist instead of custom bin script
|
||||||
|
- [ ] have custom bin/* scripts which point to dist(s) for convenience
|
||||||
- [ ] di bug: @Singleton toSelf() causes stack overflow
|
- [ ] di bug: @Singleton toSelf() causes stack overflow
|
||||||
- [ ] `Outlet` component for rendering children like so:
|
|
||||||
|
## 0.1.2
|
||||||
|
- [x] `Outlet` component for rendering children like so:
|
||||||
```
|
```
|
||||||
<Outlet children={children} />
|
<Outlet children={children} />
|
||||||
```
|
```
|
||||||
|
- [x] `Render` component
|
||||||
- [x] `data-` attributes need to function correctly (really any attribute with hyphen).
|
- [x] `data-` attributes need to function correctly (really any attribute with hyphen).
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
@ -14,6 +14,8 @@ class DefaultWebViewComponentScope extends DefaultComponentScope implements WebV
|
|||||||
addWithAttr(DefaultCase)
|
addWithAttr(DefaultCase)
|
||||||
addWithAttr(Each)
|
addWithAttr(Each)
|
||||||
addWithAttr(Echo)
|
addWithAttr(Echo)
|
||||||
|
addWithAttr(Outlet)
|
||||||
|
addWithAttr(Render)
|
||||||
addWithAttr(Switch)
|
addWithAttr(Switch)
|
||||||
addWithAttr(WhenNotEmpty)
|
addWithAttr(WhenNotEmpty)
|
||||||
addWithAttr(WhenNotNull)
|
addWithAttr(WhenNotNull)
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package groowt.view.component.web.lib
|
||||||
|
|
||||||
|
import groowt.view.View
|
||||||
|
import groowt.view.component.runtime.DefaultComponentWriter
|
||||||
|
|
||||||
|
class Outlet extends DelegatingWebViewComponent {
|
||||||
|
|
||||||
|
private final List givenChildren
|
||||||
|
|
||||||
|
Outlet(Map attr) {
|
||||||
|
givenChildren = attr.children ?: []
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View getDelegate() {
|
||||||
|
return { Writer w ->
|
||||||
|
def cw = new DefaultComponentWriter(w, context.renderContext, context)
|
||||||
|
givenChildren.each { cw << it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package groowt.view.component.web.lib
|
||||||
|
|
||||||
|
import groowt.view.View
|
||||||
|
|
||||||
|
class Render extends DelegatingWebViewComponent {
|
||||||
|
|
||||||
|
private final Object item
|
||||||
|
|
||||||
|
Render(Map attr) {
|
||||||
|
item = Objects.requireNonNull(attr.item, "<Render> attribute 'item' must not be null.")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View getDelegate() {
|
||||||
|
return { Writer w ->
|
||||||
|
if (item.respondsTo('renderTo', [Writer] as Class[])) {
|
||||||
|
item.renderTo(w)
|
||||||
|
} else if (item.respondsTo('render')) {
|
||||||
|
w << item.render()
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
'<Render> must use an item which responds to either renderTo(Writer) or render().'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package groowt.view.component.web.lib
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class OutletTests extends AbstractWebViewComponentTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void smokeScreen() {
|
||||||
|
doTest('<Outlet />', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void withChildren() {
|
||||||
|
doTest('<Echo items={[0, 1, 2]}><Outlet children={items} /></Echo>', '012')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package groowt.view.component.web.lib
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class RenderTests extends AbstractWebViewComponentTests {
|
||||||
|
|
||||||
|
static final class RenderToExample {
|
||||||
|
|
||||||
|
void renderTo(Writer w) {
|
||||||
|
w << 'Hello, World!'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class RenderExample {
|
||||||
|
|
||||||
|
String render() {
|
||||||
|
'Hello, World!'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void renderToExample() {
|
||||||
|
doTest('''
|
||||||
|
---
|
||||||
|
package groowt.view.component.web.lib
|
||||||
|
---
|
||||||
|
<Render item={new RenderTests.RenderToExample()} />
|
||||||
|
'''.stripIndent().trim(),
|
||||||
|
'Hello, World!'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void renderExample() {
|
||||||
|
doTest('''
|
||||||
|
---
|
||||||
|
package groowt.view.component.web.lib
|
||||||
|
---
|
||||||
|
<Render item={new RenderTests.RenderExample()} />
|
||||||
|
'''.stripIndent().trim(),
|
||||||
|
'Hello, World!'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user