grails.doc.macros.GspTagSourceMacro.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grails-docs Show documentation
Show all versions of grails-docs Show documentation
Grails Web Application Framework
package grails.doc.macros
import java.util.regex.Pattern
import org.radeox.macro.BaseMacro
import org.radeox.macro.CodeMacro
import org.radeox.macro.parameter.BaseMacroParameter
import org.radeox.macro.parameter.MacroParameter
import org.radeox.util.Encoder
class GspTagSourceMacro extends BaseMacro {
List baseDirs
GspTagSourceMacro(basedir) {
if (!(basedir instanceof Collection || basedir.class.array)) basedir = [ basedir ]
baseDirs = basedir.collect { f -> f as File }
}
String getName() { "source" }
void execute(Writer out, MacroParameter params) {
def source = params.params.get("0")
def i = source.indexOf('=')
def type = source[0..i-1]
def name = source[i+1..-1]
String code
switch (type) {
case "tag":
def j = name.indexOf('.')
def className = name[0..j-1]
def tagName = name[j+1..-1]
Pattern regex = ~/(?s)(\s*?def\s+?$tagName\s*?=\s*?\{\s*?attrs\s*?,{0,1}\s*?(body){0,1}\s*?->.+?)(\/\*\*|def\s*[a-zA-Z]+?\s*=\s*\{)/
// Recursively search for the tag library source file in the
// configured base directory.
def tagLibFile = null
baseDirs.find { dir ->
dir.traverse(nameFilter: /${className}.groovy/) { tagLibFile = it }
return tagLibFile
}
def text = tagLibFile?.text ?: ""
def matcher = regex.matcher(text)
if (matcher.find()) {
out << ''
out << " "
}
break
}
}
}