Skip to content
Browse files

Updated the plugin registry and added views

  • Loading branch information...
1 parent 809d417 commit 060c800d2f649dc80641f79423ba1b45ee63cd43 @sax1johno committed Feb 19, 2013
View
1 .c9revisions/README.md.c9save
@@ -1 +1,2 @@
{"ts":1360024688189,"silentsave":true,"restoring":false,"patch":[[{"diffs":[[1,"mongoose-schema-registry\n========================\n\nThis allows users to register schemas without creating a mongoose model. This allows extension of schemas later on prior to registering those models."]],"start1":0,"start2":0,"length1":0,"length2":201}]],"length":201}
+{"contributors":[],"silentsave":false,"ts":1361255713824,"patch":[[{"diffs":[[-1,"mongoose-schema"],[1,"ghiraldi-plugin"],[0,"-reg"]],"start1":0,"start2":0,"length1":19,"length2":19},{"diffs":[[0,"\n\nTh"],[-1,"is allows users to register schemas without creating a mongoose model. This allows extension of schemas later on prior to registering those model"],[1,"e plugin registry allows for the registration of plugins into a central store and provides access to plugin\nproperties for other controllers. This is particularly useful for things like the admin core plugin, which\nuses the registry to build the admin views for controller"],[0,"s."]],"start1":49,"start2":49,"length1":152,"length2":279}]],"length":328,"saved":false}
View
14 .c9revisions/lib/plugin.js.c9save
@@ -0,0 +1,14 @@
+{"ts":1361250596771,"silentsave":true,"restoring":false,"patch":[[]],"length":0}
+{"ts":1361251170871,"patch":[[{"diffs":[[1,"\nvar Plugin = {};\n\nPlugin.views = [];\n\n"]],"start1":0,"start2":0,"length1":0,"length2":39}]],"length":39,"saved":false}
+{"ts":1361251178342,"patch":[[{"diffs":[[-1,"\n"],[0,"var Plug"]],"start1":0,"start2":0,"length1":9,"length2":8},{"diffs":[[0,"ws = [];"],[-1,"\n\n"]],"start1":28,"start2":28,"length1":10,"length2":8}]],"length":36,"saved":false}
+{"contributors":[],"silentsave":false,"ts":1361252921605,"patch":[[{"diffs":[[0,"lugin = "],[1,"function()"],[0,"{};\n\nPlu"]],"start1":5,"start2":5,"length1":16,"length2":26},{"diffs":[[0,"ws = [];"],[1,"\n\nmodule.exports = Plugin;"]],"start1":38,"start2":38,"length1":8,"length2":34}]],"length":72,"saved":false}
+{"ts":1361252980349,"patch":[[{"diffs":[[0,"\nPlugin."],[1,"prototype."],[0,"views = "]],"start1":27,"start2":27,"length1":16,"length2":26}]],"length":82,"saved":false}
+{"ts":1361253041540,"patch":[[{"diffs":[[0,"unction("],[1,"properties"],[0,"){};\n\nPl"]],"start1":14,"start2":14,"length1":16,"length2":26}]],"length":92,"saved":false}
+{"ts":1361253047593,"patch":[[{"diffs":[[0,"gin."],[-1,"prototype."],[0,"view"]],"start1":41,"start2":41,"length1":18,"length2":8}]],"length":82,"saved":false}
+{"ts":1361254268108,"patch":[[{"diffs":[[-1,"var Plugin = function(properties){};\n\nPlugin.views = [];"],[1,"function Plugin (obj, options) {\n if (!(this instanceof Plugin))\n return new Plugin(obj, options);\n}"],[0,"\n\nmo"]],"start1":0,"start2":0,"length1":60,"length2":108}]],"length":130,"saved":false}
+{"ts":1361254278924,"patch":[[{"diffs":[[0,"tions);\n"],[1," \n this.views = [];\n"],[0,"}\n\nmodul"]],"start1":95,"start2":95,"length1":16,"length2":42}]],"length":156,"saved":false}
+{"ts":1361254311865,"patch":[[{"diffs":[[0,"s = [];\n"],[1," \n if (obj) {\n this.add(obj);\n }\n\n"],[0,"}\n\nmodul"]],"start1":121,"start2":121,"length1":16,"length2":66}]],"length":206,"saved":false}
+{"ts":1361254731553,"patch":[[{"diffs":[[0,"his."],[-1,"add(obj"],[1,"views.push(obj.views"],[0,");\n "]],"start1":158,"start2":158,"length1":15,"length2":28}]],"length":219,"saved":false}
+{"ts":1361255139587,"patch":[[{"diffs":[[1,"var _ = require('underscore');\n\n"],[0,"function"]],"start1":0,"start2":0,"length1":8,"length2":40},{"diffs":[[0,"(obj) {\n"],[1," if (!_.isUndefined(obj.views) && !_.isNull(obj.views)) {\n if (_.isArray(obj.views)) {\n obj.views.forEach(function(view) {\n this.views.push(obj.views); \n });\n } \n }\n"],[0," "]],"start1":173,"start2":173,"length1":16,"length2":265}]],"length":500,"saved":false}
+{"ts":1361255141077,"patch":[[{"diffs":[[0," }\n"],[-1," this.views.push(obj.views);\n"],[0," "]],"start1":426,"start2":426,"length1":44,"length2":8}]],"length":464,"saved":false}
+{"ts":1361255168765,"patch":[[{"diffs":[[0," "],[-1,"if (!_.isUndefined(obj.views) && !_.isNull(obj.views)) {\n if (_.isArray(obj.views)) {\n obj.views.forEach(function(view) {\n this.views.push(obj.views); \n });\n } \n }"],[1,"this.views = obj.views;"],[0,"\n "]],"start1":185,"start2":185,"length1":248,"length2":31}]],"length":247,"saved":false}
View
8 .c9revisions/lib/plugin_registry.js.c9save
@@ -42,3 +42,11 @@
{"ts":1360558508446,"patch":[[{"diffs":[[0,"ion("],[1,"tag, "],[0,"schema,"],[-1," tag,"],[0," fn)"]],"start1":696,"start2":696,"length1":20,"length2":20}]],"length":2181,"saved":false}
{"contributors":[],"silentsave":false,"ts":1360619672703,"patch":[[{"diffs":[[0," "],[-1,"console.log(\"keys = \" + JSON.stringify(_.keys(schemas)));"],[1,"var keys = _.keys(schemas);\n if (!_.isArray(keys)) {\n keys = [keys];\n }"],[0,"\n "]],"start1":1868,"start2":1868,"length1":65,"length2":104},{"diffs":[[0," fn("],[-1,"_."],[0,"keys"],[-1,"(schemas)"],[0,"); "],[-1," "],[-1," "],[0,"\n "]],"start1":2031,"start2":2031,"length1":37,"length2":20},{"diffs":[[0," return "],[-1,"_."],[0,"keys"],[-1,"(schemas)"],[0,";\n }\n"]],"start1":2065,"start2":2065,"length1":31,"length2":20}]],"length":2192,"saved":false}
{"contributors":[],"silentsave":false,"ts":1360716950650,"patch":[[{"diffs":[[0,"tEmitter"],[-1,";\n"],[1,",\n Schema = mongoose.Schema;\n "],[0,"\nfunctio"]],"start1":108,"start2":108,"length1":18,"length2":52},{"diffs":[[0,"tion(tag, fn) {\n"],[1," if (_.isUndefined(schemas[tag])) {\n schemas[tag] = new Schema({});\n }\n"],[0," if (!_.i"]],"start1":1502,"start2":1502,"length1":32,"length2":128}]],"length":2322,"saved":false}
+{"contributors":[],"silentsave":false,"ts":1361250770685,"patch":[[{"diffs":[[0," "],[-1,"Schema = mongoose.Schema"],[1,"plugin = require('./plugin')"],[0,";\n "]],"start1":118,"start2":118,"length1":32,"length2":36},{"diffs":[[0,"unction "],[-1,"Mongoose"],[1,"Plugin"],[0,"Registry"]],"start1":158,"start2":158,"length1":24,"length2":22},{"diffs":[[0," var "],[-1,"schema"],[1,"plugin"],[0,"s = {};\n"]],"start1":185,"start2":185,"length1":22,"length2":22}]],"length":2324,"saved":false}
+{"ts":1361250791805,"patch":[[{"diffs":[[0,"on(tag, "],[-1,"schema"],[1,"plugin"],[0,", fn) {\n"]],"start1":733,"start2":733,"length1":22,"length2":22},{"diffs":[[0," fn("],[-1,"schema"],[1,"plugin"],[0,"s[tag] = sch"]],"start1":829,"start2":829,"length1":30,"length2":30},{"diffs":[[0,"[tag] = "],[-1,"schema"],[1,"plugin"],[0,");\n "]],"start1":848,"start2":848,"length1":22,"length2":22},{"diffs":[[0,"e {\n "],[-1,"schema"],[1,"plugin"],[0,"s[tag] = schema;"]],"start1":878,"start2":878,"length1":38,"length2":38},{"diffs":[[0,"[tag] = "],[-1,"schema"],[1,"plugin"],[0,";\n "]],"start1":901,"start2":901,"length1":22,"length2":22},{"diffs":[[0,"', tag, "],[-1,"schema"],[1,"plugin"],[0,"); "]],"start1":949,"start2":949,"length1":22,"length2":22}]],"length":2324,"saved":false}
+{"ts":1361250814636,"patch":[[{"diffs":[[0,"leted = "],[-1,"schema"],[1,"plugin"],[0,"s[tag];\n"]],"start1":1226,"start2":1226,"length1":22,"length2":22},{"diffs":[[0," fn(delete "],[-1,"schema"],[1,"plugin"],[0,"s[tag]); "]],"start1":1329,"start2":1329,"length1":30,"length2":30},{"diffs":[[0," delete "],[-1,"schema"],[1,"plugin"],[0,"s[tag];\n"]],"start1":1403,"start2":1403,"length1":22,"length2":22},{"diffs":[[0,"defined("],[-1,"schema"],[1,"plugin"],[0,"s[tag]))"]],"start1":1538,"start2":1538,"length1":22,"length2":22},{"diffs":[[0," "],[-1,"schema"],[1,"plugin"],[0,"s[tag] ="]],"start1":1567,"start2":1567,"length1":22,"length2":22},{"diffs":[[0,"new "],[-1,"Schema"],[1,"plugin"],[0,"({})"]],"start1":1590,"start2":1590,"length1":14,"length2":14},{"diffs":[[0," fn("],[-1,"schema"],[1,"plugin"],[0,"s[tag]);"]],"start1":1674,"start2":1674,"length1":22,"length2":22},{"diffs":[[0," return "],[-1,"schema"],[1,"plugin"],[0,"s[tag];\n"]],"start1":1714,"start2":1714,"length1":22,"length2":22}]],"length":2324,"saved":false}
+{"ts":1361250825699,"patch":[[{"diffs":[[0," fn("],[-1,"schema"],[1,"plugin"],[0,"s);\n "]],"start1":1898,"start2":1898,"length1":22,"length2":22},{"diffs":[[0," return "],[-1,"schema"],[1,"plugin"],[0,"s;\n }"]],"start1":1933,"start2":1933,"length1":22,"length2":22},{"diffs":[[0," _.keys("],[-1,"schema"],[1,"plugin"],[0,"s);\n "]],"start1":2014,"start2":2014,"length1":22,"length2":22}]],"length":2324,"saved":false}
+{"ts":1361250835920,"patch":[[{"diffs":[[0," }\n}\n\n"],[-1,"Mongoose"],[1,"Plugin"],[0,"Registry"]],"start1":2212,"start2":2212,"length1":24,"length2":22},{"diffs":[[0,"new "],[-1,"Mongoose"],[1,"Plugin"],[0,"Regi"]],"start1":2299,"start2":2299,"length1":16,"length2":14}]],"length":2320,"saved":false}
+{"ts":1361250843922,"patch":[[{"diffs":[[0,"var "],[-1,"mongoose = require('mongoose'),\n "],[0,"_ = "]],"start1":0,"start2":0,"length1":44,"length2":8}]],"length":2284,"saved":false}
+{"ts":1361251259384,"patch":[[{"diffs":[[0,"xports ="],[1," {\n registry:"],[0," new Plu"]],"start1":2254,"start2":2254,"length1":16,"length2":32},{"diffs":[[0,"gistry()"],[1,",\n plugin: plugin\n}"],[0,";"]],"start1":2291,"start2":2291,"length1":9,"length2":31}]],"length":2322,"saved":false}
+{"ts":1361251344074,"patch":[[{"diffs":[[0,"stry(),\n "],[-1,"p"],[1,"P"],[0,"lugin: plugi"]],"start1":2293,"start2":2293,"length1":25,"length2":25}]],"length":2322,"saved":false}
View
21 .c9revisions/tests/plugin_registry_test.js.c9save
@@ -33,3 +33,24 @@
{"ts":1360558570005,"patch":[[{"diffs":[[0," reg.add("],[1,"'t', "],[0,"testSchema, 't',"]],"start1":2296,"start2":2296,"length1":32,"length2":37},{"diffs":[[0,"'t', testSchema,"],[-1," 't',"],[0," function(succes"]],"start1":2312,"start2":2312,"length1":37,"length2":32}]],"length":3358,"saved":false}
{"ts":1360558592120,"patch":[[{"diffs":[[0," reg.add("],[1,"'t', "],[0,"testSchema, 't',"]],"start1":2904,"start2":2904,"length1":32,"length2":37},{"diffs":[[0,"ema,"],[-1," 't',"],[0," fun"]],"start1":2932,"start2":2932,"length1":13,"length2":8},{"diffs":[[0," reg.add("],[1,"'t2', "],[0,"testSchema2, 't2"]],"start1":2961,"start2":2961,"length1":32,"length2":38},{"diffs":[[0,"Schema2,"],[-1," 't2',"],[0," functio"]],"start1":2987,"start2":2987,"length1":22,"length2":16},{"diffs":[[0,"reg.add("],[1,"'t3', "],[0,"testSche"]],"start1":3032,"start2":3032,"length1":16,"length2":22},{"diffs":[[0,"ma3,"],[-1," 't3',"],[0," fun"]],"start1":3054,"start2":3054,"length1":14,"length2":8}]],"length":3358,"saved":false}
{"contributors":[],"silentsave":false,"ts":1361250320157,"patch":[[{"diffs":[[0," var "],[-1,"mongoose"],[1,"plugin"],[0,"Registry"]],"start1":189,"start2":189,"length1":24,"length2":22},{"diffs":[[0,"ire('../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registry');"]],"start1":218,"start2":218,"length1":32,"length2":30},{"diffs":[[0,"ire('../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registry');"]],"start1":331,"start2":331,"length1":32,"length2":30},{"diffs":[[0,"ire('../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registry');"]],"start1":833,"start2":833,"length1":32,"length2":30},{"diffs":[[0,"ire('../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registry');"]],"start1":1259,"start2":1259,"length1":32,"length2":30},{"diffs":[[0,"ire('../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registry');"]],"start1":1792,"start2":1792,"length1":32,"length2":30},{"diffs":[[0,"ire('../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registry');"]],"start1":2188,"start2":2188,"length1":32,"length2":30},{"diffs":[[0,"'../lib/"],[-1,"mongoose"],[1,"plugin"],[0,"_registr"]],"start1":2727,"start2":2727,"length1":24,"length2":22}]],"length":3342,"saved":false}
+{"contributors":[],"silentsave":false,"ts":1361251338200,"patch":[[{"diffs":[[0,"var "],[-1,"mongoose = require('mongoose');\nvar Schema = mongoose.Schema"],[1,"pluginRegistry = require('../lib/plugin_registry');\nvar Plugin = pluginRegistry.Plugin;"],[0,"\n\nex"]],"start1":36,"start2":36,"length1":68,"length2":95}]],"length":3369,"saved":false}
+{"ts":1361251370753,"patch":[[{"diffs":[[0,"lugin_registry')"],[1,".registry"],[0,";\n test.d"]],"start1":258,"start2":258,"length1":32,"length2":41},{"diffs":[[0,"estSchema = new "],[-1,"Schema"],[1,"Plugin"],[0,"({\n t"]],"start1":411,"start2":411,"length1":38,"length2":38}]],"length":3378,"saved":false}
+{"ts":1361251378807,"patch":[[{"diffs":[[0,"lugin_registry')"],[1,".registry"],[0,";\n var te"]],"start1":380,"start2":380,"length1":32,"length2":41}]],"length":3387,"saved":false}
+{"ts":1361251408763,"patch":[[{"diffs":[[0," var test"],[-1,"Schema"],[1,"Plugin"],[0," = new Plugi"]],"start1":411,"start2":411,"length1":30,"length2":30},{"diffs":[[0,"Plugin({"],[1,"views: ["],[0,"\n "]],"start1":436,"start2":436,"length1":16,"length2":24},{"diffs":[[0," "],[-1,"title: String,\n"],[1," '../test/test',\n "],[0," "]],"start1":457,"start2":457,"length1":36,"length2":42},{"diffs":[[0," "],[-1," "],[1,"'../test/"],[0,"test"],[-1,":"],[1,"2'\n"],[0," "],[-1,"String"],[1," ]"],[0,"\n "]],"start1":493,"start2":493,"length1":36,"length2":45}]],"length":3410,"saved":false}
+{"ts":1361251416757,"patch":[[{"diffs":[[0,"eg.add('t', test"],[-1,"Schema"],[1,"Plugin"],[0,", function(succe"]],"start1":552,"start2":552,"length1":38,"length2":38}]],"length":3410,"saved":false}
+{"ts":1361251425329,"patch":[[{"diffs":[[0,"eg.log(function("],[-1,"schema"],[1,"plugin"],[0,"s) {\n "]],"start1":683,"start2":683,"length1":38,"length2":38},{"diffs":[[0,"(JSON.stringify("],[-1,"schema"],[1,"plugin"],[0,"s));\n "]],"start1":737,"start2":737,"length1":38,"length2":38}]],"length":3410,"saved":false}
+{"ts":1361251432424,"patch":[[{"diffs":[[0,"lugin_registry')"],[1,".registry"],[0,";\n var te"]],"start1":914,"start2":914,"length1":32,"length2":41},{"diffs":[[0,"estSchema = new "],[-1,"Schema"],[1,"Plugin"],[0,"({\n t"]],"start1":954,"start2":954,"length1":38,"length2":38}]],"length":3419,"saved":false}
+{"ts":1361251447989,"patch":[[{"diffs":[[0,"n({\n"],[-1," title: String,\n test: String\n"],[0," "]],"start1":975,"start2":975,"length1":71,"length2":8},{"diffs":[[0,"on(tag, "],[-1,"schema"],[1,"plugin"],[0,") {\n "]],"start1":1019,"start2":1019,"length1":22,"length2":22},{"diffs":[[0,"ed with "],[-1,"schema"],[1,"plugin"],[0," \" + JSO"]],"start1":1085,"start2":1085,"length1":22,"length2":22},{"diffs":[[0," JSON.stringify("],[-1,"schema"],[1,"plugin"],[0,"));\n "]],"start1":1103,"start2":1103,"length1":38,"length2":38}]],"length":3356,"saved":false}
+{"ts":1361251457284,"patch":[[{"diffs":[[0," var test"],[-1,"Schema"],[1,"Plugin"],[0," = new Plugi"]],"start1":945,"start2":945,"length1":30,"length2":30},{"diffs":[[0,"t', test"],[-1,"Schema"],[1,"Plugin"],[0,");\n "]],"start1":1183,"start2":1183,"length1":22,"length2":22}]],"length":3356,"saved":false}
+{"ts":1361251471330,"patch":[[{"diffs":[[0,"var test"],[-1,"Schema"],[1,"Plugin"],[0," = new "],[-1,"Schema"],[1,"Plugin"],[0,"({\n "]],"start1":1312,"start2":1312,"length1":35,"length2":35},{"diffs":[[0,"eg.add('t', test"],[-1,"Schema"],[1,"Plugin"],[0,", function(succe"]],"start1":1376,"start2":1376,"length1":38,"length2":38},{"diffs":[[0,"eg.log(function("],[-1,"schema"],[1,"plugin"],[0,"s) {\n "]],"start1":1571,"start2":1571,"length1":38,"length2":38},{"diffs":[[0,"(JSON.stringify("],[-1,"schema"],[1,"plugin"],[0,"s));\n "]],"start1":1629,"start2":1629,"length1":38,"length2":38}]],"length":3356,"saved":false}
+{"ts":1361251475839,"patch":[[{"diffs":[[0,"ved the "],[-1,"schema"],[1,"plugin"],[0," from th"]],"start1":1518,"start2":1518,"length1":22,"length2":22}]],"length":3356,"saved":false}
+{"ts":1361251486563,"patch":[[{"diffs":[[0,"lugin_registry')"],[1,".registry"],[0,";\n var te"]],"start1":1819,"start2":1819,"length1":32,"length2":41},{"diffs":[[0,"estSchema = new "],[-1,"Schema"],[1,"Plugin"],[0,"({\n \n"]],"start1":1859,"start2":1859,"length1":38,"length2":38}]],"length":3365,"saved":false}
+{"ts":1361251489682,"patch":[[{"diffs":[[0,"lugin_registry')"],[1,".registry"],[0,";\n var te"]],"start1":1286,"start2":1286,"length1":32,"length2":41}]],"length":3374,"saved":false}
+{"ts":1361251500172,"patch":[[{"diffs":[[0,"move', function("],[-1,"schema"],[1,"plugin"],[0,") {\n "]],"start1":1936,"start2":1936,"length1":38,"length2":38},{"diffs":[[0,"le.log(\""],[-1,"schema"],[1,"plugin"],[0," = \" + J"]],"start1":1979,"start2":1979,"length1":22,"length2":22},{"diffs":[[0,"ringify("],[-1,"schema"],[1,"plugin"],[0,"));\n "]],"start1":2007,"start2":2007,"length1":22,"length2":22}]],"length":3374,"saved":false}
+{"ts":1361251503472,"patch":[[{"diffs":[[0,"eg.add('t', test"],[-1,"Schema"],[1,"Plugin"],[0,", function(succe"]],"start1":2070,"start2":2070,"length1":38,"length2":38}]],"length":3374,"saved":false}
+{"ts":1361251509241,"patch":[[{"diffs":[[0," var test"],[-1,"Schema"],[1,"Plugin"],[0," = new Plugi"]],"start1":1859,"start2":1859,"length1":30,"length2":30}]],"length":3374,"saved":false}
+{"ts":1361251517403,"patch":[[{"diffs":[[0,"var test"],[-1,"Schema"],[1,"Plugin"],[0," = new "],[-1,"Schema"],[1,"Plugin"],[0,"({\n "]],"start1":2259,"start2":2259,"length1":35,"length2":35}]],"length":3374,"saved":false}
+{"ts":1361251529760,"patch":[[{"diffs":[[0,"eg.add('t', test"],[-1,"Schema"],[1,"Plugin"],[0,", function(succe"]],"start1":2323,"start2":2323,"length1":38,"length2":38},{"diffs":[[0,"unction("],[-1,"schema"],[1,"plugin"],[0,") {\n "]],"start1":2393,"start2":2393,"length1":22,"length2":22},{"diffs":[[0,"ual("],[-1,"schema, testSchema"],[1,"plugin, testPlugin"],[0,", 'S"]],"start1":2438,"start2":2438,"length1":26,"length2":26}]],"length":3374,"saved":false}
+{"ts":1361251536750,"patch":[[{"diffs":[[0,"unction("],[-1,"schema"],[1,"plugin"],[0,"s) {\n "]],"start1":2535,"start2":2535,"length1":22,"length2":22},{"diffs":[[0,"ify("],[-1,"schema"],[1,"plugin"],[0,"s));"]],"start1":2597,"start2":2597,"length1":14,"length2":14}]],"length":3374,"saved":false}
+{"ts":1361251569413,"patch":[[{"diffs":[[0,"lugin_registry')"],[1,".registry"],[0,";\n var te"]],"start1":2768,"start2":2768,"length1":32,"length2":41},{"diffs":[[0,"test"],[-1,"Schema"],[1,"Plugin"],[0," = new "],[-1,"Schema"],[1,"Plugin"],[0,"({})"]],"start1":2807,"start2":2807,"length1":27,"length2":27},{"diffs":[[0,"test"],[-1,"Schema"],[1,"Plugin"],[0,"2 = new "],[-1,"Schema"],[1,"Plugin"],[0,"({})"]],"start1":2848,"start2":2848,"length1":28,"length2":28},{"diffs":[[0,"test"],[-1,"Schema"],[1,"Plugin"],[0,"3 = new "],[-1,"Schema"],[1,"Plugin"],[0,"({})"]],"start1":2890,"start2":2890,"length1":28,"length2":28}]],"length":3383,"saved":false}
+{"ts":1361251579730,"patch":[[{"diffs":[[0,"t', test"],[-1,"Schema"],[1,"Plugin"],[0,", functi"]],"start1":2946,"start2":2946,"length1":22,"length2":22},{"diffs":[[0,"2', test"],[-1,"Schema"],[1,"Plugin"],[0,"2, funct"]],"start1":3004,"start2":3004,"length1":22,"length2":22},{"diffs":[[0,"3', test"],[-1,"Schema"],[1,"Plugin"],[0,"3, funct"]],"start1":3067,"start2":3067,"length1":22,"length2":22}]],"length":3383,"saved":false}
View
6 README.md
@@ -1,4 +1,6 @@
-mongoose-schema-registry
+ghiraldi-plugin-registry
========================
-This allows users to register schemas without creating a mongoose model. This allows extension of schemas later on prior to registering those models.
+The plugin registry allows for the registration of plugins into a central store and provides access to plugin
+properties for other controllers. This is particularly useful for things like the admin core plugin, which
+uses the registry to build the admin views for controllers.
View
15 lib/plugin.js
@@ -0,0 +1,15 @@
+var _ = require('underscore');
+
+function Plugin (obj, options) {
+ if (!(this instanceof Plugin))
+ return new Plugin(obj, options);
+
+ this.views = [];
+
+ if (obj) {
+ this.views = obj.views;
+ }
+
+}
+
+module.exports = Plugin;
View
44 lib/plugin_registry.js
@@ -1,10 +1,9 @@
-var mongoose = require('mongoose'),
- _ = require('underscore'),
+var _ = require('underscore'),
EventEmitter = require('events').EventEmitter,
- Schema = mongoose.Schema;
+ plugin = require('./plugin');
-function MongooseRegistry() {
- var schemas = {};
+function PluginRegistry() {
+ var plugins = {};
/* This class is a singleton */
if (arguments.callee._singletonInstance) {
@@ -21,13 +20,13 @@ function MongooseRegistry() {
* @param tag the tag for this schema (used to retrieve the schema)
* @return the added schema.
**/
- this.add = function(tag, schema, fn) {
+ this.add = function(tag, plugin, fn) {
if (!_.isUndefined(fn) && !_.isNull(fn) && _.isFunction(fn)) {
- fn(schemas[tag] = schema);
+ fn(plugins[tag] = plugin);
} else {
- schemas[tag] = schema;
+ plugins[tag] = plugin;
}
- this.emit('add', tag, schema);
+ this.emit('add', tag, plugin);
};
/**
@@ -36,35 +35,35 @@ function MongooseRegistry() {
* @return true if the delete was successful, false otherwise.
**/
this.remove = function(tag, fn) {
- var deleted = schemas[tag];
+ var deleted = plugins[tag];
if (!_.isUndefined(fn) && !_.isNull(fn) && _.isFunction(fn)) {
- fn(delete schemas[tag]);
+ fn(delete plugins[tag]);
} else {
- return delete schemas[tag];
+ return delete plugins[tag];
}
this.emit('remove', deleted);
};
this.get = function(tag, fn) {
- if (_.isUndefined(schemas[tag])) {
- schemas[tag] = new Schema({});
+ if (_.isUndefined(plugins[tag])) {
+ plugins[tag] = new plugin({});
}
if (!_.isUndefined(fn) && !_.isNull(fn)) {
- fn(schemas[tag]);
+ fn(plugins[tag]);
}
- return schemas[tag];
+ return plugins[tag];
};
/** For testing purposes. Will probably go away soon **/
this.log = function(fn) {
if (!_.isUndefined(fn) && !_.isNull(fn)) {
- fn(schemas);
+ fn(plugins);
}
- return schemas;
+ return plugins;
};
this.getKeys = function(fn) {
- var keys = _.keys(schemas);
+ var keys = _.keys(plugins);
if (!_.isArray(keys)) {
keys = [keys];
}
@@ -75,6 +74,9 @@ function MongooseRegistry() {
}
}
-MongooseRegistry.prototype.__proto__ = EventEmitter.prototype;
+PluginRegistry.prototype.__proto__ = EventEmitter.prototype;
-module.exports = new MongooseRegistry();
+module.exports = {
+ registry: new PluginRegistry(),
+ Plugin: plugin
+};
View
83 tests/plugin_registry_test.js
@@ -1,91 +1,90 @@
var nodeunit = require('nodeunit');
-var mongoose = require('mongoose');
-var Schema = mongoose.Schema
+var pluginRegistry = require('../lib/plugin_registry');
+var Plugin = pluginRegistry.Plugin;
exports.registryTest = nodeunit.testCase({
'testConstructor': function(test) {
- var pluginRegistry = require('../lib/plugin_registry');
+ var pluginRegistry = require('../lib/plugin_registry').registry;
test.done();
},
'testAdd': function(test) {
- var reg = require('../lib/plugin_registry');
- var testSchema = new Schema({
- title: String,
- test: String
+ var reg = require('../lib/plugin_registry').registry;
+ var testPlugin = new Plugin({views: [
+ '../test/test',
+ '../test/test2'
+ ]
});
- reg.add('t', testSchema, function(success) {
+ reg.add('t', testPlugin, function(success) {
test.ok(success, "Registration adding should've succceeded");
- reg.log(function(schemas) {
- console.log(JSON.stringify(schemas));
+ reg.log(function(plugins) {
+ console.log(JSON.stringify(plugins));
test.done();
})
})
},
'testAddEvent': function(test) {
- var reg = require('../lib/plugin_registry');
- var testSchema = new Schema({
- title: String,
- test: String
+ var reg = require('../lib/plugin_registry').registry;
+ var testPlugin = new Plugin({
});
- reg.on('add', function(tag, schema) {
- console.log("Tag " + tag + " was added with schema " + JSON.stringify(schema));
+ reg.on('add', function(tag, plugin) {
+ console.log("Tag " + tag + " was added with plugin " + JSON.stringify(plugin));
test.done();
});
- reg.add('t', testSchema);
+ reg.add('t', testPlugin);
},
'testRemove': function(test) {
- var reg = require('../lib/plugin_registry');
- var testSchema = new Schema({
+ var reg = require('../lib/plugin_registry').registry;
+ var testPlugin = new Plugin({
});
- reg.add('t', testSchema, function(success) {
+ reg.add('t', testPlugin, function(success) {
reg.remove('t', function(success) {
- test.ok(success, 'Should have removed the schema from the registry');
- reg.log(function(schemas) {
- console.log(JSON.stringify(schemas));
+ test.ok(success, 'Should have removed the plugin from the registry');
+ reg.log(function(plugins) {
+ console.log(JSON.stringify(plugins));
test.done();
});
});
});
},
'testRemoveEvent': function(test) {
- var reg = require('../lib/plugin_registry');
- var testSchema = new Schema({
+ var reg = require('../lib/plugin_registry').registry;
+ var testPlugin = new Plugin({
});
- reg.on('remove', function(schema) {
- console.log("schema = " + JSON.stringify(schema));
+ reg.on('remove', function(plugin) {
+ console.log("plugin = " + JSON.stringify(plugin));
test.done();
})
- reg.add('t', testSchema, function(success) {
+ reg.add('t', testPlugin, function(success) {
reg.remove('t');
});
},
'testGet': function(test) {
- var reg = require('../lib/plugin_registry');
- var testSchema = new Schema({
+ var reg = require('../lib/plugin_registry').registry;
+ var testPlugin = new Plugin({
});
- reg.add('t', testSchema, function(success) {
- reg.get('t', function(schema) {
- test.deepEqual(schema, testSchema, 'Schemas should be deep equal to each other.');
- reg.log(function(schemas) {
- console.log(JSON.stringify(schemas));
+ reg.add('t', testPlugin, function(success) {
+ reg.get('t', function(plugin) {
+ test.deepEqual(plugin, testPlugin, 'Schemas should be deep equal to each other.');
+ reg.log(function(plugins) {
+ console.log(JSON.stringify(plugins));
test.done();
});
});
});
},
'testKeys': function(test) {
- var reg = require('../lib/plugin_registry');
- var testSchema = new Schema({});
- var testSchema2 = new Schema({});
- var testSchema3 = new Schema({});
+ var reg = require('../lib/plugin_registry').registry;
+ var testPlugin = new Plugin({views: ['testview1']});
+ var testPlugin2 = new Plugin({});
+ var testPlugin3 = new Plugin({});
- reg.add('t', testSchema, function(success) {
- reg.add('t2', testSchema2, function(success) {
- reg.add('t3', testSchema3, function(success) {
+ reg.add('t', testPlugin, function(success) {
+ reg.add('t2', testPlugin2, function(success) {
+ reg.add('t3', testPlugin3, function(success) {
reg.getKeys(function(keys) {
var testArray = ['t', 't2', 't3'];
test.deepEqual(testArray, keys);

0 comments on commit 060c800

Please sign in to comment.
Something went wrong with that request. Please try again.