org.spincast.website.pebble.AppPebbleExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spincast-website Show documentation
Show all versions of spincast-website Show documentation
Source code for the https://www.spincast.org website.
package org.spincast.website.pebble;
import java.util.List;
import java.util.Map;
import org.jsoup.Jsoup;
import org.spincast.core.utils.SpincastStatics;
import com.mitchellbosecke.pebble.error.PebbleException;
import com.mitchellbosecke.pebble.extension.AbstractExtension;
import com.mitchellbosecke.pebble.extension.Filter;
import com.mitchellbosecke.pebble.template.EvaluationContext;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
/**
* Custom Pebble extension.
*/
public class AppPebbleExtension extends AbstractExtension {
public static final String REMOVE_HTML_TAGS_FILTER_NAME = "strip";
@Override
public Map getFilters() {
//==========================================
// Pebble filter to remove the HTML tags.
//==========================================
Filter filter = new Filter() {
@Override
public List getArgumentNames() {
return null;
}
@Override
public Object apply(Object value,
Map args,
PebbleTemplate self,
EvaluationContext evaluationContext,
int lineNumber) throws PebbleException {
if (value == null) {
return null;
}
String str = (String)value;
return Jsoup.parse(str).text();
}
};
return SpincastStatics.map(REMOVE_HTML_TAGS_FILTER_NAME, filter);
}
}