1

I have a css file with a variable section that I want to remove from the file when I run my build script (but I'll need to keep the section in the source). I'm thinking I'd wrap the section in comments (/* remove-front / & / remove-back */) with some sort of tokens and then use ant to replace everything between the comments with nothing.

Here's my example:

/* 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 */

Thanks in advance for your response.

2 Answers 2

1

I had the same thought as @FailedDev, but when trying out my Eclipse, it was balking at the "m" option (and I've added a the ability to use /*remove-front */ (spaces) and /*REMOVE-BACK*/ (case-insensitivity):

<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"/>
Sign up to request clarification or add additional context in comments.

4 Comments

I simply used the "tokens" of the OP. I assume he will use these tokens and not arbitrary ones.
True enough, one thing puzzled me though, flags="gm", didn't work when I tried it with Ant 1.7 on Eclipse, hence me using flags="gs" (the i is my not-really-required case-insensitivity)
You are right. I only tried the regex with a different program. gs is needed :) +1 from me :)
Thanks for the regex guys, it worked like a charm. I had tried with replaceregexp, but my regex wasn't strong enough to know what I was doing. I'll add it to my list of things to study.
0

I would use the standard replaceregexp task :

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.