Skip to content

Commit

Permalink
Added support for spaces after prefix and before suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Jun 29, 2015
1 parent 4ccae12 commit 4201514
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function(options) {
context = {};
}

var includeRegExp = new RegExp(prefix + 'include\\s*\\([^)"\']*["\']([^"\']*)["\'](,\\s*({[\\s\\S]*?})){0,1}\\s*\\)+' + suffix);
var includeRegExp = new RegExp(prefix + '[ ]*include\\s*\\([^)"\']*["\']([^"\']*)["\'](,\\s*({[\\s\\S]*?})){0,1}\\s*\\)+[ ]*' + suffix);

function fileInclude(file, enc, cb) {
if (file.isNull()) {
Expand Down Expand Up @@ -55,13 +55,13 @@ module.exports = function(options) {
*/
function stripCommentedIncludes(content) {
// remove single line html comments that use the format: <!-- @@include() -->
var regex = new RegExp('<\!--(.*)' + prefix + 'include([\\s\\S]*?)' + suffix + '-->', 'g');
var regex = new RegExp('<\!--(.*)' + prefix + '[ ]*include([\\s\\S]*?)[ ]*' + suffix + '-->', 'g');
return content.replace(regex, '');
}

function parseConditionalIncludes(content, data) {
// parse @@if (something) { include('...') }
var regexp = new RegExp(prefix + 'if.*\\{[^{}]*\\}\\s*' + suffix),
var regexp = new RegExp(prefix + '[ ]*if.*\\{[^{}]*\\}\\s*' + suffix),
matches = regexp.exec(content),
included = false;

Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = function(options) {
var key;
for (; ~i; i -= 1) {
key = keys[i];
text = text.replace(new RegExp(prefix + key + suffix, 'g'), variables[key]);
text = text.replace(new RegExp(prefix + '[ ]*' + key + '[ ]*' + suffix, 'g'), variables[key]);
}

var filebase = basepath === '@file' ? path.dirname(file.path) : basepath === '@root' ? process.cwd() : basepath;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-file-include",
"version": "0.11.0",
"version": "0.11.1",
"description": "a gulp plugin for file include",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures-conditional/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"title": "haoxin"
})

@@if (name === 'c' && context.title === 'haoxin') {
@@ if (name === 'c' && context.title === 'haoxin') {
@@include('c.html')
}

@@if (name === 'c' && context.title !== 'haoxin') {
@@ if (name === 'c' && context.title !== 'haoxin') {
@@include('c.html')
}
2 changes: 1 addition & 1 deletion test/fixtures/index-markdown.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<body>
@@include(markdown('view.md'))
@@ include(markdown('view.md'))
@@include('./var.html', {
"name": "haoxin",
"age": 12345
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/var.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<label>@@name</label>
<label>@@age</label>
<label>@@ age</label>

2 comments on commit 4201514

@haoxins
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TrySound Is this really required?

@TrySound
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderhaoxin

//=include
//= include

I think so.

Please sign in to comment.