(refs #32)Example of custom action extension

This commit is contained in:
Naoki Takezoe
2014-06-05 21:22:16 +09:00
parent 6f666ca49f
commit b0b318ce30
3 changed files with 55 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
package plugin
import app.Context
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
/**
* Provides extension points to plug-ins.
@@ -9,8 +10,10 @@ object PluginSystem {
private val repositoryMenuList = scala.collection.mutable.ListBuffer[Menu]()
private val globalMenuList = scala.collection.mutable.ListBuffer[Menu]()
private val actionList = scala.collection.mutable.ListBuffer[Action]()
case class Menu(label: String, url: String, icon: String, condition: Context => Boolean)
case class Action(path: String, function: (HttpServletRequest, HttpServletResponse) => Any)
def addRepositoryMenu(label: String, url: String, icon: String = "")(condition: Context => Boolean): Unit = {
repositoryMenuList += Menu(label, url, icon, condition)
@@ -20,16 +23,21 @@ object PluginSystem {
globalMenuList += Menu(label, url, icon, condition)
}
def addAction(path: String): Unit = {
// TODO
def addAction(path: String)(function: (HttpServletRequest, HttpServletResponse) => Any): Unit = {
actionList += Action(path, function)
}
def repositoryMenus: List[Menu] = repositoryMenuList.toList
def globalMenus: List[Menu] = globalMenuList.toList
lazy val repositoryMenus: List[Menu] = repositoryMenuList.toList
lazy val globalMenus: List[Menu] = globalMenuList.toList
lazy val actions: List[Action] = actionList.toList
// TODO This is a test
addGlobalMenu("Google", "http://www.google.co.jp/"){ context => context.loginAccount.isDefined }
addAction("/hello"){ (request, response) =>
"Hello World!"
}
}