Created
February 10, 2013 21:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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