Class | Buildr::Filter |
In: |
lib/buildr/core/filter.rb
(CVS)
|
Parent: | Object |
A filter knows how to copy files from one directory to another, applying mappings to the contents of these files.
You can specify the mapping using a Hash, and it will map ${key} fields found in each source file into the appropriate value in the target file. For example:
filter.using 'version'=>'1.2', 'build'=>Time.now
will replace all occurrences of ${version} with 1.2, and ${build} with the current date/time.
You can also specify the mapping by passing a proc or a method, that will be called for each source file, with the file name and content, returning the modified content.
Without any mapping, the filter simply copies files from the source directory into the target directory.
A filter has one target directory, but you can specify any number of source directories, either when creating the filter or calling from. Include/exclude patterns are specified relative to the source directories, so:
filter.include '*.png'
will only include PNG files from any of the source directories. In the same way, you can use regular expressions, so:
filter.include /picture_.*\.png/
will only include PNG files starting with picture_ from any of the sources directories.
See Buildr#filter.
sources | [R] | Returns the list of source directories (each being a file task). |
Adds additional directories from which to copy resources.
For example:
filter.from('src').into('target').using('build'=>Time.now)
Specifies the mapping to use and returns self.
The most typical mapping uses a Hash, and the default mapping uses the Maven style, so ${key} are mapped to the values. You can change that by passing a different format as the first argument. Currently supports:
For example:
filter.using 'version'=>'1.2'
Is the same as:
filter.using :maven, 'version'=>'1.2'
You can also pass a proc or method. It will be called with the file name and content, to return the mapped content.
Without any mapping, all files are copied as is.
To register new mapping type see the Mapper class.