You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Michael Wyraz <mi...@evermind.de> on 2014/05/14 12:59:29 UTC

JavaScript stack vs JavaScript module / best practice?

Hi,

I wonder when to use a stack, a module or both. For example I want to 
use "MetisMenu" (small jquery plugin that uses bootstrap/collapse and 
comes with some css).

If I use Stack only, I can define js+css but I cannot define that it 
requires jquery + bootstrap/collapse. (I could modify the original 
plugin code but I'd prefre to keep it unchanged).

If I use Module, I can define it's dependency but cannot include the CSS.

So I'll end up in using both, the following way:

from MetisMenuStack.java:

         List<StackExtension> config=new ArrayList<>();

         config.add(StackExtension.module("MetisMenu"));
config.add(StackExtension.stylesheet("classpath:META-INF/assets/metismenu-1.0.1/jquery.metisMenu.css"));

from MyTapestryModule.java:

     @Contribute(JavaScriptStackSource.class)
     public static void addMyStack(MappedConfiguration<String, 
JavaScriptStack> configuration)
     {
         configuration.addInstance("MetisMenu", MetisMenuStack.class);
     }
     @Contribute(ModuleManager.class)
     public static void setupModule(MappedConfiguration<String, Object> 
configuration,
@Path("classpath:META-INF/assets/metismenu-1.0.1/jquery.metisMenu.js") 
Resource metismenu)
     {
         configuration.add("MetisMenu", new 
JavaScriptModuleConfiguration(metismenu).dependsOn("bootstrap/collapse"));
     }

Is this the right way to do it? It looks a bit wired to me because:
- MetisMenuStack declares that it gets loaded by MetisMenu module. 
Normally the module should declare that it requires the css (i.e. the 
stack).
- All this is spread across multiple (at least two) classes. Especially 
the definition of which assets belong together is split across both 
classes (module asset in TapestryModule, CSS asset in the stack definition).

How can I do it better?

Kind regards,
Michael.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org