/** * use fixed variation value to trigger {@link LessResourceStreamLocator} * * @return static string {@link LessResourceReference#VARIATION} if less is active */ @Override public final String getVariation() { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().useLessCompiler() ? VARIATION : null; } }
/** * Render the current active {@link ITheme} which includes all {@link org.apache.wicket.request.resource.ResourceReference} objects * and the {@link de.agilecoders.wicket.markup.html.themes.bootstrap.BootstrapResponsiveCssReference} * if enabled to the response. Also it allows all subclasses to get the {@link IBootstrapSettings} by overriding this method. * * @param settings the bound {@link IBootstrapSettings} * @param headerResponse the current {@link IHeaderResponse} */ public void renderHead(IBootstrapSettings settings, IHeaderResponse headerResponse) { ITheme theme = settings.getActiveThemeProvider().getActiveTheme(); theme.renderHead(headerResponse); if (settings.useResponsiveCss()) { headerResponse.render(CssHeaderItem.forReference(settings.getResponsiveCssResourceReference())); } } }
/** * render the {@link de.agilecoders.wicket.markup.html.references.BootstrapJavaScriptReference} and if active * the {@link de.agilecoders.wicket.markup.html.references.JqueryPPJavaScriptReference} to * the response. * * @param settings the bound {@link IBootstrapSettings} * @param headerResponse the current {@link IHeaderResponse} */ @Override public void renderHead(IBootstrapSettings settings, IHeaderResponse headerResponse) { super.renderHead(settings, headerResponse); final JavaScriptReferenceHeaderItem jsReference = JavaScriptHeaderItem.forReference(settings.getJsResourceReference(), new PageParameters(), "bootstrap-js", true); References.renderWithFilter(settings, headerResponse, jsReference); if (settings.useJqueryPP()) { JavaScriptReferenceHeaderItem jqueryPP = JavaScriptHeaderItem.forReference(settings.getJqueryPPResourceReference(), new PageParameters(), "jquerypp-js", true); References.renderWithFilter(settings, headerResponse, jqueryPP); } } }
/** * Installs given settings for given application * * @param app The current application * @param settings The settings to use */ public static void install(final Application app, final IBootstrapSettings settings) { app.setMetaData(BOOTSTRAP_SETTINGS_METADATA_KEY, settings); if (settings.getBootstrapLessCompilerSettings().useLessCompiler()) { app.getResourceSettings().setResourceStreamLocator(new CachingResourceStreamLocator(new LessResourceStreamLocator())); } if (settings.updateSecurityManger()) { updateSecurityManager(app, settings); } }
@Override protected void onConfigure() { super.onConfigure(); if (Bootstrap.getSettings(getApplication()).useModernizr()) { add(new CssClassNameAppender("no-js")); } if (locale != null) { add(new AttributeModifier("lang", toAttributeValue(locale()))); } add(new CssClassNameAppender(createBrowserShortcut(clientProperties))); add(new CssClassNameAppender("theme-" + Bootstrap.getSettings().getActiveThemeProvider().getActiveTheme().name())); }
@Override public Iterable<? extends HeaderItem> getDependencies() { List<HeaderItem> dependencies = Lists.newArrayList(super.getDependencies()); dependencies.add(JavaScriptHeaderItem.forReference(Bootstrap.getSettings().getJsResourceReference())); return dependencies; } }
/** * Construct. Uses {@link de.agilecoders.wicket.settings.IBootstrapSettings#getJsResourceFilterName()} * as filter name. */ public RenderJavaScriptToFooterHeaderResponseDecorator() { this(Bootstrap.getSettings().getJsResourceFilterName()); }
@Test public void minificationIdentifierWasAppended() { getBootstrapSettings().minify(true); Assert.assertThat(References.appendMinificationIdentifier("file.ext"), is(equalTo("file.min.ext"))); }
/** * adds a ".min" extension in front of original extension if minimization is active. * If filename doesn't contain an extension no ".min" part will be added. * <p/> * e.g. "file.js" will be "file.min.js" * * @param referenceUrl The file name * @return file name containing ".min" */ public static String appendMinificationIdentifier(final String referenceUrl) { if (!Strings.isNullOrEmpty(referenceUrl) && referenceUrl.contains(".") && (Bootstrap.getSettings(Application.get()).isMinified())) { return referenceUrl.replaceFirst("\\.(?=[^.]*$)", ".min."); } return Strings.nullToEmpty(referenceUrl); }
/** * @return the {@link ThemeProvider} implementation */ private ThemeProvider themeProvider() { if (Application.exists()) { return Bootstrap.getSettings().getThemeProvider(); } else { throw new WicketRuntimeException("no application assigned to current thread"); } }
@Override public Iterable<? extends HeaderItem> getDependencies() { List<HeaderItem> dependencies = Lists.newArrayList(super.getDependencies()); dependencies.add(JavaScriptHeaderItem.forReference(Bootstrap.getSettings().getJsResourceReference())); dependencies.add(CssHeaderItem.forReference(PrettyCssResourceReference.INSTANCE)); return dependencies; } }
/** * renders a given header item with filter if present. * * @param settings The bootstrap settings * @param response The current header response * @param headerItem The header item to render */ public static void renderWithFilter(final IBootstrapSettings settings, final IHeaderResponse response, final JavaScriptReferenceHeaderItem headerItem) { final String filterName = settings.getJsResourceFilterName(); if (Strings.isNullOrEmpty(filterName)) { response.render(headerItem); } else { response.render(new FilteredHeaderItem(headerItem, filterName)); } }
@Test public void minificationIdentifierWasntAppended() { getBootstrapSettings().minify(false); Assert.assertThat(References.appendMinificationIdentifier("file.ext"), is(equalTo("file.ext"))); }
/** * @return true if less compiler should be used. */ private static boolean useLessCompiler() { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().useLessCompiler(); }
/** * @return charset setting */ protected final Charset getCharset() { if (Application.exists()) { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().getCharset(); } else { LOG.warn("no application assigned to current thread, return default charset: {}", Charsets.UTF_8); return Charsets.UTF_8; } } }
/** * Gets the {@link LessJsLessCompiler} to be used. By default returns the configured compiler on * application level, but can be overridden by the user application to provide compiler * specific to the resource. * * @return the configured application level less compiler. May be {@code null}. */ private static IBootstrapLessCompiler getCompiler() { if (Application.exists()) { return Bootstrap.getSettings().getBootstrapLessCompilerSettings().getLessCompiler(); } throw new IllegalStateException("there is no application assigned to current thread."); }
@Override public String asText() { InputStream stream = null; try { stream = getInputStream(); return IOUtils.toString(stream, Bootstrap.getSettings(Application.get()).getBootstrapLessCompilerSettings().getCharset().name()); } catch (IOException e) { throw new WicketRuntimeException(e); } finally { IOUtils.closeQuietly(stream); } }
@Override protected IBootstrapSettings createBootstrapSettings() { IBootstrapSettings settings = super.createBootstrapSettings(); settings.getBootstrapLessCompilerSettings() .setUseLessCompiler(true) .setCacheStrategy(IBootstrapLessCompilerSettings.CacheStrategy.Never); return settings; }
@Override protected void onBefore() { try { cssContent = IOUtils.toString(BootswatchCssReference.CERULEAN.getResource().getResourceStream().getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } catch (ResourceStreamNotFoundException e) { throw new RuntimeException(e); } getBootstrapSettings().getBootstrapLessCompilerSettings() .setCacheStrategy(IBootstrapLessCompilerSettings.CacheStrategy.Never) .setUseLessCompiler(true); }
/** * updates the security manager to allow fonts and less files if necessary. * * @param app The current application * @param settings The settings to use */ private static void updateSecurityManager(final Application app, final IBootstrapSettings settings) { final IPackageResourceGuard packageResourceGuard = app.getResourceSettings().getPackageResourceGuard(); if (packageResourceGuard instanceof SecurePackageResourceGuard) { SecurePackageResourceGuard guard = (SecurePackageResourceGuard) packageResourceGuard; guard.addPattern("+*.woff"); guard.addPattern("+*.eot"); guard.addPattern("+*.svg"); guard.addPattern("+*.ttf"); if (settings.getBootstrapLessCompilerSettings().useLessCompiler()) { guard.addPattern("+*.less"); } } }