Permalink
Browse files

Remove the third party dependency Templato(which was rewritten in JS …

…and a bunch of changes), and refactored the adapter code so it can now manage the helpers and the compiling together.

Also updated templates and tests to adapt to the new Adapter only code.
  • Loading branch information...
1 parent 1f8c699 commit 2e8e3fb58ed4c05ac546efebdb7a75b4a0757279 @larzconwell larzconwell committed Oct 24, 2012
View
@@ -1,154 +0,0 @@
-/*
-colors.js
-
-Copyright (c) 2010 Alexis Sellier (cloudhead) , Marak Squires
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-*/
-// prototypes the string object to have additional method calls that add terminal colors
-var isHeadless = (typeof module !== 'undefined');
-['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'].forEach(function(style) {
- // __defineGetter__ at the least works in more browsers
- // http://robertnyman.com/javascript/javascript-getters-setters.html
- // Object.defineProperty only works in Chrome
- String.prototype.__defineGetter__(style, function() {
- return isHeadless ? stylize(this, style) : // for those running in node (headless environments)
- this.replace(/( )/, '$1'); // and for those running in browsers:
- // re: ^ you'd think 'return this' works (but doesn't) so replace coerces the string to be a real string
- });
-});
-// prototypes string with method "rainbow"
-// rainbow will apply a the color spectrum to a string, changing colors every letter
-String.prototype.__defineGetter__('rainbow', function() {
- if (!isHeadless) {
- return this.replace(/( )/, '$1');
- }
- var rainbowcolors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV
- var exploded = this.split("");
- var i = 0;
- exploded = exploded.map(function(letter) {
- if (letter == " ") {
- return letter;
- } else {
- return stylize(letter, rainbowcolors[i++ % rainbowcolors.length]);
- }
- });
- return exploded.join("");
-});
-
-function stylize(str, style) {
- var styles = {
- //styles
- 'bold': [1, 22],
- 'italic': [3, 23],
- 'underline': [4, 24],
- 'inverse': [7, 27],
- //grayscale
- 'white': [37, 39],
- 'grey': [90, 39],
- 'black': [90, 39],
- //colors
- 'blue': [34, 39],
- 'cyan': [36, 39],
- 'green': [32, 39],
- 'magenta': [35, 39],
- 'red': [31, 39],
- 'yellow': [33, 39]
- };
- return '\033[' + styles[style][0] + 'm' + str + '\033[' + styles[style][1] + 'm';
-};
-// don't summon zalgo
-String.prototype.__defineGetter__('zalgo', function() {
- return zalgo(this);
-});
-// please no
-
-function zalgo(text, options) {
- var soul = {
- "up": ['̍', '̎', '̄', '̅', '̿', '̑', '̆', '̐', '͒', '͗', '͑', '̇', '̈', '̊', '͂', '̓', '̈', '͊', '͋', '͌', '̃', '̂', '̌', '͐', '̀', '́', '̋', '̏', '̒', '̓', '̔', '̽', '̉', 'ͣ', 'ͤ', 'ͥ', 'ͦ', 'ͧ', 'ͨ', 'ͩ', 'ͪ', 'ͫ', 'ͬ', 'ͭ', 'ͮ', 'ͯ', '̾', '͛', '͆', '̚'],
- "down": ['̖', '̗', '̘', '̙', '̜', '̝', '̞', '̟', '̠', '̤', '̥', '̦', '̩', '̪', '̫', '̬', '̭', '̮', '̯', '̰', '̱', '̲', '̳', '̹', '̺', '̻', '̼', 'ͅ', '͇', '͈', '͉', '͍', '͎', '͓', '͔', '͕', '͖', '͙', '͚', '̣'],
- "mid": ['̕', '̛', '̀', '́', '͘', '̡', '̢', '̧', '̨', '̴', '̵', '̶', '͜', '͝', '͞', '͟', '͠', '͢', '̸', '̷', '͡', ' ҉']
- },
- all = [].concat(soul.up, soul.down, soul.mid),
- zalgo = {};
-
- function randomNumber(range) {
- r = Math.floor(Math.random() * range);
- return r;
- };
-
- function is_char(character) {
- var bool = false;
- all.filter(function(i) {
- bool = (i == character);
- });
- return bool;
- }
-
- function heComes(text, options) {
- result = '';
- options = options || {};
- options["up"] = options["up"] || true;
- options["mid"] = options["mid"] || true;
- options["down"] = options["down"] || true;
- options["size"] = options["size"] || "maxi";
- var counts;
- text = text.split('');
- for (var l in text) {
- if (is_char(l)) {
- continue;
- }
- result = result + text[l];
- counts = {
- "up": 0,
- "down": 0,
- "mid": 0
- };
- switch (options.size) {
- case 'mini':
- counts.up = randomNumber(8);
- counts.min = randomNumber(2);
- counts.down = randomNumber(8);
- break;
- case 'maxi':
- counts.up = randomNumber(16) + 3;
- counts.min = randomNumber(4) + 1;
- counts.down = randomNumber(64) + 3;
- break;
- default:
- counts.up = randomNumber(8) + 1;
- counts.mid = randomNumber(6) / 2;
- counts.down = randomNumber(8) + 1;
- break;
- }
- var arr = ["up", "mid", "down"];
- for (var d in arr) {
- var index = arr[d];
- for (var i = 0; i <= counts[index]; i++) {
- if (options[index]) {
- result = result + soul[index][randomNumber(soul[index].length)];
- }
- }
- }
- }
- return result;
- };
- return heComes(text);
-}
View
@@ -1,64 +0,0 @@
-/*global module:false*/
-module.exports = function(grunt) {
-
- // Project configuration.
- grunt.initConfig({
- pkg: '<json:package.json>',
- meta: {
- banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
- '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
- '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
- '* Copyright (c) <%= grunt.template.today("yyyy") %> Vadim Demedes;' +
- ' Licensed MIT. */'
- },
- concat: {
- dist: {
- src: ['<banner:meta.banner>', 'lib/templato.js'],
- dest: 'dist/<%= pkg.name %>.js'
- },
- ejs: {
- src: ['<banner:meta.banner>', 'vendor/ejs/ejs.js', 'lib/engines/ejs.js'],
- dest: 'dist/engines/ejs.js'
- },
- mustache: {
- src: ['<banner:meta.banner>', 'vendor/hogan/hogan.js', 'lib/engines/mustache.js'],
- dest: 'dist/engines/mustache.js'
- },
- jade: {
- src: ['<banner:meta.banner>', 'vendor/jade/jade.js', 'lib/engines/jade.js'],
- dest: 'dist/engines/jade.js'
- }
- },
- min: {
- dist: {
- src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
- dest: 'dist/<%= pkg.name %>.min.js'
- },
- ejs: {
- src: ['<banner:meta.banner>', '<config:concat.ejs.dest>'],
- dest: 'dist/engines/ejs.min.js'
- },
- mustache: {
- src: ['<banner:meta.banner>', '<config:concat.mustache.dest>'],
- dest: 'dist/engines/mustache.min.js'
- },
- jade: {
- src: ['<banner:meta.banner>', '<config:concat.jade.dest>'],
- dest: 'dist/engines/jade.min.js'
- }
- },
- watch: {
- files: ['vendor/ejs/ejs.js', 'lib/engines/ejs.js',
- 'vendor/hogan/hogan.js', 'lib/engines/mustache.js',
- 'lib/engines/eco.js',
- 'vendor/jade/jade.js', 'lib/engines/jade.js',
- 'lib/templato.js'],
- tasks: 'concat min'
- },
- uglify: {}
- });
-
- // Default task.
- grunt.registerTask('default', 'concat min');
-
-};
View
@@ -1 +0,0 @@
-module.exports = require('./lib/templato');
@@ -1,26 +0,0 @@
-var path = require('path')
- , TemplatoEJS;
-
-TemplatoEJS = (function() {
-
- function TemplatoEJS() {
- try {
- this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'ejs'));
- } catch(err) {
- throw "To use EJS you will need to install it: [sudo] npm install [-g] ejs";
- }
- };
-
- TemplatoEJS.prototype.compile = function(template, options) {
- return this.engine.compile(template, options);
- };
-
- TemplatoEJS.prototype.render = function(data, fn) {
- return fn(data);
- };
-
- return TemplatoEJS;
-
-})();
-
-module.exports = TemplatoEJS;
@@ -1,21 +0,0 @@
-var TemplatoGeddyEJS = (function() {
-
- function TemplatoGeddyEJS() {
- // Hardcoded for specifically Geddy's EJS implementation
- // Location: `lib/template/engines/ejs.js`
- this.engine = this.engine || require('../../../../lib/template/engines/ejs');
- };
-
- TemplatoGeddyEJS.prototype.compile = function(template, options) {
- return this.engine.compile(template, options);
- };
-
- TemplatoGeddyEJS.prototype.render = function(data, fn) {
- return fn(data);
- };
-
- return TemplatoGeddyEJS;
-
-})();
-
-module.exports = TemplatoGeddyEJS;
@@ -1,38 +0,0 @@
-var path = require('path')
- , TemplatoHandlebars;
-
-TemplatoHandlebars = (function() {
-
- function TemplatoHandlebars() {
- try {
- this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'handlebars'));
- } catch(err) {
- throw "To use Handlebars you will need to install it: [sudo] npm install [-g] handlebars";
- }
- };
-
- TemplatoHandlebars.prototype.compile = function(template, options) {
- return this.engine.compile(template, options);
- };
-
- TemplatoHandlebars.prototype.render = function(data, fn) {
- return fn(data);
- };
-
- // Iterate over a object of helpers and assign them by name
- TemplatoHandlebars.prototype.registerHelper = function(data) {
- var helper;
-
- for(helper in data) {
- // Only functions are allowed to be assigned
- if(typeof data[helper] === 'function') {
- this.engine.registerHelper(helper, data[helper]);
- }
- }
- };
-
- return TemplatoHandlebars;
-
-})();
-
-module.exports = TemplatoHandlebars;
@@ -1,26 +0,0 @@
-var path = require('path')
- , TemplatoJade;
-
-TemplatoJade = (function() {
-
- function TemplatoJade() {
- try {
- this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'jade'));
- } catch(err) {
- throw "To use Jade you will need to install it: [sudo] npm install [-g] jade";
- }
- };
-
- TemplatoJade.prototype.compile = function(template, options) {
- return this.engine.compile(template, options);
- };
-
- TemplatoJade.prototype.render = function(data, fn) {
- return fn(data);
- };
-
- return TemplatoJade;
-
-})();
-
-module.exports = TemplatoJade;
@@ -1,43 +0,0 @@
-require('../../color');
-var path = require('path')
- , TemplatoMustache;
-
-TemplatoMustache = (function() {
-
- function TemplatoMustache() {
- try {
- this.engine = this.engine || require(path.join(process.cwd(), 'node_modules', 'mustache'));
- } catch(err) {
- throw [
- "To use Handlebars you will need to install it: [sudo] npm install [-g] handlebars"
- , ""
- , "Mustache, Handlebars same thing, so we're installing Handlebars. http://is.gd/kYTJyS"
- ].join('\n');
- }
- };
-
- TemplatoMustache.prototype.compile = function(template, options) {
- return this.engine.compile(template, options);
- };
-
- TemplatoMustache.prototype.render = function(data, fn) {
- return fn(data);
- };
-
- // Iterate over a object of helpers and assign them by name
- TemplatoMustache.prototype.registerHelper = function(data) {
- var helper;
-
- for(helper in data) {
- // Only functions are allowed to be assigned
- if(typeof data[helper] === 'function') {
- this.engine.registerHelper(helper, data[helper]);
- }
- }
- };
-
- return TemplatoMustache;
-
-})();
-
-module.exports = TemplatoMustache;
Oops, something went wrong.

2 comments on commit 2e8e3fb

Contributor
mde commented on 2e8e3fb Oct 25, 2012

Nice work on this!

Contributor

Thanks man it's so much cleaner now, I love it.

Please sign in to comment.