<commit_before>package org.woodylab.boot.pebble.web;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.error.PebbleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;

import java.util.Locale;

/**
 * 聋夫三拳 —— 我们不写代码，我们只是代码的搬运工。
 * <p>
 * Created by <a href="mailto:<EMAIL>">Woody</a> @ 15-12-11 下午5:17.
 */
public class PebbleViewResolver extends AbstractTemplateViewResolver implements ViewResolver {

    private static final Logger log = LoggerFactory.getLogger(PebbleViewResolver.class);

    private PebbleEngine pebbleEngine;

    public PebbleViewResolver() {
        log.debug("使用 PebbleViewResolver 作为 ViewResolver.");
        setViewClass(requiredViewClass());
    }

    @Override
    protected Class<?> requiredViewClass() {
        return PebbleView.class;
    }

    @Override
    protected View loadView(String viewName, Locale locale) throws PebbleException {

        PebbleView view = new PebbleView(pebbleEngine.getTemplate(viewName));
        view.setApplicationContext(getApplicationContext());
        view.setServletContext(getServletContext());

        return view;

    }

    public void setPebbleEngine(PebbleEngine pebbleEngine) {
        this.pebbleEngine = pebbleEngine;
    }


}<commit_msg>spring append .html to view name, strip it<commit_after>package org.woodylab.boot.pebble.web;

import com.mitchellbosecke.pebble.PebbleEngine;
import com.mitchellbosecke.pebble.error.PebbleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;

import java.util.Locale;

/**
 * 聋夫三拳 —— 我们不写代码，我们只是代码的搬运工。
 * <p>
 * Created by <a href="mailto:<EMAIL>">Woody</a> @ 15-12-11 下午5:17.
 */
public class PebbleViewResolver extends AbstractTemplateViewResolver implements ViewResolver {

    private static final Logger log = LoggerFactory.getLogger(PebbleViewResolver.class);

    private PebbleEngine pebbleEngine;

    public PebbleViewResolver() {
        log.debug("使用 PebbleViewResolver 作为 ViewResolver.");
        setViewClass(requiredViewClass());
    }

    @Override
    protected Class<?> requiredViewClass() {
        return PebbleView.class;
    }

    @Override
    protected View loadView(String viewName, Locale locale) throws PebbleException {

        // Spring 有时候会私自给 viewName 加尾巴，我斩～～
        if(viewName.endsWith(".html")) {
            viewName = viewName.substring(0, viewName.length()-5);
        }
        PebbleView view = new PebbleView(pebbleEngine.getTemplate(viewName));
        view.setApplicationContext(getApplicationContext());
        view.setServletContext(getServletContext());

        return view;

    }

    public void setPebbleEngine(PebbleEngine pebbleEngine) {
        this.pebbleEngine = pebbleEngine;
    }


}
{'fraction_non_alphanumeric': 0.09970769730431958, 'fraction_numerical': 0.007794738551477752, 'mean_word_length': 4.049180327868853, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2561361', 'n_tokens_mistral': 1015, 'n_tokens_neox': 990, 'n_words': 175}