Hooks provides a way for Scala programs to support plugins and optional features.
Under development The Hooks library is still being developed. Details will change before it's ready for release.
Annotate your code with special hooks:
val nameFilter = FilterHook[String]()
val userSavedAction = ActionHook[User]()
Call into that hook in your program code:
val displayName = nameFilter(user.name)
userSavedAction(user)
Plugins can attach behaviours to that hook to modify it:
nameFilter.hook { name => name.toUpperCase }
userSavedAction.hook { user => sendNotificationEmail(user) }
Features group these modifications:
object Uppercase extends Feature("Uppercase") {
def init() {
nameFilter.hook { name => name.toUpperCase }
}
}
Select which features you want to use when running code:
val features = List(Uppercase, AnotherFeature)
val displayName = FeatureRepository.using(features) {
nameFilter(user.name)
}
Features can depend on each other and they'll be kept together:
object Uppercase extends Feature("Uppercase",
depend = List(AnotherFeature)) {
You can control the order you want features to be initialised:
object Uppercase extends Feature("Uppercase",
depend = List(AnotherFeature)
before = List(AnotherFeature)) {
Load plugins from a directory:
val folder = new File("homedir/plugins")
val classpath = List(new File("myapplication.jar"))
new PluginLoader(folder, classpath, ".jar").hookAll()
You can add the Hooks library to your SBT project by putting this into your build file:
libraryDependencies += "cc.minotaur" %% "hooks" % "0.1"
Note that at present Hooks is compatible with Scala versions 2.9.0 and 2.9.1.
-
Start here: Quick Start →
-
[Getting Started](https://github.com/marcusatbang/Hooks/wiki/Getting Started)
-
[Advanced Topics](https://github.com/marcusatbang/Hooks/wiki/Advanced Topics)
-
- Basic application
- Website using the Play! framework (not yet implemented)
- Loading plugins from a directory