use of org.apache.tapestry5.services.javascript.JavaScriptStack in project tapestry-5 by apache.
the class JavaScriptStackPathConstructorImpl method constructPathsForJavaScriptStack.
public List<String> constructPathsForJavaScriptStack(String stackName) {
JavaScriptStack stack = javascriptStackSource.getStack(stackName);
List<Asset> assets = stack.getJavaScriptLibraries();
// if there is more than one library asset, or any modules.
if (combineScripts && stack.getJavaScriptAggregationStrategy().enablesCombine()) {
boolean needsVirtual = (assets.size() > 1) || (!stack.getModules().isEmpty());
if (needsVirtual) {
return combinedStackURL(stackName, stack);
}
}
return toPaths(assets);
}
use of org.apache.tapestry5.services.javascript.JavaScriptStack in project tapestry-5 by apache.
the class JavaScriptModule method setupCoreJavaScriptStack.
/**
* The core JavaScriptStack has a number of entries:
* <dl>
* <dt>requirejs</dt> <dd>The RequireJS AMD JavaScript library</dd>
* <dt>scriptaculous.js, effects.js</dt> <dd>Optional JavaScript libraries in compatibility mode (see {@link Trait#SCRIPTACULOUS})</dd>
* <dt>t53-compatibility.js</dt> <dd>Optional JavaScript library (see {@link Trait#INITIALIZERS})</dd>
* <dt>underscore-library, underscore-module</dt>
* <dt>The Underscore JavaScript library, and the shim that allows underscore to be injected</dt>
* <dt>t5/core/init</dt> <dd>Optional module related to t53-compatibility.js</dd>
* <dt>jquery-library</dt> <dd>The jQuery library</dd>
* <dt>jquery-noconflict</dt> <dd>Switches jQuery to no-conflict mode (only present when the infrastructure is "prototype").</dd>
* <dt>jquery</dt> <dd>A module shim that allows jQuery to be injected (and also switches jQuery to no-conflict mode)</dd>
* <dt>bootstrap.css, tapestry.css, exception-frame.css, tapestry-console.css, tree.css</dt>
* <dd>CSS files</dd>
* <dt>t5/core/[...]</dt>
* <dd>Additional JavaScript modules</dd>
* <dt>jquery</dt>
* <dd>Added if the infrastructure provider is "jquery".</dd>
* </dl>
*
* User modules may replace or extend this list.
*/
@Contribute(JavaScriptStack.class)
@Core
public static void setupCoreJavaScriptStack(OrderedConfiguration<StackExtension> configuration, Compatibility compatibility, @Symbol(SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER) String provider) {
configuration.add("requirejs", StackExtension.library(ROOT + "/require.js"));
configuration.add("underscore-library", StackExtension.library(ROOT + "/underscore-1.8.3.js"));
if (provider.equals("prototype")) {
final String SCRIPTY = "${tapestry.scriptaculous}";
add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/prototype.js");
if (compatibility.enabled(Trait.SCRIPTACULOUS)) {
add(configuration, StackExtensionType.LIBRARY, SCRIPTY + "/scriptaculous.js", SCRIPTY + "/effects.js");
}
}
if (compatibility.enabled(Trait.INITIALIZERS)) {
add(configuration, StackExtensionType.LIBRARY, ROOT + "/t53-compatibility.js");
configuration.add("t5/core/init", new StackExtension(StackExtensionType.MODULE, "t5/core/init"));
}
configuration.add("jquery-library", StackExtension.library(ROOT + "/jquery.js"));
if (provider.equals("prototype")) {
configuration.add("jquery-noconflict", StackExtension.library(ROOT + "/jquery-noconflict.js"));
}
add(configuration, StackExtensionType.MODULE, "jquery");
add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.FONT_AWESOME_ROOT + "}/css/font-awesome.css");
if (compatibility.enabled(Trait.BOOTSTRAP_3) && compatibility.enabled(Trait.BOOTSTRAP_4)) {
throw new RuntimeException("You cannot have Trait.BOOTSTRAP_3 and Trait.BOOTSTRAP_4 enabled at the same time. Check your contributions to the Compatibility service.");
}
if (compatibility.enabled(Trait.BOOTSTRAP_3)) {
addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
}
if (compatibility.enabled(Trait.BOOTSTRAP_4)) {
addCoreStylesheets(configuration, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap.css");
add(configuration, StackExtensionType.STYLESHEET, "${" + SymbolConstants.BOOTSTRAP_ROOT + "}/css/bootstrap-grid.css");
}
if (!compatibility.enabled(Trait.BOOTSTRAP_3) && !compatibility.enabled(Trait.BOOTSTRAP_4)) {
configuration.add("defaultcss", StackExtension.stylesheet("${" + SymbolConstants.DEFAULT_STYLESHEET + "}"));
}
for (String name : bundledModules) {
String full = "t5/core/" + name;
configuration.add(full, StackExtension.module(full));
}
configuration.add("underscore-module", StackExtension.module("underscore"));
}
use of org.apache.tapestry5.services.javascript.JavaScriptStack in project tapestry-5 by apache.
the class JavaScriptStackPathConstructorImpl method combinedStackURL.
private List<String> combinedStackURL(String stackName, JavaScriptStack stack) {
try {
StreamableResource assembled = assembler.assembleJavaScriptResourceForStack(stackName, compressionAnalyzer.isGZipSupported(), stack.getJavaScriptAggregationStrategy());
String path = threadLocale.getLocale().toString() + '/' + stackName + ".js";
String stackURL = assetPathConstructor.constructAssetPath(RequestConstants.STACK_FOLDER, path, assembled);
return CollectionFactory.newList(stackURL);
} catch (IOException ex) {
throw new RuntimeException(String.format("Unable to construct path for '%s' JavaScript stack: %s", stackName, ExceptionUtils.toMessage(ex)), ex);
}
}
use of org.apache.tapestry5.services.javascript.JavaScriptStack in project tapestry-5 by apache.
the class StackAssetRequestHandler method streamStackResource.
private boolean streamStackResource(String extraPath) throws IOException {
Matcher matcher = pathPattern.matcher(extraPath);
if (!matcher.matches()) {
logger.warn("Unable to parse '{}' as an asset stack path", extraPath);
return false;
}
String checksum = matcher.group(1);
String localeName = matcher.group(2);
final String stackName = matcher.group(3);
final boolean compressed = checksum.startsWith("z");
if (compressed) {
checksum = checksum.substring(1);
}
final JavaScriptStack stack = stackSource.findStack(stackName);
if (stack == null) {
logger.warn("JavaScript stack '{}' not found.", stackName);
return false;
}
// Yes, I have a big regret that the JavaScript stack stuff relies on this global, rather than
// having it passed around properly.
localizationSetter.setNonPersistentLocaleFromLocaleName(localeName);
StreamableResource resource = tracker.perform(String.format("Assembling JavaScript asset stack '%s' (%s)", stackName, localeName), new IOOperation<StreamableResource>() {
public StreamableResource perform() throws IOException {
return javaScriptStackAssembler.assembleJavaScriptResourceForStack(stackName, compressed, stack.getJavaScriptAggregationStrategy());
}
});
if (resource == null) {
return false;
}
return resourceStreamer.streamResource(resource, checksum, ResourceStreamer.DEFAULT_OPTIONS);
}
Aggregations