All Downloads are FREE. Search and download functionalities are using the official Maven repository.

raml.tools.handlebars.HandlebarsHelpers Maven / Gradle / Ivy

The newest version!
package raml.tools.handlebars;

import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;
import org.raml.model.SecurityReference;

import java.io.IOException;
import java.util.List;

public class HandlebarsHelpers {
  public static Helper lowerCaseHelper() {
    return new Helper() {

      @Override
      public CharSequence apply(Object s, Options options) throws IOException {
        if (s != null) {
          return s.toString().toLowerCase();
        }
        return "";
      }
    };
  }

  public static Helper highlightHelper() {
    return new Helper() {
      @Override
      public CharSequence apply(Object o, Options options) throws IOException {
        return o.toString();
      }
    };
  }

  public static Helper preOrLink() {
    return new Helper() {
      @Override
      public CharSequence apply(Object o, Options options) throws IOException {
        if (o == null) {
          return "";
        }
        if (o.toString().trim().startsWith("{")) {
          return new Handlebars.SafeString("
" + o.toString() + "
"); } else { return new Handlebars.SafeString(String.format("%s", o.toString(), o.toString())); } } }; } public static Helper> lockHelper() { return new Helper>() { @Override public CharSequence apply(List securityReferences, Options options) throws IOException { if (!securityReferences.isEmpty()) { return ""; } return ""; } }; } }