package soy;

import com.google.common.collect.ImmutableSet;
import com.google.template.soy.data.SoyMapData;
import com.google.template.soy.data.SoyRecord;
import play.mvc.Controller;
import play.twirl.api.Html;

import javax.inject.Inject;
import java.util.Locale;

public class Soy extends Controller {

    private final SoyRenderer soyRenderer;

    @Inject
    public Soy(final SoyRenderer soyRenderer) {
        this.soyRenderer = soyRenderer;
    }

    public Html html(final String templateName, final SoyRecord model) {
        return Html.apply(soyRenderer.render(templateName, locale(), request(), response(), model, ImmutableSet.of()));
    }

    public Html html(final String templateName) {
        return Html.apply(soyRenderer.render(templateName, locale(), request(), response(), new SoyMapData()));
    }

    private Locale locale() {
        return request().acceptLanguages().stream()
                .findFirst().map(lang -> new Locale(lang.language()))
                .orElse(Locale.ENGLISH);
    }

}

@@ -251,22 +251,96 @@
 va.util.
-Locale
+Arrays;%0Aimport java.util.Locale;%0Aimport java.util.Optional;%0Aimport java.util.Set
 ;%0A%0Apubli
@@ -593,24 +593,102 @@
 rd model) %7B%0A
+        final Set%3CString%3E activeDelegatePackages = activeDelegatePackages();%0A%0A
         retu
@@ -778,25 +778,30 @@
 el, 
-ImmutableSet.of()
+activeDelegatePackages
 ));%0A
@@ -853,24 +853,102 @@
 lateName) %7B%0A
+        final Set%3CString%3E activeDelegatePackages = activeDelegatePackages();%0A%0A
         retu
@@ -1043,16 +1043,40 @@
 apData()
+, activeDelegatePackages
 ));%0A    
@@ -1278,10 +1278,358 @@
 %0A    %7D%0A%0A
+    private Set%3CString%3E activeDelegatePackages() %7B%0A        return Optional.ofNullable(request().getQueryString(%22soyActivePackages%22))%0A                .map(str -%3E str.split(%22,%22))%0A                .map(values -%3E Arrays.asList((values)))%0A                .map(list -%3E ImmutableSet.%3CString%3EcopyOf(list))%0A                .orElse(ImmutableSet.of());%0A    %7D%0A%0A
 %7D%0A

active delegate packages