Skip to content

Commit

Permalink
Translate additional module resource paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
brett-smith committed Sep 2, 2024
1 parent b624cb8 commit eaf36b3
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 36 deletions.
5 changes: 5 additions & 0 deletions plugins/bootstrap5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,10 @@
<artifactId>jquery</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>npm</groupId>
<artifactId>jquery-treegrid</artifactId>
<version>0.3.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -228,59 +228,111 @@ public final static void flash(TemplateModel model) {
}

public final static TemplateModel danger(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.DANGER).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asDanger(bundle, key, args)).template();
}

public static Alert asDanger(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.DANGER).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel danger(String message) {
return of(new Builder().withStyle(Style.DANGER).withTitle(message).build()).template();
return of(asDanger(message)).template();
}

public static Alert asDanger(String message) {
return new Builder().withStyle(Style.DANGER).withTitle(message).build();
}

public final static TemplateModel primary(String message) {
return of(new Builder().withStyle(Style.PRIMARY).withTitle(message).build()).template();
return of(asPrimary(message)).template();
}

public static Alert asPrimary(String message) {
return new Builder().withStyle(Style.PRIMARY).withTitle(message).build();
}

public final static TemplateModel primary(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.PRIMARY).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asPrimary(bundle, key, args)).template();
}

public static Alert asPrimary(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.PRIMARY).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel success(String message) {
return of(new Builder().withStyle(Style.SUCCESS).withTitle(message).build()).template();
return of(asSuccess(message)).template();
}

public static Alert asSuccess(String message) {
return new Builder().withStyle(Style.SUCCESS).withTitle(message).build();
}

public final static TemplateModel success(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.SUCCESS).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asSuccess(bundle, key, args)).template();
}

public static Alert asSuccess(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.SUCCESS).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel warning(String message) {
return of(new Builder().withStyle(Style.WARNING).withTitle(message).build()).template();
}

public final static TemplateModel warning(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.WARNING).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asWarning(bundle, key, args)).template();
}

public static Alert asWarning(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.WARNING).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel info(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.INFO).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asInfo(bundle, key, args)).template();
}

public static Alert asInfo(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.INFO).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel info(String message) {
return of(new Builder().withStyle(Style.INFO).withTitle(message).build()).template();
return of(asInfo(message)).template();
}

public static Alert asInfo(String message) {
return new Builder().withStyle(Style.INFO).withTitle(message).build();
}

public final static TemplateModel light(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.LIGHT).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asLight(bundle, key, args)).template();
}

public static Alert asLight(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.LIGHT).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel light(String message) {
return of(new Builder().withStyle(Style.LIGHT).withTitle(message).build()).template();
return of(asLight(message)).template();
}

public static Alert asLight(String message) {
return new Builder().withStyle(Style.LIGHT).withTitle(message).build();
}

public final static TemplateModel dark(Class<?> bundle, String key, Object... args) {
return of(new Builder().withStyle(Style.DARK).withTitleKey(key, args).withBundle(bundle).build()).template();
return of(asDark(bundle, key, args)).template();
}

public static Alert asDark(Class<?> bundle, String key, Object... args) {
return new Builder().withStyle(Style.DARK).withTitleKey(key, args).withBundle(bundle).build();
}

public final static TemplateModel dark(String message) {
return of(new Builder().withStyle(Style.DARK).withTitle(message).build()).template();
return of(asDark(message)).template();
}

public static Alert asDark(String message) {
return new Builder().withStyle(Style.DARK).withTitle(message).build();
}

