Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handles no doctype properly (Fixes #59)

  • Loading branch information...
commit 331c73f8332a472697fa312a107bf6fa124a54e8 1 parent 30a1074
@existentialism existentialism authored
View
9 lib/replace.js
@@ -50,9 +50,14 @@ exports.init = function(grunt) {
var document = window.document;
// get the doctype back
var getDoctype = function (document) {
+ var html = '';
var node = document.doctype;
- var html = "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>';
- return html + '\n';
+
+ if (node) {
+ html = "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';
+ }
+
+ return html;
};
// iterate over content nodes to find the correct script tags
View
1  test/fixtures/replaceSingleAlmondNoDocType.html
@@ -0,0 +1 @@
+<html><head></head><body><script src="js/require.js" data-main="js/main"></script></body></html>
View
19 test/require_test.js
@@ -244,6 +244,25 @@ exports['require'] = {
test.done();
},
+ 'requirejs script tag can be replaced with almondified script tag with no doctype declared (#59)': function(test) {
+ 'use strict';
+ test.expect(1);
+ var config = {
+ replaceRequireScript: [{
+ files: ['tmp/replaceSingleAlmondNoDocType.html'],
+ module: 'main'
+ }],
+ modules: [{name: 'main'}],
+ almond: true
+ };
+
+ grunt.file.copy('test/fixtures/replaceSingleAlmondNoDocType.html', 'tmp/replaceSingleAlmondNoDocType.html');
+ replaceAlmondInHtmlFiles(config);
+ var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
+ test.ok(replacedFileContents.search('<script src="js/main.js"></script>') > -1, 'should replace script tag ´src´ contents');
+ test.done();
+ },
+
'requirejs script tag can be replaced with almondified script tag & leaves attributes': function(test) {
'use strict';
test.expect(1);
Please sign in to comment.
Something went wrong with that request. Please try again.