WhenNotEmpty now accepts maps.
This commit is contained in:
parent
2c43f9331a
commit
d2ffdec65f
2
TODO.md
2
TODO.md
@ -16,7 +16,7 @@
|
||||
- [x] `Switch` and `Case` components
|
||||
- [x] Fix bug with multiline nested component attributes.
|
||||
- [x] `Each` with `Map`
|
||||
- [ ] `WhenNotEmpty` with `Map`
|
||||
- [x] `WhenNotEmpty` with `Map`
|
||||
|
||||
## 0.1.0
|
||||
- [x] figure out how to make the GroovyClassLoader consistent between the groovy compiler configuration and the wvc
|
||||
|
@ -5,7 +5,7 @@ import groowt.view.component.runtime.DefaultComponentWriter
|
||||
|
||||
class WhenNotEmpty extends DelegatingWebViewComponent {
|
||||
|
||||
private final Collection items
|
||||
private final Object items
|
||||
|
||||
WhenNotEmpty(Map attr) {
|
||||
items = attr.items
|
||||
@ -14,7 +14,7 @@ class WhenNotEmpty extends DelegatingWebViewComponent {
|
||||
@Override
|
||||
protected View getDelegate() {
|
||||
return { Writer w ->
|
||||
if (!items.empty) {
|
||||
if (items instanceof Collection && !items.empty || items instanceof Map && !items.isEmpty()) {
|
||||
def cw = new DefaultComponentWriter(w, context.renderContext, context)
|
||||
children.each { cw << it }
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package groowt.view.component.web.lib
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class WhenNotEmptyTests extends AbstractWebViewComponentTests {
|
||||
|
||||
@Test
|
||||
void emptyCollection() {
|
||||
doTest('<WhenNotEmpty items={[]}>Hello, World!</WhenNotEmpty>', '')
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyMap() {
|
||||
doTest('<WhenNotEmpty items={[:]}>Hello, World!</WhenNotEmpty>', '')
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonEmptyCollection() {
|
||||
doTest('<WhenNotEmpty items={[0, 1, 2]}>012</WhenNotEmpty>', '012')
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonEmptyMap() {
|
||||
doTest('<WhenNotEmpty items={[a: 0]}>a: 0</WhenNotEmpty>', 'a: 0')
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user