public enum Style {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import static com.sshtools.bootlace.api.GAV.ofSpec;
import static com.sshtools.jenny.web.NpmWebModule.of;

import com.sshtools.bootlace.api.GAV;
import com.sshtools.bootlace.api.Plugin;
import com.sshtools.jenny.web.NpmWebModule;
import com.sshtools.jenny.web.WebModule;
import com.sshtools.jenny.web.WebModule.Type;
import com.sshtools.jenny.web.WebModule.WebModuleResource;
import com.sshtools.tinytemplate.bootstrap.forms.Form;

public class Bootstrap5 implements Plugin {
Expand All @@ -32,6 +34,14 @@ public class Bootstrap5 implements Plugin {
ofSpec("npm:jquery")
);

public final static WebModule MODULE_JQUERY_TREEGRID = new NpmWebModule.Builder().
withClass(Bootstrap5.class).
withMain("js/jquery.treegrid.min.js").
withGAV(GAV.ofSpec("npm:jquery-treegrid")).
withRequires(MODULE_JQUERY).
addResources(WebModuleResource.css(Bootstrap5.class, "css/jquery.treegrid.css")).
build();

public final static WebModule MODULE_BOOTSTRAP5 = new NpmWebModule.Builder().
withGAV(ofSpec("npm:bootstrap")).
withClass(Bootstrap5.class).
Expand All @@ -55,6 +65,14 @@ public class Bootstrap5 implements Plugin {
withRequires(MODULE_BOOTSTRAP5).
build();

public final static WebModule MODULE_BOOTSTRAP_TABLE_TREEGRID = new NpmWebModule.Builder().
withMain("dist/extensions/treegrid/bootstrap-table-treegrid.min.js").
withType(Type.JS).
withGAV(ofSpec("npm:bootstrap-table")).
withClass(Bootstrap5.class).
withRequires(MODULE_JQUERY_TREEGRID, MODULE_BOOTSTRAP_TABLE).
build();

public final static WebModule MODULE_BOOTSTRAP5_AUTOCOMPLETE =
of(
Bootstrap5.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<input type="hidden" name="name">

<t:if component.navigation>
<div class="btn-group float-end" role="group"
<div class="btn-group" role="group"
aria-label="Breadcrumbs">
<t:if navAction.cd>
<a id="cd" href="${ui-path}${query-options}"
Expand Down
4 changes: 3 additions & 1 deletion web/src/main/java/com/sshtools/jenny/web/NpmWebModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ public WebModule build() {
var bldr = new WebModule.Builder();
bldr.withName(toNpm(gav));
bldr.withLoader(loader);
bldr.addResources(this.resources);
bldr.withUri("/" + resource);
bldr.withRequires(this.requires);
bldr.asDirectory();
bldr.addResources(this.resources.stream().map(resx ->
resx.translate(resource)
).toList());

var packages = props.getProperty("resource") + "/package.json";
var pkgres = loader.getResource(packages);
Expand Down
4 changes: 4 additions & 0 deletions web/src/main/java/com/sshtools/jenny/web/ResourceRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public Handler handler() {
return classpathResource(base(), path());
}
}

public ResourceRef translate(String uri) {
return new ResourceRef(base, loader, uri + "/" + path);
}
}
3 changes: 2 additions & 1 deletion web/src/main/java/com/sshtools/jenny/web/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.sshtools.jenny.web;

import java.io.FileNotFoundException;
import java.nio.file.NoSuchFileException;
import java.util.function.Consumer;

Expand Down Expand Up @@ -59,7 +60,7 @@ public void get(Transaction tx) throws Exception {
tx.selector(c.getKey());
try {
c.getValue().get(tx);
} catch (NoSuchFileException fnfe) {
} catch (NoSuchFileException | FileNotFoundException fnfe) {
if (LOG.debug())
LOG.debug("File not found. {0}", fnfe.getMessage());
tx.notFound();
Expand Down
23 changes: 17 additions & 6 deletions web/src/main/java/com/sshtools/jenny/web/Web.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ public void afterOpen(PluginContext context) {
withClasspathResources("/(.*)", getClass().getClassLoader(), "web/");

configureServer(bldr);


bldr.handle(new AllSelector(), tx -> tx.responseCode(Status.NOT_FOUND));

httpd = bldr.build();

httpd.start();
Expand Down Expand Up @@ -243,6 +245,10 @@ public TemplateModel require(TemplateModel template, WebModulesRef modules) {

}

public RootContext httpd() {
return httpd;
}

public Router router() {
return router;
}
Expand Down Expand Up @@ -279,11 +285,13 @@ private void addModules(ArrayList<Route> l, HashSet<String> m, WebModule... modu
*/
for(var module : modules) {
if(!this.modules.containsKey(module.name())) {
var hndl = router().route().
handle(module.pattern(), module.handler()).
build();

l.add(hndl);
if(module.hasHandler()) {
var hndl = router().route().
handle(module.pattern(), module.handler()).
build();

l.add(hndl);
}
this.modules.put(module.name(), module);
m.add(module.name());
}
Expand Down Expand Up @@ -317,6 +325,9 @@ private void configureServer(RootContextBuilder bldr) {
}
});

/* TODO Arggh... The "view source" in firefox bug when compression is on really needs fixing */
bldr.withoutCompression();

webConfig.ini().sectionOr("ncsa").ifPresent(cfg -> {
bldr.withLogger(new NCSALoggerBuilder().
withAppend(cfg.getBoolean("append", true)).
Expand Down
Loading

0 comments on commit eaf36b3

Please sign in to comment.