Add Support for SLM
Roots supports Jade, by default. We can make it support Slm as well, at least for the most part.
Install Slm for Accord
Create and Edit the accord Adapter for Slm
Copy /usr/local/lib/node_modules/roots/node_modules/accord/lib/adapters/jade to /usr/local/lib/node_modules/roots/node_modules/accord/lib/adapters/slm.
In /usr/local/lib/node_modules/roots/node_modules/accord/lib/adapters/slm/, rename 1.x.js to 0.5.x.js. The number before .js
should satisfy (via a call to semver.satisfies
the slm version number specified in slm’s package.json.
In the file you’ve just renamed:
- replace all instances of “Jade” with “Slm” and all instances of “jade” with “slm”.
- remove the string ‘yade’ from the array on line 32.
- insert
null
as second argument ofrender
call on line 37.
Resulting source should look something like this:
// Generated by CoffeeScript 1.10.0
(function() {
var Adapter, Slm, UglifyJS, W, fs, path,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Adapter = require('../../adapter_base');
path = require('path');
fs = require('fs');
W = require('when');
UglifyJS = require('uglify-js');
Slm = (function(superClass) {
var compile;
extend(Slm, superClass);
function Slm() {
return Slm.__super__.constructor.apply(this, arguments);
}
Slm.prototype.name = 'slm';
Slm.prototype.extensions = ['slm'];
Slm.prototype.output = 'html';
Slm.prototype.supportedEngines = ['slm'];
Slm.prototype._render = function(str, options) {
return compile((function(_this) {
return function() {
return _this.engine.render(str, null, options);
};
})(this));
};
Slm.prototype._compile = function(str, options) {
return compile((function(_this) {
return function() {
return _this.engine.compile(str, options);
};
})(this));
};
Slm.prototype._compileClient = function(str, options) {
return compile((function(_this) {
return function() {
return _this.engine.compileClient(str, options);
};
})(this));
};
Slm.prototype.clientHelpers = function() {
var runtime, runtime_path;
runtime_path = path.join(this.engine.__accord_path, 'runtime.js');
runtime = fs.readFileSync(runtime_path, 'utf8');
return UglifyJS.minify(runtime, {
fromString: true
}).code;
};
compile = function(fn) {
var err, error, res;
try {
res = fn();
} catch (error) {
err = error;
return W.reject(err);
}
return W.resolve({
result: res
});
};
return Slm;
})(Adapter);
module.exports = Slm;
}).call(this);