提交 599c0155 编写于 作者: S Stefan Wolf

Added base class to modularize groovy view scripts

上级 29270bf1
......@@ -651,6 +651,21 @@ THE SOFTWARE.
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.kohsuke.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<!-- version specified in grandparent pom -->
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
......@@ -672,7 +687,7 @@ THE SOFTWARE.
<configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration>
</plugin>
</plugin>
</plugins>
</reporting>
......
package jenkins.util.groovy
import lib.FormTagLib
import lib.LayoutTagLib
import org.kohsuke.stapler.jelly.groovy.JellyBuilder
import org.kohsuke.stapler.jelly.groovy.Namespace
import lib.JenkinsTagLib
/**
* Base class for utility classes for Groovy view scripts
* <p />
* Usage from script of a subclass, say ViewHelper:
* <p />
* <tt>new ViewHelper(delegate).method();</tt>
* <p />
* see <tt>ModularizeViewScript</tt> in ui-samples for an example how to use this class.
*
* @author Stefan Wolf (wolfs)
*/
abstract class AbstractGroovyViewModule {
JellyBuilder builder
FormTagLib f
LayoutTagLib l
JenkinsTagLib t
Namespace st
public AbstractGroovyViewModule(JellyBuilder b) {
builder = b
f= builder.namespace(FormTagLib)
l=builder.namespace(LayoutTagLib)
t=builder.namespace(JenkinsTagLib)
st=builder.namespace("jelly:stapler")
}
def methodMissing(String name, args) {
builder.invokeMethod(name,args)
}
def propertyMissing(String name) {
builder.getProperty(name)
}
def propertyMissing(String name, value) {
builder.setProperty(name, value)
}
}
package jenkins.plugins.ui_samples.ModularizeViewScript
import org.kohsuke.stapler.jelly.groovy.JellyBuilder
import lib.FormTagLib
import jenkins.util.groovy.AbstractGroovyViewModule
namespace("/lib/samples").sample(title:_("Define View Fragments Elsewhere")) {
......@@ -19,18 +20,14 @@ namespace("/lib/samples").sample(title:_("Define View Fragments Elsewhere")) {
// I defined this class here just to make the sample concise.
// this class can be defined anywhere, and typically you'd do this somewhere in your src/main/groovy
static class SomeGenerator {
JellyBuilder b;
FormTagLib f;
static class SomeGenerator extends AbstractGroovyViewModule {
SomeGenerator(JellyBuilder builder) {
this.b = builder
f = builder.namespace(FormTagLib.class)
super(builder)
}
def generateSomeFragment() {
b.h2("Two")
b.div(style:"background-color:gray; padding:2em") {
h2("Two")
div(style:"background-color:gray; padding:2em") {
p("Hello") // once inside a closure, no explicit 'b.' reference is needed. this is just like other Groovy builders
// calling other methods
......@@ -39,7 +36,7 @@ static class SomeGenerator {
}
def generateMoreFragment(String msg) {
b.h2(msg);
h2(msg);
f.textarea();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册