Coverage Summary for Class: CSSPlugin (kweb.plugins.css)
Class |
Class, %
|
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
CSSPlugin |
0%
(0/1)
|
0%
(0/3)
|
|
0%
(0/8)
|
0%
(0/51)
|
package kweb.plugins.css
import kweb.plugins.KwebPlugin
import kweb.plugins.staticFiles.ResourceFolder
import kweb.plugins.staticFiles.StaticFilesPlugin
import org.jsoup.nodes.Document
/**
* Add multiple CSS files to your Kweb app from your resources folder.
*
* @property resourceFolder The relative path to the folder in the src/main/resources folder where the .css files are located
* @property fileNames The list of file names located in the resourceFolder which should be added to the website. Only files with suffix .css (case-insensitive) will be linked
*
* @author Cyneath
*/
class CSSPlugin(private val resourceFolder: String, private val fileNames: Set<String>) : KwebPlugin(dependsOn = setOf(StaticFilesPlugin(ResourceFolder(resourceFolder), "/kweb_static/css"))) {
constructor(resourceFolder: String, fileName: String) : this(resourceFolder, setOf(fileName))
override fun decorate(doc: Document) {
fileNames.filter { f -> f.endsWith(".css", true) }.forEach {
doc.head().appendElement("link")
.attr("rel", "stylesheet")
.attr("type", "text/css")
.attr("href", "/kweb_static/css/$it")
}
}
}