Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

Commit

Permalink
Delegate url generation for templates to configured URL handler inste…
Browse files Browse the repository at this point in the history
…ad of

calling URLUtil directly. The default implementation still calls URLUtil
to generate the URLs.

This allows other URL handler implementations to convert a URL to a method
call and generate a url from a method reference
  • Loading branch information
Chris Gow committed Jul 26, 2012
1 parent 422f8a0 commit 74310e9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ronin/src/ronin/IRoninUtilsEnhancement.gsx
Expand Up @@ -153,7 +153,7 @@ enhancement IRoninUtilsEnhancement : IRoninUtils {
*/
@URLMethodValidator
static function urlFor(target : MethodReference) : String {
return URLUtil.urlFor(target)
return Ronin.Config.URLHandler.urlFor(target)
}

/**
Expand Down
4 changes: 4 additions & 0 deletions ronin/src/ronin/config/DefaultURLHandler.gs
Expand Up @@ -3,6 +3,7 @@ package ronin.config
uses ronin.*
uses java.net.*
uses gw.lang.reflect.*
uses gw.lang.reflect.features.MethodReference

/**
* Default implementation of {@link ronin.config.IURLHandler}. Looks up a type in the "controller"
Expand All @@ -11,6 +12,9 @@ uses gw.lang.reflect.*
* if one or both path components are missing.
*/
class DefaultURLHandler implements IURLHandler {
override function urlFor(target : MethodReference) : String {
return URLUtil.urlFor(target)
}

override function getControllerMethod(request : String[]) : IMethodInfo {
var controllerType = getControllerType(request)
Expand Down
7 changes: 7 additions & 0 deletions ronin/src/ronin/config/IURLHandler.gs
@@ -1,6 +1,7 @@
package ronin.config

uses gw.lang.reflect.IMethodInfo
uses gw.lang.reflect.features.MethodReference

/**
* Represents an object responsible for locating a controller method given a URL.
Expand All @@ -15,4 +16,10 @@ interface IURLHandler {
*/
function getControllerMethod(request : String[]) : IMethodInfo

/**
* Generates a URL that this handler is capable of handling based on the specified target method reference
* @param target The controller method that will be executed from this URL
* @return The URL as string
*/
function urlFor(target : MethodReference) : String
}

0 comments on commit 74310e9

Please sign in to comment.