halvalla
Version:
Generate React elements with CoffeeScript functions
178 lines (160 loc) • 6.13 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var BagMan, doctypes, elements, escape, mergeElements, nickName, normalizeArray, quote,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
slice = [].slice,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
doctypes = {
'default': '',
'html': '',
'5': '',
'xml': '',
'transitional': '',
'strict': '',
'frameset': '',
'1.1': '',
'basic': '',
'mobile': '',
'ce': ''
};
elements = {
regular: 'a abbr address article aside audio b bdi bdo blockquote body button canvas caption cite code colgroup datalist dd del details dfn div dl dt em fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup html i iframe ins kbd label legend li map mark menu meter nav noscript object ol optgroup option output p pre progress q rp rt ruby s samp section select small span strong sub summary sup table tbody td textarea tfoot th thead time title tr u ul video',
raw: 'style',
script: 'script',
coffeescript: 'coffeescript',
comment: 'comment',
"void": 'area base br col command embed hr img input keygen link meta param source track wbr',
obsolete: 'applet acronym bgsound dir frameset noframes isindex listing nextid noembed plaintext rb strike xmp big blink center font marquee multicol nobr spacer tt',
obsolete_void: 'basefont frame'
};
nickName = function(thing) {
var name, ref, ref1, ref2;
if (!thing) {
return "All Done! We close bag now\n";
}
if (thing._Halvalla) {
return thing._Halvalla.birthName;
}
if ((ref = thing.props) != null ? ref._Halvalla : void 0) {
return (ref1 = thing.props) != null ? ref1._Halvalla.birthName : void 0;
}
if (thing.name && thing.name !== "") {
return "some function maybe " + thing.name;
}
if (thing['$$typeof']) {
if ('string' === typeof thing.tag) {
name = thing.type;
} else {
name = ((ref2 = thing.type) != null ? ref2.name : void 0) || "no Can!";
}
return "React Element " + name;
}
return "some anonymous bozo " + thing.toString();
};
normalizeArray = function(b) {
var c, d, v;
c = Array.isArray(b) ? b : [b];
if (c.normalized != null) {
return c;
}
d = (function() {
var i, len, results;
results = [];
for (i = 0, len = c.length; i < len; i++) {
v = c[i];
if (v !== null && v !== '') {
results.push(v);
}
}
return results;
})();
Object.defineProperty(d, 'normalized', {
value: true,
enumerable: false
});
return d;
};
BagMan = BagMan = (function() {
function BagMan() {
this.harvest = bind(this.harvest, this);
this.reinspect = bind(this.reinspect, this);
this.inspect = bind(this.inspect, this);
this.shipOut = bind(this.shipOut, this);
this.lastShipment = null;
this.shipment = null;
return;
}
BagMan.prototype.context = function() {
var a, inputStuff;
inputStuff = 1 <= arguments.length ? slice.call(arguments, 0) : [];
this.lastShipment = null;
a = normalizeArray.apply(null, inputStuff);
this.toDoList = a.reverse();
this.shipment = [];
};
BagMan.prototype.shipOut = function(thing) {
var kind;
if (!this.shipment) {
return thing;
}
if (thing === this.lastShipment) {
return thing;
}
this.lastShipment = thing;
kind = thing.constructor.name;
if (kind === 'String' || kind === 'Number' || kind === 'Boolean') {
thing = thing.toString();
}
this.shipment.push(thing);
return thing;
};
BagMan.prototype.inspect = function() {
return this.toDoList.pop();
};
BagMan.prototype.reinspect = function(stuff) {
var eachItem, i, newStuff;
newStuff = normalizeArray(stuff);
for (i = newStuff.length - 1; i >= 0; i += -1) {
eachItem = newStuff[i];
this.toDoList.push(eachItem);
}
return stuff;
};
BagMan.prototype.harvest = function() {
return this.shipment;
};
return BagMan;
})();
mergeElements = function() {
var a, args, element, i, j, len, len1, ref, result;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
result = [];
for (i = 0, len = args.length; i < len; i++) {
a = args[i];
ref = (elements[a] || a).split(' ');
for (j = 0, len1 = ref.length; j < len1; j++) {
element = ref[j];
if (indexOf.call(result, element) < 0) {
result.push(element);
}
}
}
return result;
};
escape = function(text) {
return text.toString().replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
};
quote = function(value) {
return "\"" + value + "\"";
};
module.exports = {
doctypes: doctypes,
elements: elements,
mergeElements: mergeElements,
normalizeArray: normalizeArray,
escape: escape,
quote: quote,
allTags: {},
BagMan: BagMan
};
}).call(this);