<commit_before>/*
 * Copyright 2014 Red Hat, Inc.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  The Apache License v2.0 is available at
 *  http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */

package io.vertx.ext.web.templ.handlebars.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;

import io.vertx.ext.web.common.template.CachingTemplateEngine;

import com.github.jknack.handlebars.Context;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.ValueResolver;
import com.github.jknack.handlebars.io.TemplateLoader;
import com.github.jknack.handlebars.io.TemplateSource;
import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.common.template.impl.TemplateHolder;
import io.vertx.ext.web.templ.handlebars.HandlebarsTemplateEngine;

/**
 * @author <a href="http://<EMAIL>"><NAME></a>
 * @author <a href="http://tfox.org"><NAME></a>
 */
public class HandlebarsTemplateEngineImpl extends CachingTemplateEngine<Template> implements HandlebarsTemplateEngine {

  private final Handlebars handlebars;
  private final Loader loader;

  private ValueResolver[] resolvers;

  public HandlebarsTemplateEngineImpl(Vertx vertx, String extension) {
    super(vertx, extension);
    loader = new Loader(vertx);
    // custom resolvers
    resolvers = new ValueResolver[ValueResolver.VALUE_RESOLVERS.length + 2];
    // custom resolvers for vertx json types
    resolvers[0] = JsonArrayValueResolver.INSTANCE;
    resolvers[1] = JsonObjectValueResolver.INSTANCE;
    // default resolvers
    System.arraycopy(ValueResolver.VALUE_RESOLVERS, 0, resolvers, 2, ValueResolver.VALUE_RESOLVERS.length);
    // create the engine
    handlebars = new Handlebars(loader);
  }

  @Override
  public void render(Map<String, Object> context, String templateFile, Handler<AsyncResult<Buffer>> handler) {
    try {<commit_msg>fix handlebars API change<commit_after>/*
 * Copyright 2014 Red Hat, Inc.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  The Apache License v2.0 is available at
 *  http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */

package io.vertx.ext.web.templ.handlebars.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;

import io.vertx.ext.web.common.template.CachingTemplateEngine;

import com.github.jknack.handlebars.Context;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.Template;
import com.github.jknack.handlebars.ValueResolver;
import com.github.jknack.handlebars.io.TemplateLoader;
import com.github.jknack.handlebars.io.TemplateSource;
import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
import io.vertx.ext.web.common.template.impl.TemplateHolder;
import io.vertx.ext.web.templ.handlebars.HandlebarsTemplateEngine;

/**
 * @author <a href="http://<EMAIL>"><NAME></a>
 * @author <a href="http://tfox.org"><NAME></a>
 */
public class HandlebarsTemplateEngineImpl extends CachingTemplateEngine<Template> implements HandlebarsTemplateEngine {

  private static final List<ValueResolver> VALUE_RESOLVERS_LIST = ValueResolver.defaultValueResolvers();
  private static final ValueResolver[] VALUE_RESOLVERS = VALUE_RESOLVERS_LIST.toArray(VALUE_RESOLVERS_LIST.size());

  private final Handlebars handlebars;
  private final Loader loader;

  private ValueResolver[] resolvers;

  public HandlebarsTemplateEngineImpl(Vertx vertx, String extension) {
    super(vertx, extension);
    loader = new Loader(vertx);
    // custom resolvers
    resolvers = new ValueResolver[VALUE_RESOLVERS.length + 2];
    // custom resolvers for vertx json types
    resolvers[0] = JsonArrayValueResolver.INSTANCE;
    resolvers[1] = JsonObjectValueResolver.INSTANCE;
    // default resolvers
    System.arraycopy(VALUE_RESOLVERS, 0, resolvers, 2, VALUE_RESOLVERS.length);
    // create the engine
    handlebars = new Handlebars(loader);
  }

  @Override
  public void render(Map<String, Object> context, String templateFile, Handler<AsyncResult<Buffer>> handler) {
    try {
{'fraction_non_alphanumeric': 0.10322183459880976, 'fraction_numerical': 0.007798071003488611, 'mean_word_length': 4.700584795321637, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '686549', 'n_tokens_mistral': 1509, 'n_tokens_neox': 1457, 'n_words': 355}