Sha256: 80864fa3b04adbe09b5e424ad436a3189361e93d9d02717ab748477e86c477a7

Contents?: true

Size: 778 Bytes

Versions: 4

Compression:

Stored size: 778 Bytes

Contents

module.exports.register = function (handlebars) {
	handlebars.registerHelper('code', function(options) {

		var className = options.hash.lang || "";

		// Input html
		var input = options.fn(this);

		// Escale html to string
		input = handlebars.Utils.escapeExpression(input);

		// Break by lines
		var lines = input.split("\n");

		// Get number of tabs before first line
		var numTabs = getNumFrontTabs(lines[0]);

		// Remove tabs before 
		lines = lines.map(function(line) {
			return line.substring(numTabs);
		});

		// Rejoin the lines
		return "<pre><code class='" + className + "'>" + lines.join("\n") + "</code></pre>";
	});
};


function getNumFrontTabs(line) {
	var count = 0;
	var index = 0;
	while (line.charAt(index++) === "\t") {
		count++;
	}
	return count;
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_modular_admin-0.2.4 app/assets/javascripts/rails_modular_admin/_common/_helpers/code-helper.js
rails_modular_admin-0.2.3 app/assets/javascripts/rails_modular_admin/_common/_helpers/code-helper.js
rails_modular_admin-0.2.2 app/assets/javascripts/rails_modular_admin/_common/_helpers/code-helper.js
rails_modular_admin-0.2.0 app/assets/javascripts/rails_modular_admin/_common/_helpers/code-helper.js