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

The following examples show how to use com.github.jknack.handlebars.Options#param() . 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: ComponentPresentedHelper.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public Object apply(Set<String> context, Options options)
        throws IOException {
    String first = options.param(0, null);

    Validate.notNull(first, "found 'null', expected 'first'");
    if (context == null) {
        context = new HashSet<>();
    }

    Buffer buffer = options.buffer();
    if (!context.contains(first)) {
        buffer.append(options.inverse());
    } else {
        buffer.append(options.fn());
    }
    return buffer;
}
 
Example 2
Source File: FormatTimestampHelper.java    From Baragon with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence apply(Number context, Options options) throws IOException {
  String dateFormatString;
  try {
    dateFormatString = options.param(0, defaultFormatString);
  } catch (ClassCastException cce) {  // phorce.
    LOG.warn(String.format("Date format %s isn't subclass of String, using default: %s", options.param(0), defaultFormatString));
    dateFormatString = defaultFormatString;
  }

  final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatString);

  final Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(context.longValue());

  return simpleDateFormat.format(cal.getTime());
}
 
Example 3
Source File: Helpers.java    From bootstraped-multi-test-results-report with MIT License 5 votes vote down vote up
private Helper<String> embeddingHelper() {
    return new Helper<String>() {
        @Override
        public CharSequence apply(String arg0, Options arg1) throws IOException {
            String toReturn;
            String id = UUID.randomUUID().toString();
            int index = arg1.param(1);
            if (arg1.param(0).toString().contains("image")) {
                toReturn =
                    "<button 'type='button'"
                        + "class='btn btn-primary'"
                        + "data-toggle='modal' "
                        + "data-target='#" + id + "'>"
                        + "  Screenshot " + ++index + ""
                        + "</button>";
                toReturn +=
                    "<div id='" + id + "'"
                        + "class='modal fade'"
                        + "tabindex='-1'"
                        + "role='dialog'"
                        + "aria-labelledby='myModalLabel'"
                        + "aria-hidden='true'>"
                        + "  <div style='width:90%;height:90%;'"
                        + "  class='modal-dialog'>"
                        + "    <div class='modal-content'>"
                        + "      <div class='modal-body'>"
                        + "        <img "
                        + "        src='data:image/png;base64," + arg0 + "'"
                        + "        class='img-responsive'>"
                        + "      </div>"
                        + "    </div>"
                        + "  </div>"
                        + "</div>";
            } else {
                toReturn = "<pre>" + arg0 + "</pre>";
            }
            return toReturn;
        }
    };
}
 
Example 4
Source File: EqHelper.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(Object context, Options options)
        throws IOException {
    String first = options.param(0, null);

    Validate.notNull(first, "found 'null', expected 'first'");

    Buffer buffer = options.buffer();
    if (!first.equals(context.toString())) {
        buffer.append(options.inverse());
    } else {
        buffer.append(options.fn());
    }
    return buffer;
}
 
Example 5
Source File: NeqHelper.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply(Object context, Options options)
        throws IOException {
    String first = options.param(0, null);

    Validate.notNull(first, "found 'null', expected 'first'");

    Buffer buffer = options.buffer();
    if (first.equals(context)) {
        buffer.append(options.inverse());
    } else {
        buffer.append(options.fn());
    }
    return buffer;
}