GSS Custom Functions

140 views
Skip to first unread message

Jeffrey Kleiss

unread,
Feb 18, 2015, 6:49:46 PM2/18/15
to google-web-tool...@googlegroups.com
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

Julien Dramaix

unread,
Feb 19, 2015, 4:19:40 PM2/19/15
to google-web-tool...@googlegroups.com
Hi Jeffrey,

Indeed this is a functionality we have to add (I've talked about that in my presentation about GSS at gwt.create) for GWT 2.8.

But  it's not a good idea to give the possibility to developers to change the behavior of GwtGssFunctionMapProvider by extending it and giving their own implementation.

I think the best approach is that add a configuration-property named "CssResource.customGssFunctionMapProvider". This value of this property must be the fully qualified name of a class implementing the interface com.google.gwt.thirdparty.common.css.GssFunctionMapProvider

Then the GssResourceGenerator looks to this property and create an instance of this class and pass this instance to the GwtGssFunctionMapProvider. 

GwtGssFunctionMapProvider will add the functions defined in this custom GssMapFunctionProvider at the end of its map.

If you could propose a patch for that it would be great. Don't hesitate to contact me if you need more info.

Julien 


--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/3135e1af-bdce-45ed-bfbf-4d3192573e25%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages