Skip to content

Commit

Permalink
#618 Moved Helper.java to core, and updated data-sly-use in page.html…
Browse files Browse the repository at this point in the history
…. Refactored Helper.java to allow siteCSS to exist under per:Site/jcr:content
  • Loading branch information
cmrockwell committed Oct 27, 2020
1 parent 2019764 commit 51469da
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
7 changes: 7 additions & 0 deletions pagerenderer/server/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>

<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.sightly.compiler.java</artifactId>
<version>1.0.18</version>
<scope>provided</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
package apps.pagerenderserver.components.page;

/*-
* #%L
* peregrine server page renderer - UI Apps
* %%
* Copyright (C) 2017 headwire inc.
* %%
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* #L%
*/
package com.peregrine.pagerender.server.helpers;

import javax.script.Bindings;

import com.peregrine.pagerender.server.models.PageModel;
import org.apache.sling.scripting.sightly.pojo.Use;
import org.apache.sling.api.resource.Resource;

import org.apache.sling.models.factory.ModelFactory;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.scripting.SlingScriptHelper;

public class Helper implements Use {
public class PageHelper implements Use {

private Object model;
private String siteRootPath;
Expand All @@ -60,6 +35,12 @@ public String getModelClass() {
return model.getClass().toString();
}

public String[] getSiteCSS(){
PageModel page = resource.adaptTo(PageModel.class);
return page.getSiteCSS();
}


public void init(Bindings bindings) {
resource = (Resource) bindings.get("resource");
SlingHttpServletRequest request = (SlingHttpServletRequest) bindings.get("request");
Expand All @@ -77,6 +58,7 @@ public void init(Bindings bindings) {
} catch(Throwable t) {
model = sling.getService(ModelFactory.class).getModelFromRequest(request);
}
model.toString();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import org.apache.sling.models.annotations.Optional;
import org.apache.sling.models.factory.ModelFactory;

import java.util.Objects;

/**
* Created by rr on 12/2/2016.
*/
Expand All @@ -71,11 +73,9 @@ public Resource getParentContent(Resource res) {
Resource page = res.getParent();
if(page != null) {
Resource parentPage = page.getParent();
if(parentPage != null) {
if(PAGE_PRIMARY_TYPE.equals(parentPage.getResourceType())) {
Resource child = parentPage.getChild(JCR_CONTENT);
return child;
}
if(Objects.nonNull(parentPage) && Objects.nonNull(parentPage.getChild(JCR_CONTENT))) {
Resource child = parentPage.getChild(JCR_CONTENT);
return child;
}
}
return null;
Expand Down Expand Up @@ -126,7 +126,9 @@ public String getPagePath() {
public String[] getSiteCSS() {
if(siteCSS == null) {
String[] value = (String[]) getInheritedProperty(SITE_CSS);
if(value != null && value.length != 0) return value;
if(value != null && value.length != 0) {
return value;
}
if(getTemplate() != null) {
PageModel templatePageModel = getTemplatePageModel();
if(templatePageModel != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<!DOCTYPE html><sly data-sly-use.helper="apps.pagerenderserver.components.page.Helper"/>
<!DOCTYPE html><sly data-sly-use.helper="com.peregrine.pagerender.server.helpers.PageHelper"/>
<html lang="en">
<head>
<meta charset="utf-8">
<sly data-sly-list="${helper.model.prefetchDNS}"><link rel="preconnect" href="${item}"><link rel="dns-prefetch" href="${item}"></sly>
<sly data-sly-list="${helper.model.siteJS}"><link rel="preload" href="${item}" as="script"></sly>
<sly data-sly-list="${helper.model.siteCSS}"><link rel="preload" href="${item}" as="style"></sly>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#c0c0c0">

Expand Down

0 comments on commit 51469da

Please sign in to comment.