Permalink
Browse files

refinements on filters

  • Loading branch information...
1 parent 1c0ed3e commit 7d2a1351df8722f5081a9a7af9c7f7983934e445 @drewfish committed Apr 11, 2012
Showing with 36 additions and 4 deletions.
  1. +1 −1 Readme.md
  2. +22 −0 crank.json
  3. +13 −3 lib/crank.js
View
@@ -102,7 +102,7 @@ updates changelog. {file} defaults to `Changelog.md`
* `dateformat`: string
* format to use for revision dates
* `filters`: list of objects describing how to modify versions
- * `subject`: "version", "date", "changeid", "changes"
+ * `subject`: "version", "date", "changeid"
* `regexp`: string
* `replace`: "string"
* if results in `--CRANK:SKIP--` then version is skipped
View
@@ -0,0 +1,22 @@
+{
+ "//": "just an example of some things that are possible",
+
+ "changelog": {
+ "changes": {
+ "filters": [
+ {
+ "//": "skip changes that just update the changelog",
+ "subject": "message",
+ "regexp": "^updated changelog$",
+ "replace": "--CRANK:SKIP--"
+ },
+ {
+ "//": "skip changes that just update the version",
+ "subject": "message",
+ "regexp": "^updated version$",
+ "replace": "--CRANK:SKIP--"
+ }
+ ]
+ }
+ }
+}
View
@@ -165,7 +165,7 @@ Base.prototype.filter = function(list, filters) {
var regexps = {},
f, filter,
i, item,
- skip,
+ subject, skip,
out = [];
if (! filters.length) {
@@ -176,6 +176,10 @@ Base.prototype.filter = function(list, filters) {
// slight optimization
for (f = 0; f < filters.length; f++) {
filter = filters[f];
+ if ('changes' === filter.subject) {
+ console.error('WARNING: illegal filter subject "changes". skipping.');
+ continue;
+ }
regexps[filter.regexp] = new RegExp(filter.regexp);
}
@@ -184,11 +188,17 @@ Base.prototype.filter = function(list, filters) {
item = list[i];
for (f = 0; f < filters.length; f++) {
filter = filters[f];
- item[filter.subject] = item[filter.subject].replace(regexps[filter.regexp], filter.replace);
- if (item[filter.subject] === '--CRANK:SKIP--') {
+ if ('changes' === filter.subject) {
+ // warning already shown
+ continue;
+ }
+ subject = item[filter.subject] || '';
+ subject = subject.replace(regexps[filter.regexp], filter.replace);
+ if (subject === '--CRANK:SKIP--') {
skip = true;
break;
}
+ item[filter.subject] = subject;
}
if (! skip) {
out.push(item);

0 comments on commit 7d2a135

Please sign in to comment.