Skip to content

Commit

Permalink
Version 0.10.0 released.
Browse files Browse the repository at this point in the history
  • Loading branch information
outaTiME committed Aug 20, 2015
1 parent 0d3bf45 commit 5657061
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 43 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
npm-debug.log
tmp
.DS_Store
15 changes: 4 additions & 11 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"node": true,
"sub": true,
"undef": true,
"boss": true,
"eqnull": true,
"node": true,
"predef": [
"describe",
"it",
"before",
"beforeEach",
"after",
"afterEach"
]
"unused": true
}
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
sudo: false
language: node_js
node_js:
- "0.10"
before_install:
- 'iojs'
- '0.12'
- '0.10'
before_script:
- npm install -g grunt-cli
231 changes: 225 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# grunt-replace [![Build Status](https://secure.travis-ci.org/outaTiME/grunt-replace.png?branch=master)](http://travis-ci.org/outaTiME/grunt-replace)
# grunt-replace [![Build Status](https://travis-ci.org/outaTiME/grunt-replace.svg?branch=master)](https://travis-ci.org/outaTiME/grunt-replace)

> Replace text patterns with [applause](https://github.com/outaTiME/applause).


## Install

From NPM:
Expand Down Expand Up @@ -42,10 +40,230 @@ module.exports = function (grunt) {

### Options

function () {
var name = 'Applause Options';
return sections[name] || '_(Coming soon)_'; // empty


#### patterns
Type: `Array`

Define patterns that will be used to replace the contents of source files.

#### patterns.match
Type: `String|RegExp`

Indicates the matching expression.

If matching type is `String` we use a simple variable lookup mechanism `@@string` (in any other case we use the default regexp replace logic):

```javascript
{
patterns: [
{
match: 'foo',
replacement: 'bar' // replaces "@@foo" to "bar"
}
]
}
```

#### patterns.replacement or patterns.replace
Type: `String|Function|Object`

Indicates the replacement for match, for more information about replacement check out the [String.replace].

You can specify a function as replacement. In this case, the function will be invoked after the match has been performed. The function's result (return value) will be used as the replacement string.

```javascript
{
patterns: [
{
match: /foo/g,
replacement: function () {
return 'bar'; // replaces "foo" to "bar"
}
}
]
}
```

Also supports object as replacement (we create string representation of object using [JSON.stringify]):

```javascript
{
patterns: [
{
match: /foo/g,
replacement: [1, 2, 3] // replaces "foo" with string representation of "array" object
}
]
}
```

[String.replace]: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
[JSON.stringify]: http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

#### patterns.json
Type: `Object`

If an attribute `json` found in pattern definition we flatten the object using `delimiter` concatenation and each key–value pair will be used for the replacement (simple variable lookup mechanism and no regexp support).

```javascript
{
patterns: [
{
json: {
"key": "value" // replaces "@@key" to "value"
}
}
]
}
```

Also supports nested objects:

```javascript
{
patterns: [
{
json: {
"key": "value", // replaces "@@key" to "value"
"inner": { // replaces "@@inner" with string representation of "inner" object
"key": "value" // replaces "@@inner.key" to "value"
}
}
}
]
}
```

For deferred invocations is possible to define functions:

```javascript
{
patterns: [
{
json: function (done) {
done({
key: 'value'
});
}
}
]
}
```

#### patterns.yaml
Type: `String`

If an attribute `yaml` found in pattern definition will be converted and then processed like [json attribute](#patternsjson).

```javascript
{
patterns: [
{
yaml: 'key: value' // replaces "@@key" to "value"
}
]
}
```

For deferred invocations is possible to define functions:

```javascript
{
patterns: [
{
yaml: function (done) {
done('key: value');
}
}
]
}
```

#### patterns.cson
Type: `String`

If an attribute `cson` found in pattern definition will be converted and then processed like [json attribute](#patternsjson).

```javascript
{
patterns: [
{
cson: 'key: \'value\''
}
]
}
```

For deferred invocations is possible to define functions:

```javascript
{
patterns: [
{
cson: function (done) {
done('key: \'value\'');
}
}
]
}
```

#### variables
Type: `Object`

This is the old way to define patterns using plain object (simple variable lookup mechanism and no regexp support). You can still use this but for more control you should use the new `patterns` way.

```javascript
{
variables: {
'key': 'value' // replaces "@@key" to "value"
}
}
```

#### prefix
Type: `String`
Default: `@@`

The prefix added for matching (prevent bad replacements / easy way).

> This only applies for simple variable lookup mechanism.
#### usePrefix
Type: `Boolean`
Default: `true`

If set to `false`, we match the pattern without `prefix` concatenation (useful when you want to lookup an simple string).

> This only applies for simple variable lookup mechanism.
#### preservePrefix
Type: `Boolean`
Default: `false`

If set to `true`, we preserve the `prefix` in target.

> This only applies for simple variable lookup mechanism and `patterns.replacement` is an string.
#### delimiter
Type: `String`
Default: `.`

The delimiter used to flatten when using object as replacement.

#### preserveOrder
Type: `Boolean`
Default: `false`

If set to `true`, we preserve the patterns definition order, otherwise these will be sorted (in ascending order) to prevent replacement issues like `head` / `header` (typo regexps will be resolved at last).

#### detail
Type: `Boolean`
Default: `false`

If set to `true`, return a object response with the `content` and `detail` of replace operation.


#### excludeBuiltins
Type: `Boolean`
Expand Down Expand Up @@ -407,6 +625,7 @@ replace: {

## Release History

* 2015-08-06   v0.10.0   Last [applause](https://github.com/outaTiME/applause) integration and package.json update.
* 2015-08-06   v0.9.3   New pedantic option (thanks [@donkeybanana](https://github.com/donkeybanana)). Fix issue with special characters attributes ($$, $&, $`, $', $n or $nn) on JSON, YAML and CSON.
* 2015-05-07   v0.9.2   Fix regression issue with empty string in replacement.
* 2015-05-01   v0.9.1   Better output.
Expand Down
5 changes: 2 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# grunt-replace [![Build Status](https://secure.travis-ci.org/outaTiME/grunt-replace.png?branch=master)](http://travis-ci.org/outaTiME/grunt-replace)
# grunt-replace [![Build Status](https://travis-ci.org/outaTiME/grunt-replace.svg?branch=master)](https://travis-ci.org/outaTiME/grunt-replace)

> Replace text patterns with [applause](https://github.com/outaTiME/applause).


## Install

From NPM:
Expand Down Expand Up @@ -404,6 +402,7 @@ replace: {

## Release History

* 2015-08-06   v0.10.0   Last [applause](https://github.com/outaTiME/applause) integration and package.json update.
* 2015-08-06   v0.9.3   New pedantic option (thanks [@donkeybanana](https://github.com/donkeybanana)). Fix issue with special characters attributes ($$, $&, $`, $', $n or $nn) on JSON, YAML and CSON.
* 2015-05-07   v0.9.2   Fix regression issue with empty string in replacement.
* 2015-05-01   v0.9.1   Better output.
Expand Down
23 changes: 5 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
{
"name": "grunt-replace",
"description": "Replace text patterns with applause.",
"version": "0.9.3",
"homepage": "http://github.com/outaTiME/grunt-replace",
"version": "0.10.0",
"author": {
"name": "outaTiME",
"url": "http://outa.im/"
},
"repository": {
"type": "git",
"url": "http://github.com/outaTiME/grunt-replace.git"
},
"bugs": {
"url": "http://github.com/outaTiME/grunt-replace/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/outaTiME/grunt-replace/blob/master/LICENSE-MIT"
}
],
"repository": "outaTiME/grunt-replace",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
},
Expand All @@ -30,7 +18,7 @@
"dependencies": {
"chalk": "^1.0.0",
"lodash": "^3.1.0",
"applause": "0.4.3"
"applause": "1.0.3"
},
"devDependencies": {
"grunt": "^0.4.0",
Expand Down Expand Up @@ -59,7 +47,6 @@
"flatten"
],
"files": [
"tasks",
"LICENSE-MIT"
"tasks"
]
}
7 changes: 4 additions & 3 deletions scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ while ((match = pattern.exec(readme)) !== null) {

var Applause = require('applause');
var options = {
variables: {
'options': function () {
patterns: [{
match: 'options',
replacement: function () {
var name = 'Applause Options';
return sections[name] || '_(Coming soon)_'; // empty
}
}
}]
};
var applause = Applause.create(options);
var contents = fs.readFileSync('docs/README.md', 'utf8');
Expand Down

0 comments on commit 5657061

Please sign in to comment.