Skip to content
This repository
Browse code

Merge pull request #64 from existentialism/doctype-fix

Handles no doctype properly
  • Loading branch information...
commit fc26d1180481b53dfb5d22cd3178c3659e86de38 2 parents 30a1074 + 331c73f
Sebastian Golasch authored March 29, 2013
9  lib/replace.js
@@ -50,9 +50,14 @@ exports.init = function(grunt) {
50 50
           var document = window.document;
51 51
           // get the doctype back
52 52
           var getDoctype = function (document) {
  53
+            var html = '';
53 54
             var node = document.doctype;
54  
-            var html = "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>';
55  
-            return html + '\n';
  55
+
  56
+            if (node) {
  57
+                html = "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';
  58
+            }
  59
+
  60
+            return html;
56 61
           };
57 62
 
58 63
           // iterate over content nodes to find the correct script tags
1  test/fixtures/replaceSingleAlmondNoDocType.html
... ...
@@ -0,0 +1 @@
  1
+<html><head></head><body><script src="js/require.js" data-main="js/main"></script></body></html>
19  test/require_test.js
@@ -244,6 +244,25 @@ exports['require'] = {
244 244
     test.done();
245 245
   },
246 246
 
  247
+  'requirejs script tag can be replaced with almondified script tag with no doctype declared (#59)': function(test) {
  248
+    'use strict';
  249
+    test.expect(1);
  250
+    var config = {
  251
+        replaceRequireScript: [{
  252
+            files: ['tmp/replaceSingleAlmondNoDocType.html'],
  253
+        module: 'main'
  254
+        }],
  255
+        modules: [{name: 'main'}],
  256
+        almond: true
  257
+    };
  258
+
  259
+    grunt.file.copy('test/fixtures/replaceSingleAlmondNoDocType.html', 'tmp/replaceSingleAlmondNoDocType.html');
  260
+    replaceAlmondInHtmlFiles(config);
  261
+    var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
  262
+    test.ok(replacedFileContents.search('<script src="js/main.js"></script>') > -1, 'should replace script tag ´src´ contents');
  263
+    test.done();
  264
+  },
  265
+
247 266
   'requirejs script tag can be replaced with almondified script tag & leaves attributes': function(test) {
248 267
     'use strict';
249 268
     test.expect(1);

0 notes on commit fc26d11

Please sign in to comment.
Something went wrong with that request. Please try again.