Skip to content

Instantly share code, notes, and snippets.

@zkochan
Last active November 13, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkochan/27ea2b9d6dc72abea03c to your computer and use it in GitHub Desktop.
Save zkochan/27ea2b9d6dc72abea03c to your computer and use it in GitHub Desktop.
requirebin sketch
var registerPlugin = require('register-plugin');
var domify = require('domify')
function helloWorld(app, options, next) {
app.sayIt = function() {
document.body.appendChild(domify('Hello world!'));
};
next();
}
helloWorld.attributes = {
name: 'hello-world',
version: '1.0.0'
};
var app = {};
registerPlugin(app, helloWorld, function(err) {
app.sayIt();
});
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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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}({1:[function(require,module,exports){"use strict";var TopoSort=function(){this.ins=Object.create(null);this.map=Object.create(null)};module.exports=TopoSort;TopoSort.prototype.add=function(node,nodes){nodes=Array.isArray(nodes)?nodes:[nodes];this.ins[node]=this.ins[node]||0;for(var i=0;i<nodes.length;++i){var n=nodes[i];this.ins[n]=this.ins[n]?this.ins[n]+1:1}this.map[node]=this.map[node]?this.map[node].concat(nodes):nodes};TopoSort.prototype.sort=function(){var s=[];var l=[];var node;var unsorted=0;for(node in this.ins){++unsorted;if(this.ins[node]===0){s.push(node)}}while(s.length!==0){var n=s.pop();l.push(n);--unsorted;if(this.map[n]){var len=this.map[n].length;for(var i=0;i<len;++i){var m=this.map[n][i];if(--this.ins[m]===0){s.push(m)}}}}if(unsorted!==0){var circular=[];for(node in this.ins){if(this.ins[node]!==0){circular.push(node)}}throw new Error("At least 1 circular dependency in nodes: \n\n"+circular.join("\n")+"\n\nGraph cannot be sorted!")}return l}},{}],"register-plugin":[function(require,module,exports){"use strict";var TopoSort=require("topo-sort");function registerNext(target,plugins,cb){var plugin=plugins.shift();if(!plugin){return cb()}plugin.register(target,plugin.pluginOptions,function(err){if(err){return cb(err)}registerNext(target,plugins,cb)})}function register(target,plugins,cb){plugins=[].concat(plugins);var registrations=[];for(var i=0;i<plugins.length;++i){var plugin=plugins[i];if(typeof plugin==="function"&&!plugin.register){plugin={register:plugin}}if(plugin.register.register){plugin.register=plugin.register.register}var attributes=plugin.register.attributes;var registration={register:plugin.register,name:attributes.name||attributes.pkg.name,version:attributes.version||attributes.pkg.version,pluginOptions:plugin.options,dependencies:attributes.dependencies};registrations.push(registration)}var registrationDict={};var tsort=new TopoSort;registrations.forEach(function(registration){registrationDict[registration.name]=registration;var deps=registration.dependencies||[];tsort.add(registration.name,[].concat(deps))});var sortedPluginNames=tsort.sort();sortedPluginNames.reverse();var sortedPlugins=[];for(var i=0;i<sortedPluginNames.length;i++){var pluginName=sortedPluginNames[i];if(!registrationDict[pluginName]){return cb(new Error("Plugin called "+pluginName+" required by dependencies but wasn't registered"))}sortedPlugins.push(registrationDict[pluginName])}registerNext(target,sortedPlugins,cb)}module.exports=register},{"topo-sort":1}]},{},[]);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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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}({domify:[function(require,module,exports){module.exports=parse;var innerHTMLBug=false;var bugTestDiv;if(typeof document!=="undefined"){bugTestDiv=document.createElement("div");bugTestDiv.innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';innerHTMLBug=!bugTestDiv.getElementsByTagName("link").length;bugTestDiv=undefined}var map={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:innerHTMLBug?[1,"X<div>","</div>"]:[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.polyline=map.ellipse=map.polygon=map.circle=map.text=map.line=map.path=map.rect=map.g=[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 registerPlugin=require("register-plugin");var domify=require("domify");function helloWorld(app,options,next){app.sayIt=function(){document.body.appendChild(domify("Hello world!"))};next()}helloWorld.attributes={name:"hello-world",version:"1.0.0"};var app={};registerPlugin(app,helloWorld,function(err){app.sayIt()});
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"register-plugin": "0.1.1",
"domify": "1.4.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment