yeoman-include
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -44,11 +44,11 @@ /* | ||
include: { | ||
"test/dest": 'test/fixtures/app/*.html' | ||
test: 'test/fixtures/app/*.html' | ||
}, | ||
"include:clean": { | ||
"app": 'test/fixtures/app/*.html' | ||
test: 'test/fixtures/app/*.html' | ||
}, | ||
"include:clean-dest": { | ||
"dest": 'test/dest/*.html' | ||
test: 'test/dest/*.html' | ||
}, | ||
@@ -73,3 +73,3 @@ | ||
// plugin's task(s), then test the result. | ||
grunt.registerTask('test', ['clean', 'include', 'copy', 'include:clean', 'include:clean-dest', 'nodeunit']); | ||
grunt.registerTask('test', ['clean', 'include:test', 'copy', 'include:clean:test', 'include:clean-dest:test', 'nodeunit']); | ||
@@ -76,0 +76,0 @@ // By default, lint and run all tests. |
{ | ||
"name": "yeoman-include", | ||
"description": "Yeoman task to include static templates", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/marmelab/yeoman-include", | ||
@@ -35,3 +35,4 @@ "author": { | ||
"grunt-contrib-copy": "~0.4.1", | ||
"grunt": "~0.4.1" | ||
"grunt": "~0.4.1", | ||
"exec-sync": "~0.1.6" | ||
}, | ||
@@ -38,0 +39,0 @@ "peerDependencies": { |
@@ -28,14 +28,20 @@ # yeoman-include | ||
include: { | ||
"destinationFolder": 'source/*.html' | ||
myTask: 'source/*.html' | ||
}, | ||
// Run others grunt task like uglify | ||
"include:clean": { | ||
"app": 'source/*.html' | ||
myTask: 'source/*.html' | ||
}, | ||
"include:clean-dest": { | ||
"dest": 'destinationFolder/*.html' | ||
myTask: 'dest/*.html' | ||
}, | ||
}) | ||
grunt.registerTask('build', [ | ||
'include:myTask', | ||
// Run task like cssmin, ugligy ... | ||
'include:clean:myTask', | ||
'include:clean-dest:myTask' | ||
]); | ||
``` | ||
@@ -49,12 +55,31 @@ | ||
grunt.initConfig({ | ||
include: { | ||
"test/dest": 'test/fixtures/app/*.html' | ||
}, | ||
"include:clean": { | ||
"app": 'test/fixtures/app/*.html' | ||
}, | ||
"include:clean-dest": { | ||
"dest": 'test/dest/*.html' | ||
}, | ||
include: { | ||
build: '<%= yeoman.app %>/*.html' | ||
tmp: '.tmp/*.html' | ||
}, | ||
"include:clean": { | ||
build: '<%= yeoman.app %>/*.html', | ||
tmp: '.tmp/*.html' | ||
}, | ||
"include:clean-dest": { | ||
build: <%= yeoman.dist %>/*.html', | ||
tmp: '.tmp/*.html' | ||
} | ||
}) | ||
grunt.registerTask('build', [ | ||
'clean:dist', | ||
'include:build', | ||
'cssmin', | ||
'concat', | ||
'uglify', | ||
'coffee', | ||
'copy:dist', | ||
'rev', | ||
'usemin', | ||
'include:clean:build', | ||
'include:clean-dest:build' | ||
]); | ||
``` | ||
@@ -67,2 +92,3 @@ | ||
## Release History | ||
v0.1 (08/14/2013) : Add simple yeoman include task | ||
- v0.1 (08/14/2013) : Add simple yeoman include task | ||
- v0.2 (09/08/2013) : Allows multiple task (eg. include:build, include:tmp) |
@@ -11,3 +11,4 @@ /* | ||
var fs = require('fs'); | ||
var fs = require('fs'); | ||
var execSync = require('exec-sync'); | ||
@@ -19,28 +20,27 @@ module.exports = function(grunt) { | ||
this.files.forEach(function (files) { | ||
var destDir = files.dest; | ||
var files = execSync('ls '+this.data).split("\n"); | ||
files.src.forEach(function(file){ | ||
var content = grunt.file.read(file); | ||
var fileData = file.split('/'); | ||
var filename = fileData.pop(); | ||
var fileDir = fileData.join('/')+'/'; | ||
for(var i = 0, nbFiles = files.length; i < nbFiles; i++){ | ||
var file = files[i]; | ||
var content = grunt.file.read(file); | ||
var fileData = file.split('/'); | ||
fileData.pop(); | ||
var fileDir = fileData.join('/')+'/'; | ||
var placeholders = content.match(regexp); | ||
if(!placeholders || !placeholders.length){ | ||
return; | ||
} | ||
var placeholders = content.match(regexp); | ||
if(!placeholders || !placeholders.length){ | ||
return; | ||
} | ||
for(var i = 0, length = placeholders.length; i < length; i++){ | ||
var placeHolder = placeholders[i]; | ||
var layoutFile = placeHolder.match(/\[include:([^\]]+)\]/)[1]; | ||
for(var j = 0, length = placeholders.length; j < length; j++){ | ||
var placeHolder = placeholders[j]; | ||
var layoutFile = placeHolder.match(/\[include:([^\]]+)\]/)[1]; | ||
var endPlaceHolder = placeHolder.split('[').join('\\['); | ||
var layout = grunt.file.read(fileDir+layoutFile); | ||
content = content.split(placeHolder).join(placeHolder+layout+endPlaceHolder); | ||
} | ||
var endPlaceHolder = placeHolder.split('[').join('\\['); | ||
var layout = grunt.file.read(fileDir+layoutFile); | ||
content = content.split(placeHolder).join(placeHolder+layout+endPlaceHolder); | ||
} | ||
grunt.file.write(file, content); | ||
}); | ||
}); | ||
grunt.file.write(file, content); | ||
} | ||
}); | ||
@@ -56,48 +56,53 @@ | ||
var files = execSync('ls '+this.data).split("\n"); | ||
// Clean app files | ||
this.files.forEach(function (files) { | ||
files.src.forEach(function(file){ | ||
var content = grunt.file.read(file); | ||
for(var i = 0, nbFiles = files.length; i < nbFiles; i++){ | ||
var file = files[i]; | ||
var content = grunt.file.read(file); | ||
var layouts = content.match(regexp); | ||
if(!layouts || !layouts.length){ | ||
return; | ||
} | ||
var layouts = content.match(regexp); | ||
if(!layouts || !layouts.length){ | ||
return; | ||
} | ||
for(var i = 0, length = layouts.length; i < length; i++){ | ||
var layoutContent = layouts[i].match(contentRegexp); | ||
for(var j = 0, length = layouts.length; j < length; j++){ | ||
var layoutContent = layouts[j].match(contentRegexp); | ||
content = content.split(layouts[i]).join(layoutContent[1]); | ||
} | ||
content = content.split(layouts[j]).join(layoutContent[1]); | ||
} | ||
grunt.file.write(file, content); | ||
}); | ||
}); | ||
grunt.file.write(file, content); | ||
} | ||
}); | ||
grunt.registerMultiTask('include:clean-dest', 'Clean final layout templating', function(){ | ||
if(this.files.length == 0){ | ||
return; | ||
} | ||
var regexp = /(<!--\s+\[include:[^\]]+\]\s+-->)(?:\r|\n|.)+?<!--\s+\\\[include:[^\]]+\]\s+-->/g; | ||
var contentRegexp = /<!--\s+\[include:[^\]]+\]\s+-->((?:\r|\n|.)+?)<!--\s+\\\[include:[^\]]+\]\s+-->/; | ||
var files = execSync('ls '+this.data).split("\n"); | ||
// Clean app files | ||
this.files.forEach(function (files) { | ||
files.src.forEach(function(file){ | ||
var content = grunt.file.read(file); | ||
for(var i = 0, nbFiles = files.length; i < nbFiles; i++){ | ||
var file = files[i]; | ||
var content = grunt.file.read(file); | ||
var layouts = content.match(regexp); | ||
if(!layouts || !layouts.length){ | ||
return; | ||
} | ||
var layouts = content.match(regexp); | ||
if(!layouts || !layouts.length){ | ||
return; | ||
} | ||
for(var i = 0, length = layouts.length; i < length; i++){ | ||
var layoutContent = layouts[i].match(contentRegexp); | ||
for(var j = 0, length = layouts.length; j < length; j++){ | ||
var layoutContent = layouts[j].match(contentRegexp); | ||
content = content.split(layouts[i]).join(layoutContent[1]); | ||
} | ||
content = content.split(layouts[j]).join(layoutContent[1]); | ||
} | ||
grunt.file.write(file, content); | ||
}); | ||
}); | ||
grunt.file.write(file, content); | ||
} | ||
}); | ||
}; |
Sorry, the diff of this file is not supported yet
36150
24
182
92
6