Search in sources :

Example 1 with OrchidComponent

use of com.eden.orchid.api.theme.components.OrchidComponent in project Orchid by JavaEden.

the class OrchidContextImpl method getSiteData.

@Override
public Map<String, Object> getSiteData(Object... data) {
    Map<String, Object> siteData = new HashMap<>();
    Map<String, ?> root = getRoot().toMap();
    for (String key : root.keySet()) {
        siteData.put(key, root.get(key));
    }
    if (data != null && data.length > 0) {
        if (data[0] instanceof OrchidPage) {
            OrchidPage page = (OrchidPage) data[0];
            siteData.put("page", page);
            if (!EdenUtils.isEmpty(page.getType()) && !page.getType().equalsIgnoreCase("page")) {
                siteData.put(page.getType(), page);
            }
            Map<String, OrchidComponent> pageComponents = page.getComponents();
            for (Map.Entry<String, OrchidComponent> componentEntry : pageComponents.entrySet()) {
                siteData.put(componentEntry.getKey(), componentEntry.getValue());
            }
        } else if (data[0] instanceof OrchidComponent) {
            OrchidComponent component = (OrchidComponent) data[0];
            siteData.put("component", component);
            if (!EdenUtils.isEmpty(component.getAlias()) && !component.getAlias().equalsIgnoreCase("component")) {
                siteData.put(component.getAlias(), component);
            }
        } else if (data[0] instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) data[0];
            siteData.put("data", jsonObject);
            for (String key : jsonObject.keySet()) {
                siteData.put(key, jsonObject.get(key));
            }
        } else if (data[0] instanceof Map) {
            Map<String, ?> map = (Map<String, ?>) data[0];
            siteData.put("data", map);
            for (String key : map.keySet()) {
                siteData.put(key, map.get(key));
            }
        } else if (data[0] instanceof JSONArray) {
            JSONArray jsonArray = (JSONArray) data[0];
            siteData.put("data", jsonArray);
        } else if (data[0] instanceof Collection) {
            Collection collection = (Collection) data[0];
            siteData.put("data", collection);
        }
    }
    siteData.put("root", root);
    siteData.put("theme", getTheme());
    siteData.put("index", getIndex());
    siteData.put("site", this);
    return siteData;
}
Also used : OrchidPage(com.eden.orchid.api.theme.pages.OrchidPage) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) OrchidComponent(com.eden.orchid.api.theme.components.OrchidComponent) Collection(java.util.Collection) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

OrchidComponent (com.eden.orchid.api.theme.components.OrchidComponent)1 OrchidPage (com.eden.orchid.api.theme.pages.OrchidPage)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1