made with requirebin
Created
August 5, 2014 20:25
-
-
Save jessetane/f70ec67a55f06167eeb4 to your computer and use it in GitHub Desktop.
requirebin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hg = require('hyperglue2') | |
var html = '<div><ul><li></li></ul></div>'; | |
var el = hg(html, { li: [ 1, 2, 3 ] }); | |
console.log(el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"3yUnou":[function(require,module,exports){var domify=require("domify");module.exports=hyperglue;function hyperglue(el,data){if(typeof el==="string"){el=domify(el)}if(!data&&data!=="")return el;if(typeof data==="object"){for(var selector in data){var value=data[selector];if(selector==="_text"){el.innerText=value}else if(selector==="_html"){el.innerHTML=value}else if(selector==="_attr"){for(var attr in value){var val=value[attr];if(val===null||val===undefined){el.removeAttribute(attr)}else{el.setAttribute(attr,value[attr])}}}else{var isArray=Array.isArray(value);var needsCache=false;var matches=null;if(isArray){el.hyperglueArrays=el.hyperglueArrays||{};matches=el.hyperglueArrays[selector];if(!matches){el.hyperglueArrays[selector]=[];needsCache=true}}matches=matches||el.querySelectorAll(selector);for(var i=0;i<matches.length;i++){var match=matches[i];if(isArray){if(!match.parentNode)continue;if(needsCache&&needsCache!==match.parent){needsCache=match.parentNode;el.hyperglueArrays[selector].push({node:match.cloneNode(true),parentNode:match.parentNode,cloneNode:function(){return this.node.cloneNode(true)}})}var parent=match.parentNode;while(parent.childNodes.length){parent.removeChild(parent.childNodes[0])}for(var n in value){var item=value[n];parent.appendChild(hyperglue(match.cloneNode(true),item))}}else{hyperglue(match,value)}}}}}else{el.innerText=data}return el}},{domify:3}],hyperglue2:[function(require,module,exports){module.exports=require("3yUnou")},{}],3:[function(require,module,exports){module.exports=parse;var map={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:[0,"",""]};map.td=map.th=[3,"<table><tbody><tr>","</tr></tbody></table>"];map.option=map.optgroup=[1,'<select multiple="multiple">',"</select>"];map.thead=map.tbody=map.colgroup=map.caption=map.tfoot=[1,"<table>","</table>"];map.text=map.circle=map.ellipse=map.line=map.path=map.polygon=map.polyline=map.rect=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"];function parse(html,doc){if("string"!=typeof html)throw new TypeError("String expected");if(!doc)doc=document;var m=/<([\w:]+)/.exec(html);if(!m)return doc.createTextNode(html);html=html.replace(/^\s+|\s+$/g,"");var tag=m[1];if(tag=="body"){var el=doc.createElement("html");el.innerHTML=html;return el.removeChild(el.lastChild)}var wrap=map[tag]||map._default;var depth=wrap[0];var prefix=wrap[1];var suffix=wrap[2];var el=doc.createElement("div");el.innerHTML=prefix+html+suffix;while(depth--)el=el.lastChild;if(el.firstChild==el.lastChild){return el.removeChild(el.firstChild)}var fragment=doc.createDocumentFragment();while(el.firstChild){fragment.appendChild(el.removeChild(el.firstChild))}return fragment}},{}]},{},[]);var hg=require("hyperglue2");var html="<div><ul><li></li></ul></div>";var el=hg(html,{li:[1,2,3]});console.log(el); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "requirebin-sketch", | |
"version": "1.0.0", | |
"dependencies": { | |
"hyperglue2": "0.0.3" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style type='text/css'>html, body { margin: 0; padding: 0; border: 0; } | |
body, html { height: 100%; width: 100%; }</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment