使用方法在groovy中设置表格样式
我正在用groovy构建一封html电子邮件,我想用一种方法为我的元素设置样式。我想使用createTableCSS方法为我的表格设置样式。但它不起作用。样式已超出表标记的范围使用方法在groovy中设置表格样式,groovy,html-table,styling,Groovy,Html Table,Styling,我正在用groovy构建一封html电子邮件,我想用一种方法为我的元素设置样式。我想使用createTableCSS方法为我的表格设置样式。但它不起作用。样式已超出表标记的范围 String createTableCSS(String width, String border, String cellSpacing, String background, String classes ){ return "'width':'"+width+"'" } def responseDoc =
String createTableCSS(String width, String border, String cellSpacing, String background, String classes ){
return "'width':'"+width+"'"
}
def responseDoc = job.addDocument("ECommerce_test.html"){out ->
def xmlWriter = new OutputStreamWriter(out)
MarkupBuilder html = new MarkupBuilder(xmlWriter)
html.doubleQuotes = true
html.expandEmptyElements = true
html.omitEmptyAttributes = false
html.omitNullAttributes = false
html.escapeAttributes = false
html.html(lang:'en') {
head {
title('E-Commerce email')
base('target':'_blank')
meta('http-equiv' : 'Content-Type', 'content' : 'text/html; charset=ISO-8859-1')
meta('name':'viewport', 'content':'width=320')
style(type:"text/css", '''
''')
}
body('style':'padding:0; margin:0; -webkit-text-size-adjust:none; width:100%;','bgcolor':'#F2F2F2') {
div(){
table(){ //Container table
tr(){
td('width':'20','class':'nomob'){
}
td('align':'center'){
table(createTableCSS("640", "", "", "", "")){
}
}
td(){
}
}
}
}
} //End <body>
} //End <html>
}
String createTableCSS(字符串宽度、字符串边框、字符串单元格间距、字符串背景、字符串类){
返回“'width':”+width+“”
}
def responseDoc=job.addDocument(“ECommerce_test.html”){out->
def xmlWriter=新的OutputStreamWriter(输出)
MarkupBuilder html=新的MarkupBuilder(xmlWriter)
html.doubleQuotes=true
html.expandEmptyElements=true
html.ommitEmptyAttributes=false
html.null属性=false
html.escapeAttributes=false
html.html(lang:'en'){
头{
标题(“电子商务电子邮件”)
基本(“目标”:“空白”)
meta('http-equiv':'Content-Type','Content':'text/html;charset=ISO-8859-1')
meta('name':'viewport','content':'width=320')
样式(类型:“文本/css”和“
''')
}
正文('style':'padding:0;margin:0;-webkit文本大小调整:无;宽度:100%;','bgcolor':'#f2f2'){
分区(){
table(){//容器表
tr(){
td('width':'20','class':'nomob'){
}
td('align':'center'){
表(createTableCSS(“640”、“0”、“0”、“0”、“0”){
}
}
td(){
}
}
}
}
}//结束
}//结束
}
结果是这样的
<table>'width':'640'</table>
<table width:"640"></table>
“宽度”:“640”
应该是这样的
<table>'width':'640'</table>
<table width:"640"></table>
我不需要方法也可以做到这一点,但我真的很想知道如何在这种代码中使用方法。这里的问题是,使用此方法会导致在表闭包中指定一个字符串作为参数。您需要的是一个返回映射的方法。您可以通过将方法替换为以下方法来解决此问题:
def createTableCSS(String width, String border, String cellSpacing, String background, String classes) {
return [width: width]
}
这里的问题是,使用此方法会导致在表闭包中指定一个字符串作为参数。您需要的是一个返回映射的方法。您可以通过将方法替换为以下方法来解决此问题:
def createTableCSS(String width, String border, String cellSpacing, String background, String classes) {
return [width: width]
}