I noticed in the Closure Stylesheet docs that you can define your own custom functions in Java when you use the
--gss-function-map-provider flag.
Is there this option with GWT?
I did notice that GwtGssFunctionMapProvider provides extra GSS GWT functions, but found no way of extending this for my own custom methods. The GssResourceGenerator constructs it via a new. It would be nice to extend GwtGssFunctionMapProvider, or create a new class that GwtGssFunctionMapProvider uses to add custom functions.
I would propose changing GwtGssFunctionMapProvider to:
public class GwtGssFunctionMapProvider extends DefaultGssFunctionMapProvider {
private final ResourceContext context;
public GwtGssFunctionMapProvider() {
}
public void setResourceContext(ResourceContext context) {
this.context = context;
}
@Override
public Map<String, GssFunction> get() {
Map<String, GssFunction> gssFunctionMap = super.get();
return ImmutableMap.<String, GssFunction>builder().putAll(gssFunctionMap)
// TODO add a namespace for gwt-specific function ?
.put(EvalFunction.getName(), new EvalFunction())
.put(ValueFunction.getName(), new ValueFunction())
.put(ResourceUrlFunction.getName(), new ResourceUrlFunction(context))
.build();
}
}
This would allow it to be constructed with no arguments, which allows Reflection to easily be used to construct the object. Next we could change GssResourceGenerator to look for a configuration-property to be added to the gwt.xml file to define the new class that must extend GwtGssFunctionMapProvider, could then add custom functions.
If this sounds like an interesting approach, I could start coding a patch to accomplish this.
Thanks,
Jeffrey