Skip to content

Commit

Permalink
add path method
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesward committed Apr 7, 2024
1 parent 441dcc5 commit 993e011
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/webjars/WebJarVersionLocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ public String fullPath(final String webJarName, final String exactPath) {
}
}

/**
*
* @param webJarName The name of the WebJar, i.e. bootstrap
* @param exactPath The path to the file within the WebJar, i.e. js/bootstrap.js
* @return The path to the file in the standard WebJar classpath location, including the version, i.e. bootstrap/3.1.1/js/bootstrap.js
*/
@Nullable
public String path(final String webJarName, final String exactPath) {
String maybeFullPath = fullPath(webJarName, exactPath);
if (maybeFullPath != null) {
return maybeFullPath.replace(WEBJARS_PATH_PREFIX + "/", "");
}
else {
return null;
}
}

/**
* @param webJarName The name of the WebJar, i.e. bootstrap
* @return The version of the WebJar, i.e 3.1.1
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/org/webjars/WebJarVersionLocatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public void full_path_exists_version_not_supplied() {
assertEquals(WebJarVersionLocator.WEBJARS_PATH_PREFIX + "/bootstrap/3.1.1/js/bootstrap.js", new WebJarVersionLocator().fullPath("bootstrap", "js/bootstrap.js"));
}

@Test
public void path_exists_version_not_supplied() {
assertEquals("bootstrap/3.1.1/js/bootstrap.js", new WebJarVersionLocator().path("bootstrap", "js/bootstrap.js"));
}

@Test
public void full_path_exists_version_supplied() {
assertEquals(WebJarVersionLocator.WEBJARS_PATH_PREFIX + "/bootstrap/3.1.1/js/bootstrap.js", new WebJarVersionLocator().fullPath("bootstrap", "3.1.1/js/bootstrap.js"));
Expand Down

0 comments on commit 993e011

Please sign in to comment.