-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read external resources locally when generating html report #404
Merged
takahirom
merged 14 commits into
takahirom:main
from
eyedol:295-inlineHtmlReportsResources
Jun 18, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f2cf09b
Read external resources locally when generating html report
eyedol f11dc4b
Use webjars for web assets
eyedol 0ffb2d0
Move function for writing web asset to its own class
eyedol 12e0128
Simplify how to locate webjar files
eyedol 72cf195
Minor clean up
eyedol b65cc85
Load internal css last
eyedol cf8de79
Minor clean up
eyedol 2b7b652
Remove unneeded local files
eyedol 589d969
Minor clean up
eyedol 5d333ee
If index.html file not found throw an error
eyedol 0acb0cb
Fix function name
eyedol 4252666
Remove unused declaration
eyedol 9864d9d
Show all tabs available
eyedol 008fabf
Make error message more clearer
eyedol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...de-build/roborazzi-gradle-plugin/src/main/java/io/github/takahirom/roborazzi/WebAssets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.github.takahirom.roborazzi | ||
|
||
import org.webjars.WebJarVersionLocator | ||
import java.io.File | ||
|
||
class WebAssets private constructor(private val webJarVersionLocator: WebJarVersionLocator) { | ||
private val materializeCss = "materializecss" | ||
private val materialIcons = "material-design-icons" | ||
private val webJarResource = "resources" | ||
|
||
fun writeToRoborazziReportsDir(reportDir: File) { | ||
writeLocalAssetsToRoborazziReportsDir(reportDir) | ||
writeWebJarAssetsToRoborazziReportsDir(reportDir) | ||
} | ||
|
||
private fun writeLocalAssetsToRoborazziReportsDir(reportDir: File) { | ||
writeAssets( | ||
assetName = "report-style.css", | ||
exactPath = "assets/report-style.css", | ||
reportDir = reportDir | ||
) | ||
} | ||
|
||
private fun writeWebJarAssetsToRoborazziReportsDir(reportDir: File) { | ||
mapOf( | ||
materializeCss to listOf( | ||
"css/materialize.min.css", | ||
"js/materialize.min.js", | ||
), | ||
materialIcons to listOf( | ||
"material-icons.css", | ||
"MaterialIcons-Regular.ttf", | ||
) | ||
).forEach { (key, value) -> | ||
value.forEach { exactPath -> | ||
webJarVersionLocator.locate(key, exactPath)?.let { | ||
writeAssets( | ||
assetName = exactPath.substringAfterLast("/"), | ||
exactPath = "$webJarResource/$it", | ||
reportDir = reportDir | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun outputFile(directory: File, filename: String): File { | ||
return File(directory, filename).apply { | ||
parentFile.apply { if (!exists()) mkdirs() } | ||
} | ||
} | ||
|
||
private fun WebJarVersionLocator.locate(webJarName: String, exactPath: String) = run { | ||
path(webJarName, exactPath)?.let { "webjars/$it" } | ||
} | ||
|
||
private fun writeAssets( | ||
assetName: String, | ||
exactPath: String, | ||
reportDir: File | ||
) { | ||
val assetsDirectory = File(reportDir, "assets") | ||
val asset = this::class.java | ||
.classLoader | ||
.getResource("META-INF/$exactPath")?.readBytes() | ||
if (asset != null) { | ||
val assetFile = outputFile(assetsDirectory, assetName) | ||
assetFile.writeBytes(asset) | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
fun create( | ||
webJarVersionLocator: WebJarVersionLocator = WebJarVersionLocator() | ||
): WebAssets = WebAssets(webJarVersionLocator) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
include-build/roborazzi-gradle-plugin/src/main/resources/META-INF/assets/report-style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.container { | ||
width: 90%; | ||
} | ||
|
||
h3 { | ||
color: orange; | ||
} | ||
|
||
a, .menu { | ||
color: white; | ||
} | ||
|
||
th a, td a { | ||
display: block; | ||
color: black; | ||
} | ||
|
||
.material-icons { | ||
color: #29b6f6; | ||
} | ||
|
||
.us { | ||
color: #ffcc80; | ||
} | ||
|
||
#imageBottomSheet { | ||
max-height: 100%; | ||
top: 15%; | ||
} | ||
|
||
#modalImage { | ||
max-width: 100%; | ||
} |
66 changes: 66 additions & 0 deletions
66
include-build/roborazzi-gradle-plugin/src/main/resources/META-INF/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>Roborazzi report</title> | ||
<!-- Compiled and minified CSS --> | ||
<link href="assets/materialize.min.css" rel="stylesheet" /> | ||
<link href="assets/material-icons.css" rel="stylesheet" /> | ||
|
||
<link href="assets/report-style.css" rel="stylesheet"/> | ||
</head> | ||
<body> | ||
<nav role="navigation" class="light-blue lighten-1"> | ||
<div class="nav-wrapper container"> | ||
<a href="#" class="brand-logo">Roborazzi report</a> | ||
<a href="#" data-target="nav-mobile" class="sidenav-trigger"> | ||
<i class="material-icons menu">menu</i> | ||
</a> | ||
</div> | ||
</nav> | ||
<div class="section"> | ||
<div class="container"> | ||
<p>REPORT_TEMPLATE_BODY</p> | ||
</div> | ||
</div> | ||
|
||
<div id="imageBottomSheet" class="modal bottom-sheet max-height"> | ||
<div class="modal-content center-align"> | ||
<img id="modalImage" src="" alt=""> | ||
</div> | ||
</div> | ||
|
||
<footer class="page-footer orange"> | ||
<div class="container"> | ||
<a class="us" href="https://github.com/takahirom/roborazzi" target="_blank" | ||
rel="noopener noreferrer">Roborazzi</a> | ||
<br> | ||
<br> | ||
</div> | ||
</footer> | ||
<!-- Compiled and minified JavaScript --> | ||
<script src="assets/materialize.min.js"></script> | ||
<script> | ||
M.AutoInit(); | ||
document.addEventListener('DOMContentLoaded', function() { | ||
M.Tabs.getInstance(document.getElementsByClassName("tabs")[0]).select('results'); | ||
var modalInstance = M.Modal.init(document.getElementById('imageBottomSheet'), {}); | ||
var modal = document.getElementById('imageBottomSheet'); | ||
var modalImage = document.getElementById('modalImage'); | ||
var modalTriggers = document.querySelectorAll('.modal-trigger'); | ||
modalTriggers.forEach(function(trigger) { | ||
trigger.addEventListener('click', function() { | ||
var src = this.getAttribute('src'); | ||
var alt = this.getAttribute('data-alt'); | ||
modalImage.setAttribute('src', src); | ||
modalImage.setAttribute('alt', alt); | ||
var instance = M.Modal.getInstance(modal); | ||
instance.open(); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. The CSS from the webjar packing seems a little old. The styling is a little off from
main
Looking to see if there is a recently one published with webjar.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed it, but it's a subtle change. So I think it is ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, however not all the tabs shows. That I think needs to be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved it with 9864d9d. All the tabs shows now though we lost the fixed sized tabs. I believe it should be okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now scroll through the tabs! Thank you!