提交 c5cb67be 编写于 作者: K Kohsuke Kawaguchi

Merge pull request #205 from wolfs/master

Added base class for groovy view modularization
...@@ -651,6 +651,21 @@ THE SOFTWARE. ...@@ -651,6 +651,21 @@ THE SOFTWARE.
</archive> </archive>
</configuration> </configuration>
</plugin> </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> </plugins>
</build> </build>
...@@ -672,7 +687,7 @@ THE SOFTWARE. ...@@ -672,7 +687,7 @@ THE SOFTWARE.
<configuration> <configuration>
<dependencyLocationsEnabled>false</dependencyLocationsEnabled> <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</reporting> </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 package jenkins.plugins.ui_samples.ModularizeViewScript
import org.kohsuke.stapler.jelly.groovy.JellyBuilder import org.kohsuke.stapler.jelly.groovy.JellyBuilder
import lib.FormTagLib import jenkins.util.groovy.AbstractGroovyViewModule
namespace("/lib/samples").sample(title:_("Define View Fragments Elsewhere")) { namespace("/lib/samples").sample(title:_("Define View Fragments Elsewhere")) {
...@@ -19,18 +20,14 @@ 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. // 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 // this class can be defined anywhere, and typically you'd do this somewhere in your src/main/groovy
static class SomeGenerator { static class SomeGenerator extends AbstractGroovyViewModule {
JellyBuilder b;
FormTagLib f;
SomeGenerator(JellyBuilder builder) { SomeGenerator(JellyBuilder builder) {
this.b = builder super(builder)
f = builder.namespace(FormTagLib.class)
} }
def generateSomeFragment() { def generateSomeFragment() {
b.h2("Two") h2("Two")
b.div(style:"background-color:gray; padding:2em") { 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 p("Hello") // once inside a closure, no explicit 'b.' reference is needed. this is just like other Groovy builders
// calling other methods // calling other methods
...@@ -39,7 +36,7 @@ static class SomeGenerator { ...@@ -39,7 +36,7 @@ static class SomeGenerator {
} }
def generateMoreFragment(String msg) { def generateMoreFragment(String msg) {
b.h2(msg); h2(msg);
f.textarea(); f.textarea();
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册