Java Code Examples for com.github.jknack.handlebars.Options#fn()

The following examples show how to use com.github.jknack.handlebars.Options#fn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CurrentRackIsPresentHelper.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence apply(Collection<UpstreamInfo> upstreams, Options options) throws IOException {
  if (!currentRackId.isPresent()) {
    return options.fn();
  }

  if (upstreams == null) {
    return options.inverse();
  }

  for (UpstreamInfo upstreamInfo : upstreams) {
    if (upstreamInfo.getRackId().isPresent() && upstreamInfo.getRackId().get().toLowerCase().equals(currentRackId.get().toLowerCase())) {
      return options.fn();
    }
  }
  return options.inverse();
}
 
Example 2
Source File: IfEqualHelper.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence apply(String context, Options options) throws IOException {
	if (options.params.length != 1 || !(options.params[0] instanceof String)) {
		throw new IllegalArgumentException(
				"#if_equal requires one and only one String as an argument to compare against.\nShould be of the form:\n{{#if_equal someVar \"MYSTRING\"}}The value of someVar is MYSTRING{{else}}The value of someVar is not MYSTRING{/if_equal}}");
	}

	String match = (String) options.params[0];

	if (context == null || !context.equals(match)) {
		return options.inverse(Context.newContext(options.context, context));
	}

	return options.fn(Context.newContext(options.context, context));
}
 
Example 3
Source File: IfEqualHelper.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
@Override
public CharSequence apply(final Object context, final Options options)
        throws IOException {
    if (options.hash.get("value").equals(context.toString())) {
        return options.fn();
    } else {
        return options.inverse();
    }
}
 
Example 4
Source File: IfPresentHelper.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public CharSequence apply(Object context, Options options) throws IOException {
  if (context instanceof Optional) {
    context = ((Optional<Object>) context).orElse(null);
  }

  if (context != null) {
    return options.fn(context);
  } else {
    return options.inverse();
  }
}
 
Example 5
Source File: IfHasNewLinesOrBackticksHelper.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public CharSequence apply(Object context, Options options) throws IOException {
  if (context.toString().contains("\n") || context.toString().contains("`")) {
    return options.fn();
  } else {
    return options.inverse();
  }
}
 
Example 6
Source File: IfContainedInHelperSource.java    From Baragon with Apache License 2.0 5 votes vote down vote up
public static CharSequence ifContainedIn(Collection<String> haystack, String needle, Options options) throws IOException {
  if (Objects.isNull(haystack)) {
    return options.inverse();
  }

  for (String element : haystack) {
    if (element.contains(needle)) {
      return options.fn();
    }
  }

  return options.inverse();
}
 
Example 7
Source File: IfEqualHelperSource.java    From Baragon with Apache License 2.0 5 votes vote down vote up
public static CharSequence ifEqual(String v1, String v2, Options options) throws IOException {
  if (v1 == null ? v2 == null : v1.equals(v2)) {
    return options.fn();
  } else {
    return options.inverse();
  }
}
 
Example 8
Source File: IfEqualHelperSource.java    From Baragon with Apache License 2.0 5 votes vote down vote up
public static CharSequence ifOptionalEqual(Optional<String> v1, Optional<String> v2, Options options) throws IOException {
  if (v1.equals(v2)) {
    return options.fn();
  } else {
    return options.inverse();
  }
}