Skip to content

Commit

Permalink
add bootstrap-theme.css as theme, fix issue in GoogleCssReference (re…
Browse files Browse the repository at this point in the history
…lated to issue #349)
  • Loading branch information
l0rdn1kk0n committed Jul 1, 2014
1 parent cb1ff9e commit e67a05b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.agilecoders.wicket.themes.markup.html.bootstrap;

import de.agilecoders.wicket.core.settings.Theme;

/**
* # Description
*
* java representation of `bootstrap-theme.css` which is an enhanced default bootstrap theme.
*
* # Usage
*
* ```
* public void init() {
* final IBootstrapSettings settings = new BootstrapSettings();
* Bootstrap.install(this, settings);
* // theme provider must be set after `install` because it needs webjars.
* settings.setThemeProvider(new SingleThemeProvider(new BootstrapThemeTheme()));
* }
* ```
*
* @author Michael Haitz <[email protected]>
*/
public class BootstrapThemeTheme extends Theme {

/**
* Constructor.
*
* @param name the theme name
*/
public BootstrapThemeTheme(String name) {
super(name, BootstrapThemeThemeCssReference.instance());
}

/**
* Construct using default theme name: `bootstrap-theme`.
*/
public BootstrapThemeTheme() {
this("bootstrap-theme");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package de.agilecoders.wicket.themes.markup.html.bootstrap;

import de.agilecoders.wicket.core.Bootstrap;
import de.agilecoders.wicket.core.util.Dependencies;
import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.HeaderItem;

/**
* # Description
*
* The BootstrapThemeThemeCssReference uses the latest version of bootstrap-theme.css from the `org.webjars.bootstrap`
* dependency which is defined in `pom.xml`. This reference has a dependency to base bootstrap css reference, but there
* will be no version conflicts between this reference and the `bootstrap.css` from `BootstrapCssReference` because both
* will are loaded from same jar file.
*
* # Usage
*
* this css resource reference can be used directly:
* ```java
* response.render(CssHeaderItem.forReference(BootstrapThemeThemeCssReference.instance()));
* ```
*
* or together with bootstrap theme:
*
* ```
* settings.setThemeProvider(new SingleThemeProvider(new BootstrapThemeTheme()));
* ```
*
* @author Michael Haitz <[email protected]>
*/
public class BootstrapThemeThemeCssReference extends WebjarsCssResourceReference {
private static final long serialVersionUID = 1L;

/**
* @return singleton instance of {@link de.agilecoders.wicket.themes.markup.html.bootstrap.BootstrapThemeThemeCssReference}
*/
public static BootstrapThemeThemeCssReference instance() {
return Holder.INSTANCE;
}

/**
* Singleton instance of this reference
*/
private static final class Holder {
private static final BootstrapThemeThemeCssReference INSTANCE = new BootstrapThemeThemeCssReference();
}

/**
* Private constructor to prevent instantiation.
*/
private BootstrapThemeThemeCssReference() {
super("/bootstrap/current/css/bootstrap-theme.css");
}

@Override
public Iterable<? extends HeaderItem> getDependencies() {
return Dependencies.combine(super.getDependencies(),
CssHeaderItem.forReference(Bootstrap.getSettings().getCssResourceReference()));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package de.agilecoders.wicket.themes.markup.html.google;

import de.agilecoders.wicket.core.Bootstrap;
import de.agilecoders.wicket.jquery.util.Generics2;
import de.agilecoders.wicket.core.util.Dependencies;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.HeaderItem;
import org.apache.wicket.request.resource.CssResourceReference;

import java.util.List;

/**
* # Description
*
Expand Down Expand Up @@ -47,9 +45,7 @@ private GoogleCssReference() {

@Override
public Iterable<? extends HeaderItem> getDependencies() {
final List<HeaderItem> dependencies = Generics2.newArrayList(super.getDependencies());
dependencies.add(CssHeaderItem.forReference(Bootstrap.getSettings().getCssResourceReference()));

return dependencies;
return Dependencies.combine(super.getDependencies(),
CssHeaderItem.forReference(Bootstrap.getSettings().getCssResourceReference()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.agilecoders.wicket.themes.markup.html.google;

import de.agilecoders.wicket.core.markup.html.themes.bootstrap.BootstrapCssReference;
import de.agilecoders.wicket.core.settings.Theme;

/**
Expand All @@ -23,11 +22,11 @@ public class GoogleTheme extends Theme {
* Construct.
*/
public GoogleTheme(final String name) {
super(name, BootstrapCssReference.instance(), GoogleCssReference.instance());
super(name, GoogleCssReference.instance());
}

/**
* Construct.
* Construct using default theme name: `google`
*/
public GoogleTheme() {
this("google");
Expand Down

0 comments on commit e67a05b

Please sign in to comment.