Comparing version 0.1.0 to 0.1.1
323
index.js
// Generated by CoffeeScript 1.12.4 | ||
(function() { | ||
var Button, Link, debounceZero, defaultPrevented, defineTag, h, helper, i, isValidSnabbdomChild, len, looksLikeSelector, sdAttrs, sdClass, sdEvents, sdProps, sdStyle, snabbdom, t, tagMod, tagNames, tags, | ||
hasProp = {}.hasOwnProperty, | ||
slice = [].slice; | ||
var Button, Link, debounceZero, defaultPrevented, defineTag, h, helper, i, isValidSnabbdomChild, len, looksLikeSelector, sdAttrs, sdClass, sdEvents, sdProps, sdStyle, snabbdom, t, tagMod, tagNames, tags, | ||
hasProp = {}.hasOwnProperty, | ||
slice = [].slice; | ||
snabbdom = require("snabbdom"); | ||
snabbdom = require("snabbdom"); | ||
sdClass = require("snabbdom/modules/class"); | ||
sdClass = require("snabbdom/modules/class"); | ||
sdProps = require("snabbdom/modules/props"); | ||
sdProps = require("snabbdom/modules/props"); | ||
sdAttrs = require("snabbdom/modules/attributes"); | ||
sdAttrs = require("snabbdom/modules/attributes"); | ||
sdStyle = require("snabbdom/modules/style"); | ||
sdStyle = require("snabbdom/modules/style"); | ||
sdEvents = require("snabbdom/modules/eventlisteners"); | ||
sdEvents = require("snabbdom/modules/eventlisteners"); | ||
h = require('snabbdom/h'); | ||
h = require('snabbdom/h'); | ||
isValidSnabbdomChild = function(x) { | ||
return (typeof x === "string") || (typeof x === "object" && x.hasOwnProperty("sel") && x.hasOwnProperty("elm")); | ||
}; | ||
isValidSnabbdomChild = function(x) { | ||
return (typeof x === "string") || (typeof x === "object" && x.hasOwnProperty("sel") && x.hasOwnProperty("elm")); | ||
}; | ||
looksLikeSelector = function(x) { | ||
return typeof x === "string" && (x[0] === "." || x[0] === "#"); | ||
looksLikeSelector = function(x) { | ||
return typeof x === "string" && (x[0] === "." || x[0] === "#"); | ||
}; | ||
helper = function(selector, data, children) { | ||
var k, newData, v; | ||
newData = { | ||
"class": {}, | ||
on: {}, | ||
attrs: {}, | ||
props: {} | ||
}; | ||
for (k in data) { | ||
if (!hasProp.call(data, k)) continue; | ||
v = data[k]; | ||
switch (k) { | ||
case "selector": | ||
selector += v; | ||
break; | ||
case "class": | ||
case "key": | ||
case "style": | ||
case "on": | ||
case "attrs": | ||
case "props": | ||
newData[k] = v; | ||
break; | ||
default: | ||
switch (k[0]) { | ||
case "$": | ||
newData.on[k.slice(1)] = v; | ||
break; | ||
case "%": | ||
newData.attrs[k.slice(1)] = v; | ||
break; | ||
case ".": | ||
newData["class"][k.slice(1)] = v; | ||
break; | ||
default: | ||
newData.props[k] = v; | ||
} | ||
} | ||
} | ||
return h(selector, newData, children); | ||
}; | ||
helper = function(selector, data, children) { | ||
var k, newData, v; | ||
newData = { | ||
"class": {}, | ||
on: {}, | ||
attrs: {}, | ||
props: {} | ||
}; | ||
for (k in data) { | ||
if (!hasProp.call(data, k)) continue; | ||
v = data[k]; | ||
switch (k) { | ||
case "selector": | ||
selector += v; | ||
break; | ||
case "class": | ||
case "key": | ||
case "style": | ||
case "on": | ||
case "attrs": | ||
case "props": | ||
newData[k] = v; | ||
break; | ||
default: | ||
switch (k[0]) { | ||
case "$": | ||
newData.on[k.slice(1)] = v; | ||
break; | ||
case "%": | ||
newData.attrs[k.slice(1)] = v; | ||
break; | ||
case ".": | ||
newData["class"][k.slice(1)] = v; | ||
break; | ||
default: | ||
newData.props[k] = v; | ||
} | ||
} | ||
defineTag = module.exports.defineTag = function(tag) { | ||
return function() { | ||
var args, params, sel; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
switch (args.length) { | ||
case 0: | ||
return h(tag); | ||
case 1: | ||
if (looksLikeSelector(args[0])) { | ||
return h(tag + args[0]); | ||
} | ||
if (isValidSnabbdomChild(args[0])) { | ||
return h(tag, {}, args); | ||
} | ||
if (typeof args[0] === "object") { | ||
return helper(tag, args[0]); | ||
} | ||
console.log.apply(args); | ||
throw new Error("invalid single kjappas tag argument"); | ||
} | ||
return h(selector, newData, children); | ||
sel = tag; | ||
if (looksLikeSelector(args[0])) { | ||
sel += args.shift(); | ||
} | ||
if (typeof args[0] === "object") { | ||
params = args.shift(); | ||
} | ||
return helper(sel, params, [].concat.apply([], args)); | ||
}; | ||
}; | ||
defineTag = module.exports.defineTag = function(tag) { | ||
return function() { | ||
var args, params, sel; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
switch (args.length) { | ||
case 0: | ||
return h(tag); | ||
case 1: | ||
if (looksLikeSelector(args[0])) { | ||
return h(tag + args[0]); | ||
} | ||
if (isValidSnabbdomChild(args[0])) { | ||
return h(tag, {}, args); | ||
} | ||
if (typeof args[0] === "object") { | ||
return helper(tag, args[0]); | ||
} | ||
console.log.apply(args); | ||
throw new Error("invalid single kjappas tag argument"); | ||
} | ||
sel = tag; | ||
if (looksLikeSelector(args[0])) { | ||
sel += args.shift(); | ||
} | ||
if (typeof args[0] === "object") { | ||
params = args.shift(); | ||
} | ||
return helper(sel, params, [].concat.apply([], args)); | ||
}; | ||
}; | ||
tagNames = module.exports.tagNames = "a abbr address article aside audio b bdi bdo blockquote 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 header hgroup i iframe ins kbd label legend li mark menu meter nav noscript object ol optgroup option output p pre progress q rp rt ruby s samp script section select small span strong style sub summary sup table tbody td textarea tfoot th thead time title tr u ul video applet acronym bgsound dir frameset noframes isindex area base br col command embed hr img input keygen link meta param source track wbr basefont frame applet acronym bgsound dir frameset noframes isindex listing nextid noembed plaintext rb strike xmp big blink center font marquee multicol nobr spacer tt basefont frame main map".split(" "); | ||
tagNames = module.exports.tagNames = "a abbr address article aside audio b bdi bdo blockquote 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 header hgroup i iframe ins kbd label legend li mark menu meter nav noscript object ol optgroup option output p pre progress q rp rt ruby s samp script section select small span strong style sub summary sup table tbody td textarea tfoot th thead time title tr u ul video applet acronym bgsound dir frameset noframes isindex area base br col command embed hr img input keygen link meta param source track wbr basefont frame applet acronym bgsound dir frameset noframes isindex listing nextid noembed plaintext rb strike xmp big blink center font marquee multicol nobr spacer tt basefont frame main map".split(" "); | ||
tags = {}; | ||
tags = {}; | ||
module.exports = { | ||
tags: tags | ||
}; | ||
module.exports = { | ||
tags: tags | ||
}; | ||
for (i = 0, len = tagNames.length; i < len; i++) { | ||
t = tagNames[i]; | ||
module.exports[t] = tags[t] = defineTag(t); | ||
} | ||
for (i = 0, len = tagNames.length; i < len; i++) { | ||
t = tagNames[i]; | ||
module.exports[t] = tags[t] = defineTag(t); | ||
} | ||
tagMod = module.exports.tagMod = function(tagFunc, modFunc) { | ||
return function() { | ||
var r; | ||
if (typeof tagFunc === "string") { | ||
tagFunc = tags[tagFunc]; | ||
} | ||
r = tagFunc.apply(this, arguments); | ||
modFunc(r); | ||
return r; | ||
}; | ||
tagMod = module.exports.tagMod = function(tagFunc, modFunc) { | ||
return function() { | ||
var r; | ||
if (typeof tagFunc === "string") { | ||
tagFunc = tags[tagFunc]; | ||
} | ||
r = tagFunc.apply(this, arguments); | ||
modFunc(r); | ||
return r; | ||
}; | ||
}; | ||
debounceZero = function(fn) { | ||
var cb, timeout; | ||
timeout = null; | ||
return cb = function() { | ||
var args, tieout; | ||
args = arguments; | ||
clearTimeout(timeout); | ||
return tieout = setTimeout((function() { | ||
return fn.apply(null, args); | ||
}), 0); | ||
}; | ||
debounceZero = function(fn) { | ||
var cb, timeout; | ||
timeout = null; | ||
return cb = function() { | ||
var args, tieout; | ||
args = arguments; | ||
clearTimeout(timeout); | ||
return tieout = setTimeout((function() { | ||
return fn.apply(null, args); | ||
}), 0); | ||
}; | ||
}; | ||
module.exports.createRefresh = function(fn, vnode, patch) { | ||
patch || (patch = snabbdom.init([sdClass, sdProps, sdAttrs, sdStyle, sdEvents])); | ||
return debounceZero(function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return vnode = patch(vnode, fn.apply(null, args)); | ||
}); | ||
}; | ||
module.exports.createRefresh = function(fn, vnode, patch) { | ||
patch || (patch = snabbdom.init([sdClass, sdProps, sdAttrs, sdStyle, sdEvents])); | ||
return debounceZero(function() { | ||
var args; | ||
args = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
return vnode = patch(vnode, fn.apply(null, args)); | ||
}); | ||
}; | ||
defaultPrevented = module.exports.defaultPrevented = function() { | ||
var args, fn; | ||
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; | ||
if (!fn) { | ||
return fn; | ||
} | ||
return function(ev) { | ||
ev.preventDefault(); | ||
return fn.apply(null, [ev].concat(slice.call(args))); | ||
}; | ||
defaultPrevented = module.exports.defaultPrevented = function() { | ||
var args, fn; | ||
fn = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : []; | ||
if (!fn) { | ||
return fn; | ||
} | ||
return function(ev) { | ||
ev.preventDefault(); | ||
return fn.apply(null, [ev].concat(slice.call(args))); | ||
}; | ||
}; | ||
module.exports.infest = function(obj) { | ||
var k, results, v; | ||
if (obj == null) { | ||
obj = window; | ||
module.exports.infest = function(obj) { | ||
var k, results, v; | ||
if (obj == null) { | ||
obj = window; | ||
} | ||
results = []; | ||
for (k in tags) { | ||
if (!hasProp.call(tags, k)) continue; | ||
v = tags[k]; | ||
if (k !== "map") { | ||
results.push(obj[k] = v); | ||
} else { | ||
results.push(void 0); | ||
} | ||
results = []; | ||
for (k in tags) { | ||
if (!hasProp.call(tags, k)) continue; | ||
v = tags[k]; | ||
if (k !== "map") { | ||
results.push(obj[k] = v); | ||
} else { | ||
results.push(void 0); | ||
} | ||
} | ||
return results; | ||
}; | ||
} | ||
return results; | ||
}; | ||
Link = module.exports.Link = tagMod("a", function(t) { | ||
var base; | ||
(base = t.data.props).href || (base.href = "#"); | ||
return t.data.on.click = defaultPrevented(t.data.on.click); | ||
}); | ||
Link = module.exports.Link = tagMod("a", function(t) { | ||
var base; | ||
(base = t.data.props).href || (base.href = "#"); | ||
return t.data.on.click = defaultPrevented(t.data.on.click); | ||
}); | ||
Button = module.exports.Button = function(props) { | ||
var text; | ||
text = props.value; | ||
delete props.value; | ||
return button(props, text); | ||
}; | ||
}).call(this); | ||
Button = module.exports.Button = function(props) { | ||
var text; | ||
text = props.value; | ||
delete props.value; | ||
return button(props, text); | ||
}; |
{ | ||
"name": "kjappas", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "HTML-as-JavaScript Snabbdom template library", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepublish": "coffee -c index.coffee" | ||
"prepublish": "coffee -c -b index.coffee" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
18429
169