@Test public void shouldConstructAppMenu() { Res res = Res.from("menu.yaml"); Object data = YAML.parse(res.getContent(), Object.class); System.out.println(data); AppMenu menu = AppMenu.from(data); System.out.println(menu); eq(menu.getItems().size(), 2); AppMenuItem item1 = menu.getItems().get(0); eq(item1.getCaption(), "item1"); eq(item1.getTarget(), "aaa"); AppMenuItem item2 = menu.getItems().get(1); eq(item2.getCaption(), "item2"); isNull(item2.getTarget()); AppSubMenuItem subitem1 = item2.getSubmenu().getItems().get(0); AppSubMenuItem subitem2 = item2.getSubmenu().getItems().get(1); AppSubMenuItem subitem3 = item2.getSubmenu().getItems().get(2); eq(subitem1.getCaption(), "d"); eq(subitem1.getTarget(), ""); eq(subitem2.getCaption(), "e"); eq(subitem2.getTarget(), "f"); eq(subitem3.getCaption(), "last"); eq(subitem3.getTarget(), ""); }
private Res getResource(String filename, boolean partial) { String sub = partial ? "/partials/" : "/templates/"; return Res.from(filename, "rapidoid" + sub); }
@SuppressWarnings("unchecked") public static PageMenu parse(String filename) { byte[] yaml = Res.from(filename).getBytesOrNull(); Map<String, ?> data = yaml != null ? YAML.parse(yaml, Map.class) : null; return from(data); }