mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
(refs #32)Example of custom action extension
This commit is contained in:
@@ -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!"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user