Skip to content

Instantly share code, notes, and snippets.

@acthp
Created February 10, 2013 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acthp/4751078 to your computer and use it in GitHub Desktop.
Save acthp/4751078 to your computer and use it in GitHub Desktop.
Wrap requirejs text plugin for compiling haml. Works around dependency loading problems in r.js by detecting node and using the node loader. However the resulting javascript blob appears to deadlock. The callback for the request() call never executes.
// haml loader for requirejs
(function() {
function register(text, haml) {
var plugin = Object.create(text); // inherit methods of the text loader
function wrapload(fn) {
return function(value) {
fn(haml.compileHaml({source: value}));
}
}
function load(name, req, onload, config) {
return text.load(name, req, wrapload(onload), config);
}
plugin.load = load;
return plugin;
};
if (typeof process !== 'undefined') {
haml = require.nodeRequire(process.cwd() + '/node_modules/haml');
define(['text'], function(text) {
return register(text, haml);
});
} else {
define(['text', 'lib/haml'], register);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment