zoukankan      html  css  js  c++  java
  • Gradle Goodness: Parse Files with SimpleTemplateEngine in Copy Task

    With the copy task of Gradle we can copy files that are parsed by Groovy's SimpleTemplateEngine. This means we can expand properties in the source file and add Groovy code that is going to be executed. We must use the expand() method in the copy task where we can pass properties to be used in the source file.

    00.version = 'DEMO'
    01.group = 'com.mrhaki'
    02. 
    03.task copy(type: Copy) {
    04.from 'src/templates'
    05.into "$buildDir"
    06.include 'projectinfo.html.template'
    07.rename { file -> 'projectinfo.html' }
    08.expand(project: project, title: 'ProjectInfo', generated: new Date())
    09.}

    We define the following source file in src/templates/projectinfo.html.template:

    00.<html>
    01.<head>
    02.<title>${title}</title>
    03.</head>
    04.<body>
    05.<h1>${project.name}</h1>
    06. 
    07.<ul>
    08.<% project.properties.findAll { k,v -> v instanceof String }.each { key, value -> %>
    09.<li>$key = $value</li>
    10.<% } %>
    11.</ul>
    12. 
    13.<hr />
    14.<p>Generated on ${generated.format('dd-MM-yyyy')}</p>
    15.</body>
    16.</html>

    When we run the copy task we get the following output:

  • 相关阅读:
    快速幂算法
    TIME-April
    数据结构之splay树
    数据结构学习路线
    智能优化技术(四) 蚁群优化算法
    智能优化学习目录
    模式识别(四)人工神经网络
    模式识别(一) 决策树分类
    模式识别学习
    poj 2676 Sudoku
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4189108.html
Copyright © 2011-2022 走看看