Skip to content

Instantly share code, notes, and snippets.

@kulikov
Forked from maccman/slug.js
Created April 20, 2012 12:48
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 kulikov/2428265 to your computer and use it in GitHub Desktop.
Save kulikov/2428265 to your computer and use it in GitHub Desktop.
Hem & Less
var hem = new (require('hem'));
var less = require('less');
var fs = require('fs');
var argv = process.argv.slice(2);
hem.compilers.less = function(path) {
var content, result;
content = fs.readFileSync(path, 'utf8');
result = '';
less.render(content, function(err, css) {
if (err) { throw err; }
result = css;
});
return result;
};
require.extensions['.less'] = function(module, filename) {
var source;
source = JSON.stringify(hem.compilers.less(filename));
return module._compile("module.exports = " + source, filename);
};
hem.exec(argv[0]);
@kulikov
Copy link
Author

kulikov commented Apr 20, 2012

This has been fixed now with the latest beta of Hem. You can monkey patch or add more compilers fairly easily.

Just create a file called slug.js, containing the following: https://gist.github.com/1324427

Make sure you use the beta version of Hem though:

{
"name": "app",
"version": "0.0.1",
"dependencies": {
"ace": "~0.0.1",
"hem": "beta",
"es5-shimify": "~0.0.1",
"json2ify": "~0.0.1",
"jqueryify": "~0.0.1",
"spine": "~1.0.3",
"less": "latest"
}
}

Take a look at the source, or ping me on IRC for more info.

@kulikov
Copy link
Author

kulikov commented Apr 20, 2012

Патч для компилятора для поддержки хогана

https://github.com/CyberWalrus/hem/blob/master/src/compilers.coffee
https://github.com/danshultz/hem/blob/master/src/compilers.coffee

  hogan = require('hogan.js')

  compilers.mustache = (path) ->
    content = hogan.compile(fs.readFileSync(path, 'utf-8'), { asString: true })
    """
    module.exports = (function() { 
      var Hogan = require('hogan.js/lib/hogan');
      return new Hogan.Template(#{content}); 
    }).call(this);
    """

  require.extensions['.mustache'] = (module, filename) ->
    module._compile(compilers.hogan(filename));

@kulikov
Copy link
Author

kulikov commented Apr 20, 2012

И вот еще пример добавления поддержки LESS

https://github.com/AbleCoder/hem-less

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment