【问题标题】:replace multiple variable content lines of css using ant使用ant替换css的多个可变内容行
【发布时间】:2011-10-06 08:09:40
【问题描述】:

我有一个带有可变部分的 css 文件,我想在运行构建脚本时从文件中删除它(但我需要将该部分保留在源代码中)。我想我会用某种标记将部分包装在 cmets (/* remove-front / & / remove-back */) 中,然后使用 ant 将 cmets 之间的所有内容替换为什么都没有。

这是我的例子:

/* remove-front */
.footerGradients {
  /* gradient settings (used http://www.colorzilla.com/gradient-editor/ to generate following code) */

  background-color: #606869;
  background: -webkit-gradient(linear, left bottom, left top, color-stop(0, #2f3838), color-stop(100%, #606869));
  background: -moz-linear-gradient(center bottom, #2f3838 0, #606869 100%);
  background: -ms-linear-gradient(center bottom, #2f3838 0, #606869 100%);
  background: -o-linear-gradient(center bottom, #2f3838 0, #606869 100%);
  background: linear-gradient(center bottom, #2f3838 0, #606869 100%);
  -pie-background: linear-gradient(#2f3838, #606869);
  filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#2f3838,endColorstr=#606869);
  /* end gradient settings */

}
.footerShadows {
  /* box shadow settings (used http://css3generator.com/ to generate following code) */

  -webkit-box-shadow: 0 0 2px 0 #293535;
  -moz-box-shadow: 0 0 2px 0 #293535;
  box-shadow: 0 0 2px 0 #293535;
  /* end box shadow settings */

}
/* remove-back */

提前感谢您的回复。

【问题讨论】:

    标签: css ant build-script


    【解决方案1】:

    我和@FailedDev 有同样的想法,但是在尝试我的 Eclipse 时,它​​对“m”选项犹豫不决(我添加了使用/*remove-front */(空格)和/*REMOVE-BACK*/(不区分大小写):

    <copy tofile="src/test2.css" file="src/test.css" overwrite="true"/>
    <replaceregexp 
       file="src/test2.css" 
       match="/\*\s*remove-front\s*\*/.*?/\*\s*remove-back\s*\*/"
       replace=""
       flags="gsi" 
       byline="false"/>
    

    【讨论】:

    • 我只是使用了 OP 的“令牌”。我假设他会使用这些令牌而不是任意令牌。
    • 确实,有件事让我感到困惑,flags="gm",当我在 Eclipse 上使用 Ant 1.7 尝试它时不起作用,因此我使用 flags="gs"i 不是我的 -真正需要的不区分大小写)
    • 你是对的。我只用不同的程序尝试了正则表达式。需要 gs :) 我 +1 :)
    • 感谢正则表达式的家伙,它就像一个魅力。我曾尝试使用 replaceregexp,但我的正则表达式不够强大,无法知道我在做什么。我会把它添加到我的学习清单中。
    【解决方案2】:

    我会使用标准的 replaceregexp 任务:

    http://ant.apache.org/manual/Tasks/replaceregexp.html

     <replaceregexp file="${css.file}"
                    match="/\* remove-front \*/.*?/\* remove-back \*/"
                    replace=""
                    byline="false"
                    flags="gs"
    />
    

    【讨论】:

      猜你喜欢
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 2014-04-24
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多