Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #42, add xpcshell support

  • Loading branch information...
commit 0bb2eb056f90936977d38346b64874d48a91c6d8 1 parent 30d880c
@jrburke jrburke authored
Showing with 38 additions and 7 deletions.
  1. +38 −7 text.js
View
45 text.js
@@ -1,17 +1,17 @@
/**
- * @license RequireJS text 2.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
+ * @license RequireJS text 2.0.5+ Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/requirejs/text for details
*/
/*jslint regexp: true */
-/*global require: false, XMLHttpRequest: false, ActiveXObject: false,
- define: false, window: false, process: false, Packages: false,
- java: false, location: false */
+/*global require, XMLHttpRequest, ActiveXObject,
+ define, window, process, Packages,
+ java, location, Components, FileUtils */
define(['module'], function (module) {
'use strict';
- var text, fs,
+ var text, fs, Cc, Ci,
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
@@ -23,7 +23,7 @@ define(['module'], function (module) {
masterConfig = (module.config && module.config()) || {};
text = {
- version: '2.0.5',
+ version: '2.0.5+',
strip: function (content) {
//Strips <?xml ...?> declarations so that external SVG and XML
@@ -326,7 +326,38 @@ define(['module'], function (module) {
}
callback(content);
};
- }
+ } else if (masterConfig.env === 'xpconnect' || (!masterConfig.env &&
+ typeof Components !== 'undefined' && Components.classes &&
+ Components.interfaces)) {
+ //Avert your gaze!
+ Cc = Components.classes,
+ Ci = Components.interfaces;
+ Components.utils['import']('resource://gre/modules/FileUtils.jsm');
+
+ text.get = function (url, callback) {
+ var inStream, convertStream,
+ readData = {},
+ fileObj = new FileUtils.File(url);
+ //XPCOM, you so crazy
+ try {
+ inStream = Cc['@mozilla.org/network/file-input-stream;1']
+ .createInstance(Ci.nsIFileInputStream);
+ inStream.init(fileObj, 1, 0, false);
+
+ convertStream = Cc['@mozilla.org/intl/converter-input-stream;1']
+ .createInstance(Ci.nsIConverterInputStream);
+ convertStream.init(inStream, "utf-8", inStream.available(),
+ Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
+
+ convertStream.readString(inStream.available(), readData);
+ convertStream.close();
+ inStream.close();
+ callback(readData.value);
+ } catch (e) {
+ throw new Error((fileObj && fileObj.path || '') + ': ' + e);
+ }
+ };
+ }
return text;
});
Please sign in to comment.
Something went wrong with that request. Please try again.