Skip to content

Commit

Permalink
Merge pull request #1 from jpgarcia/master
Browse files Browse the repository at this point in the history
Fixed missing file variable issue + added support for ejs templates
  • Loading branch information
johnny.halife committed Jan 3, 2013
2 parents 81f7729 + 3756ee8 commit 21171cf
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tasks/grunt-cdn.js
Expand Up @@ -14,10 +14,11 @@ module.exports = function (grunt) {
var supportedTypes = {
html: 'html',
css: 'css',
soy: 'html'
soy: 'html',
ejs: 'html'
};

var reghtml = new RegExp(/(src|href)=['"]([^'"]+)['"]/ig);
var reghtml = new RegExp(/<(?:img|link|source|script).*\b(?:href|src)\b.*['"]([\/]\w[^'"]+)['"].*\/?>/ig);

var regcss = new RegExp(/url\(([^)]+)\)/ig);

Expand All @@ -38,17 +39,14 @@ module.exports = function (grunt) {
content = grunt.helper('cdn:' + supportedTypes[type], content, filename, relativeTo);

// write the contents to destination
var filePath = dest ? path.join(dest, path.basename(filename)) : file;
var filePath = dest ? path.join(dest, path.basename(filename)) : filename;
grunt.file.write(filePath, content);
});
});

grunt.registerHelper('cdn:html', function (content, filename, relativeTo) {
return content.replace(reghtml, function (attribute, type, resource) {
return grunt.template.process("<%= type %>=\"<%= url %>\"", {
type: type,
url: (cdnUrl(resource, filename, relativeTo) || resource)
});
return content.replace(reghtml, function (match, resource) {
return match.replace(resource, cdnUrl(resource, filename, relativeTo));
});
});

Expand Down Expand Up @@ -80,7 +78,7 @@ module.exports = function (grunt) {
return;
}

var src = path.join(relativeTo, resourceUrl.pathname);
var src = path.join(relativeTo, resourceUrl.pathname).replace(/:\/(\w)/, '://$1');

return grunt.template.process("<%= url %><%= search %>", {
url: src,
Expand Down

0 comments on commit 21171cf

Please sign in to comment.