Skip to content

make TemplateEngine configurable (see #211), reloaded#213

Merged
gitblit merged 1 commit into
masterfrom
config_template_engine
Sep 1, 2015
Merged

make TemplateEngine configurable (see #211), reloaded#213
gitblit merged 1 commit into
masterfrom
config_template_engine

Conversation

@decebals

@decebals decebals commented Sep 1, 2015

Copy link
Copy Markdown
Member

Implementation based on this comment.

I have a updated pippo-demo-template on pipe:

public class PebbleDemo {

    public static void main(String[] args) {
        // .peb is the default file extension
//        Pippo pippo = new Pippo(new TemplateApplication(new PebbleTemplateEngine(), "pebble/hello"));
        Pippo pippo = new Pippo(new TemplateApplication(new MyPebbleTemplateEngine(), "pebble/hello"));
        pippo.start();
    }

    public static class MyPebbleTemplateEngine extends PebbleTemplateEngine {

        @Override
        protected void init(PebbleEngine engine) {
            engine.addExtension(new AbstractExtension() {

                @Override
                public Map<String, Filter> getFilters() {
                    Map<String, Filter> filters = new HashMap<>();
                    filters.put("myupper", new MyUpperFilter());

                    return filters;
                }

            });
        }

    }

    public static class MyUpperFilter implements Filter {

        @Override
        public List<String> getArgumentNames() {
            return null;
        }

        @Override
        public Object apply(Object input, Map<String, Object> args){
            return (input != null) ? ((String) input).toUpperCase() : null;
        }

    }

}

gitblit added a commit that referenced this pull request Sep 1, 2015
make TemplateEngine configurable (see #211), reloaded
@gitblit
gitblit merged commit f2f0f57 into master Sep 1, 2015
@gitblit

gitblit commented Sep 1, 2015

Copy link
Copy Markdown
Collaborator

👍 Looks good.

@decebals
decebals deleted the config_template_engine branch September 1, 2015 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants