1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <div class="entry"> <span class="entry-date"> <g:longDate>${entryInstance.lastUpdated}</g:longDate> : ${entryInstance.author} </span> <h2><g:link action="show" id="${entryInstance.id}">${entryInstance.title}</g:link></h2> <p>${entryInstance.summary}</p> <g:if test="${entryInstance.filename}"> <p> <img src="${createLinkTo(dir:'payload/'+entryInstance.author.login, file:''+entryInstance.filename)}" alt="${entryInstance.filename}" title="${entryInstance.filename}" /> </p> </g:if> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | class EntryTagLib { def displayFile = {attrs, body-> def user = attrs["user"] def filename = attrs["filename"] if(filename){ def extension = filename.split("\\.")[-1] def userDir = "payload/${user}" switch(extension.toUpperCase()){ case ["JPG", "PNG", "GIF"]: def html = """ <p> <img src="${createLinkTo(dir:''+userDir, file:''+filename)}" alt="${filename}" title="${filename}" /> </p> """ out << html break case "HTML": out << "p>html</p>" break default: out << "<p>file</p>" break } }else{ out << "<!-- no file -->" } } } |
1 2 3 4 5 6 7 8 9 10 11 | <div class="entry"> <span class="entry-date"> <g:longDate>${entryInstance.lastUpdated}</g:longDate> : ${entryInstance.author} </span> <h2><g:link action="show" id="${entryInstance.id}">${entryInstance.title}</g:link></h2> <p>${entryInstance.summary}</p> <g:displayFile filename="${entryInstance.filename}" user="${entryInstance.author.login}" /> </div> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | class EntryTagLib { def displayFile = {attrs, body-> def user = attrs["user"] def filename = attrs["filename"] if(filename){ def extension = filename.split("\\.")[-1] def userDir = "payload/${user}" switch(extension.toUpperCase()){ case ["JPG", "PNG", "GIF"]: //SNIP break case "HTML": def webRootDir = servletContext.getRealPath("/") out << new File(webRootDir+"/"+userDir, filename).text break default: def html = """ <p> <a href="${createLinkTo(dir:''+userDir, file:''+filename)}">${filename}</a> </p> """ out << html break } }else{ out << "<!-- no file -->" } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //test.html <p> This is some <b>test</b> HTML. </p> <p> Here is a link to the <a href="http://grails.org">Grails</a> homepage. </p> <p> And here is a link to the <img src="//grails.org/images/grails-logo.png">Grails Logo</img>. </p> //noextension This file doesn't have an extension. |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |