Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2014 SQUARESPACE, Inc.
*
* Licensed 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.
*/
package com.squarespace.template.plugins;
import static com.squarespace.template.GeneralUtils.isTruthy;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import com.squarespace.template.Arguments;
import com.squarespace.template.ArgumentsException;
import com.squarespace.template.BasePredicate;
import com.squarespace.template.CodeExecuteException;
import com.squarespace.template.Context;
import com.squarespace.template.GeneralUtils;
import com.squarespace.template.JsonUtils;
import com.squarespace.template.Patterns;
import com.squarespace.template.Predicate;
import com.squarespace.template.PredicateRegistry;
import com.squarespace.template.ReferenceScanner.References;
import com.squarespace.template.ReprEmitter;
import com.squarespace.template.StringView;
import com.squarespace.template.SymbolTable;
import com.squarespace.template.VariableRef;
public class CorePredicates implements PredicateRegistry {
/**
* Registers the active predicates in this registry.
*/
@Override
public void registerPredicates(SymbolTable table) {
table.add(DEBUG);
table.add(EQUAL);
table.add(EVEN);
table.add(GREATER_THAN);
table.add(GREATER_THAN_OR_EQUAL);
table.add(LESS_THAN);
table.add(LESS_THAN_OR_EQUAL);
table.add(NOT_EQUAL);
table.add(NTH);
table.add(ODD);
table.add(PLURAL);
table.add(SINGULAR);
};
public static final Predicate DEBUG = new BasePredicate("debug?", false) {
@Override
public boolean apply(Context ctx, Arguments args) throws CodeExecuteException {
return isTruthy(ctx.resolve("debug"));
}
};
/**
* Class of predicates that take 1 argument which is either (a) a JSON value or
* (b) a variable reference.
*/
private static abstract class JsonPredicate extends BasePredicate {
JsonPredicate(String identifier) {
super(identifier, true);
}
JsonPredicate(String identifier, boolean requiresArgs) {
super(identifier, requiresArgs);
}
public abstract void limitArgs(Arguments args) throws ArgumentsException;
@Override
public void addReferences(Arguments args, References refs) {
addVariableNames(args, refs);
}
@Override
public void validateArgs(Arguments args) throws ArgumentsException {
limitArgs(args);
List