use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class StrSubFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
SoyValue arg2 = args.size() == 3 ? args.get(2) : null;
Preconditions.checkArgument(arg0 instanceof StringData || arg0 instanceof SanitizedContent, "First argument to strSub() function is not StringData or SanitizedContent: %s", arg0);
Preconditions.checkArgument(arg1 instanceof IntegerData, "Second argument to strSub() function is not IntegerData: %s", arg1);
if (arg2 != null) {
Preconditions.checkArgument(arg2 instanceof IntegerData, "Third argument to strSub() function is not IntegerData: %s", arg2);
}
String strArg0 = arg0.coerceToString();
int intArg1 = arg1.integerValue();
if (arg2 != null) {
return StringData.forValue(strArg0.substring(intArg1, arg2.integerValue()));
} else {
return StringData.forValue(strArg0.substring(intArg1));
}
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class BidiMarkAfterFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue value = args.get(0);
boolean isHtml = args.size() == 2 && args.get(1).booleanValue();
String markAfterKnownDir = BidiFunctionsRuntime.bidiMarkAfter(bidiGlobalDirProvider.get(), value, isHtml);
return StringData.forValue(markAfterKnownDir);
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class InternalValueUtils method convertCompileTimeGlobalsMap.
/**
* Converts a compile-time globals map in user-provided format into one in the internal format.
*
* <p>The returned map will have the same iteration order as the provided map.
*
* @param compileTimeGlobalsMap Map from compile-time global name to value. The values can be any
* of the Soy primitive types: null, boolean, integer, float (Java double), or string.
* @return An equivalent map in the internal format.
* @throws IllegalArgumentException If the map contains an invalid value.
*/
public static ImmutableMap<String, PrimitiveData> convertCompileTimeGlobalsMap(Map<String, ?> compileTimeGlobalsMap) {
ImmutableMap.Builder<String, PrimitiveData> resultMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, ?> entry : compileTimeGlobalsMap.entrySet()) {
Object valueObj = entry.getValue();
PrimitiveData value;
boolean isValidValue = true;
try {
SoyValue value0 = SoyValueConverter.INSTANCE.convert(valueObj).resolve();
if (!(value0 instanceof PrimitiveData)) {
isValidValue = false;
}
value = (PrimitiveData) value0;
} catch (SoyDataException sde) {
isValidValue = false;
// make compiler happy
value = null;
}
if (!isValidValue) {
throw new IllegalArgumentException("Compile-time globals map contains invalid value: " + valueObj + " for key: " + entry.getKey());
}
resultMapBuilder.put(entry.getKey(), value);
}
return resultMapBuilder.build();
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class DetachableSoyValueProvider method resolve.
@Override
public final SoyValue resolve() {
SoyValue local = resolvedValue;
checkState(local != TombstoneValue.INSTANCE, "called resolve() before status() returned ready.");
return local;
}
use of com.google.template.soy.data.SoyValue in project closure-templates by google.
the class MinFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
return BasicFunctionsRuntime.min(arg0, arg1);
}
Aggregations