1

I have a CSS file that I use for testing. It @imports all of my stylesheets:

@import "css/structure.css"
@import "css/typography.css"
@import "css/forms.css"

This lets me test the styling and changes, but in a way that you'd never want live.

When I "build" this project, I'd like to find all of these references (RegEx css/(.*?.css)) and then use that list as a FileSet to then merge and compress.

The merging and compressing are, oddly, the easiest part. I'm at a complete loss on how to use RegEx to build my FileSet.

If I have to go to a .properties file, I will, but I was hoping for something that could be more automated.

Appreciate any thoughts...

—Nate

nathanziarek
  • 619
  • 1
  • 6
  • 16

2 Answers2

0

Is standard file globbing not working? Have you tried:

<fileset dir="${resource.dir}" casesensitive="yes">
  <include name="**/*.css"/>
</fileset>

See the FileSet Type documentation for more info.

hoipolloi
  • 7,984
  • 2
  • 27
  • 28
  • That works great for a lot of what I'm doing, but for the CSS and JS files, they need to be loaded in a certain order. All the examples I've seen have you list them out in a properties file, which is fine, it's just double work. We already list them, and in order, so I was hoping I could just scrape through that data. – nathanziarek Aug 02 '11 at 12:48
0

I'm far and away not a great RegEx'er, but I think I found my solution:

I created a target that loads my main styles.css file, scrapes the individual files from it and places it all in a comma-separated property:

    <!-- Get CSS Filelist -->
<target name="get.css">
    <loadfile property="list-temp.css" srcFile="${source_dev}/css/styles.css"/>
    <propertyregex property="list-temp2.css" input="${list-temp.css}" regexp='[\s|.]*?@import url\("(.*?)"\);\s' replace="\1," casesensitive="false" global="true" />
    <propertyregex property="list-temp3.css" input="${list-temp2.css}" regexp=',$' replace="" casesensitive="false" global="true" />
    <propertyregex property="list.css" input="${list-temp3.css}" regexp='/\*.*?\*/' replace="" casesensitive="false" global="true" />
    <echo>${list.css}</echo>
</target>

That results in ${list.css} = "one.css, two.css, structure.css, etc.css" which I can then use as a file list / file set.

It isn't pretty, but it works. I wish I could rewrite that RegEx to something more robust (right now, you forget a semi-colon or use single quotes and it's busted) ... but beggars can't be choosers!

Thanks for the help hoipolloi!

nz

nathanziarek
  • 619
  • 1
  • 6
  • 16