diff --git a/Makefile b/Makefile index 01f30701..ab720f28 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,20 @@ -doc_dirs = doc $(wildcard doc/*/) -outdoc_dirs = out $(addprefix out/,$(doc_dirs)) doc_sources = $(wildcard doc/*/*.md) $(wildcard doc/*.md) outdoc_files = $(addprefix out/,$(doc_sources:.md=.html)) -docs: $(outdoc_files) +docassets = $(addprefix out/,$(wildcard doc/_assets/*)) + +VERSION = $(shell node -e "console.log( require('./src/package.json').version )") + +docs: $(outdoc_files) $(docassets) + +out/doc/_assets/%: doc/_assets/% + mkdir -p $(@D) + cp $< $@ out/doc/%.html: doc/%.md mkdir -p $(@D) node tools/doc/generate.js --format=html --template=doc/template.html $< > $@ + cat $@ | sed 's/__VERSION__/${VERSION}/' > $@ clean: rm -rf out/ diff --git a/README.plugins b/README.plugins deleted file mode 100644 index 72c45644..00000000 --- a/README.plugins +++ /dev/null @@ -1,16 +0,0 @@ -So, a plugin is an npm package whose name starts with ep_ and that contains a file ep.json -require("ep_etherpad-lite/static/js/plugingfw/plugins").update() will use npm to list all installed modules and read their ep.json files. These will contain registrations for hooks which are loaded -A hook registration is a pairs of a hook name and a function reference (filename for require() plus function name) -require("ep_etherpad-lite/static/js/plugingfw/hooks").callAll("hook_name", {argname:value}) will call all hook functions registered for hook_name -That is the basis. -Ok, so that was a slight simplification: inside ep.json, hook registrations are grouped into groups called "parts". Parts from all plugins are ordered using a topological sort according to "pre" and "post" pointers to other plugins/parts (just like dependencies, but non-installed plugins are silently ignored). -This ordering is honored when you do callAll(hook_name) - hook functions for that hook_name are called in that order -Ordering between plugins is undefined, only parts are ordered. - -A plugin usually has one part, but it van have multiple. -This is so that it can insert some hook registration before that of another plugin, and another one after. -This is important for e.g. registering URL-handlers for the express webserver, if you have some very generic and some very specific url-regexps -So, that's basically it... apart from client-side hooks -which works the same way, but uses a separate member of the part (part.client_hooks vs part.hooks), and where the hook function must obviously reside in a file require():able from the client... -One thing more: The main etherpad tree is actually a plugin itself, called ep_etherpad-lite, and it has it's own ep.json... -was that clear? \ No newline at end of file diff --git a/bin/convert.js b/bin/convert.js index ec792717..4bbdd667 100644 --- a/bin/convert.js +++ b/bin/convert.js @@ -1,9 +1,9 @@ var startTime = new Date().getTime(); var fs = require("fs"); -var ueberDB = require("ueberDB"); -var mysql = require("mysql"); -var async = require("async"); +var ueberDB = require("../src/node_modules/ueberDB"); +var mysql = require("../src/node_modules/ueberDB/node_modules/mysql"); +var async = require("../src/node_modules/async"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; var AttributePool = require("ep_etherpad-lite/static/js/AttributePool"); diff --git a/bin/migrateDirtyDBtoMySQL.js b/bin/migrateDirtyDBtoMySQL.js new file mode 100644 index 00000000..f2bc8efe --- /dev/null +++ b/bin/migrateDirtyDBtoMySQL.js @@ -0,0 +1,11 @@ +var dirty = require("../src/node_modules/ueberDB/node_modules/dirty")('var/dirty.db'); +var db = require("../src/node/db/DB"); + +db.init(function() { + db = db.db; + dirty.on("load", function() { + dirty.forEach(function(key, value) { + db.set(key, value); + }); + }); +}); diff --git a/doc/_assets/style.css b/doc/_assets/style.css new file mode 100644 index 00000000..fe1343af --- /dev/null +++ b/doc/_assets/style.css @@ -0,0 +1,44 @@ +body.apidoc { + width: 60%; + min-width: 10cm; + margin: 0 auto; +} + +#header { + background-color: #5a5; + padding: 10px; + color: #111; +} + +a, +a:active { + color: #272; +} +a:focus, +a:hover { + color: #050; +} + +#apicontent a.mark, +#apicontent a.mark:active { + float: right; + color: #BBB; + font-size: 0.7cm; + text-decoration: none; +} +#apicontent a.mark:focus, +#apicontent a.mark:hover { + color: #AAA; +} + +#apicontent code { + padding: 1px; + background-color: #EEE; + border-radius: 4px; + border: 1px solid #DDD; +} +#apicontent pre>code { + display: block; + overflow: auto; + padding: 5px; +} \ No newline at end of file diff --git a/doc/all.md b/doc/all.md index c0cbf369..f1e071a6 100644 --- a/doc/all.md +++ b/doc/all.md @@ -1,3 +1,4 @@ @include documentation @include api/api +@include plugins @include database diff --git a/doc/api/api.md b/doc/api/api.md index b96fa0c8..eb5bb9c9 100644 --- a/doc/api/api.md +++ b/doc/api/api.md @@ -1,7 +1,8 @@ @include embed_parameters @include http_api -@include hooks +@include hooks_overview @include hooks_client-side @include hooks_server-side @include editorInfo -@include changeset_library \ No newline at end of file +@include changeset_library +@include pluginfw \ No newline at end of file diff --git a/doc/api/hooks.md b/doc/api/hooks_overview.md similarity index 100% rename from doc/api/hooks.md rename to doc/api/hooks_overview.md diff --git a/doc/api/pluginfw.md b/doc/api/pluginfw.md new file mode 100644 index 00000000..2189c74c --- /dev/null +++ b/doc/api/pluginfw.md @@ -0,0 +1,14 @@ +# Plugin Framework +`require("ep_etherpad-lite/static/js/plugingfw/plugins")` + +## plugins.update +`require("ep_etherpad-lite/static/js/plugingfw/plugins").update()` will use npm to list all installed modules and read their ep.json files, registering the contained hooks. +A hook registration is a pairs of a hook name and a function reference (filename for require() plus function name) + +## hooks.callAll +`require("ep_etherpad-lite/static/js/plugingfw/hooks").callAll("hook_name", {argname:value})` will call all hook functions registered for `hook_name` with `{argname:value}`. + +## hooks.aCallAll +? + +## ... diff --git a/doc/plugins.md b/doc/plugins.md new file mode 100644 index 00000000..3717c111 --- /dev/null +++ b/doc/plugins.md @@ -0,0 +1,106 @@ +# Plugins +Etherpad-Lite allows you to extend its functionality with plugins. A plugin registers hooks (functions) for certain events (thus certain features) in Etherpad-lite to execute its own functionality based on these events. + +Publicly available plugins can be found in the npm registry (see ). Etherpad-lite's naming convention for plugins is to prefix your plugins with `ep_`. So, e.g. it's `ep_flubberworms`. Thus you can install plugins from npm, using `npm install ep_flubberworm` in etherpad-lite's root directory. + +You can also browse to `http://yourEtherpadInstan.ce/admin/plugins`, which will list all installed plugins and those available on npm. It even provides functionality to search through all available plugins. + +## Folder structure +A basic plugin usually has the following folder structure: +``` +ep_/ + | static/ + | templates/ + + ep.json + + package.json +``` +If your plugin includes client-side hooks, put them in `static/js/`. If you're adding in CSS or image files, you should put those files in `static/css/ `and `static/image/`, respectively, and templates go into `templates/`. + +A Standard directory structure like this makes it easier to navigate through your code. That said, do note, that this is not actually *required* to make your plugin run. + +## Plugin definition +Your plugin definition goes into `ep.json`. In this file you register your hooks, indicate the parts of your plugin and the order of execution. (A documentation of all available events to hook into can be found in chapter [hooks](#all_hooks).) + +A hook registration is a pairs of a hook name and a function reference (filename to require() + exported function name) + +```json +{ + "parts": [ + { + "name": "nameThisPartHoweverYouWant", + "hooks": { + "authenticate" : "ep_/:FUNCTIONNAME1", + "expressCreateServer": "ep_/:FUNCTIONNAME2" + }, + "client_hooks": { + "acePopulateDOMLine": "ep_plugin/:FUNCTIONNAME3" + } + } + ] +} +``` + +Etherpad-lite will expect the part of the hook definition before the colon to be a javascript file and will try to require it. The part after the colon is expected to be a valid function identifier of that module. So, you have to export your hooks, using [`module.exports`](http://nodejs.org/docs/latest/api/modules.html#modules_modules) and register it in `ep.json` as `ep_/path/to/:FUNCTIONNAME`. +You can omit the `FUNCTIONNAME` part, if the exported function has got the same name as the hook. So `"authorize" : "ep_flubberworm/foo"` will call the function `exports.authorize` in `ep_flubberworm/foo.js` + +### Client hooks and server hooks +There are server hooks, which will be executed on the server (e.g. `expressCreateServer`), and there are client hooks, which are executed on the client (e.g. `acePopulateDomLine`). Be sure to not make assumptions about the environment your code is running in, e.g. don't try to access `process`, if you know your code will be run on the client, and likewise, don't try to access `window` on the server... + +### Parts +As your plugins become more and more complex, you will find yourself in the need to manage dependencies between plugins. E.g. you want the hooks of a certain plugin to be executed before (or after) yours. You can also manage these dependencies in your plugin definition file `ep.json`: + +```javascript +{ + "parts": [ + { + "name": "onepart", + "pre": [], + "post": ["ep_onemoreplugin/partone"] + "hooks": { + "storeBar": "ep_monospace/plugin:storeBar", + "getFoo": "ep_monospace/plugin:getFoo", + } + }, + { + "name": "otherpart", + "pre": ["ep_my_example/somepart", "ep_otherplugin/main"], + "post": [], + "hooks": { + "someEvent": "ep_my_example/otherpart:someEvent", + "another": "ep_my_example/otherpart:another" + } + } + ] +} +``` + +Usually a plugin will add only one functionality at a time, so it will probably only use one `part` definition to register its hooks. However, sometimes you have to put different (unrelated) functionalities into one plugin. For this you will want use parts, so other plugins can depend on them. + +#### pre/post +The `"pre"` and `"post"` definitions, affect the order in which parts of a plugin are executed. This ensures that plugins and their hooks are executed in the correct order. + +`"pre"` lists parts that must be executed *before* the defining part. `"post"` lists parts that must be executed *after* the defining part. + +You can, on a basic level, think of this as double-ended dependency listing. If you have a dependency on another plugin, you can make sure it loads before yours by putting it in `"pre"`. If you are setting up things that might need to be used by a plugin later, you can ensure proper order by putting it in `"post"`. + +Note that it would be far more sane to use `"pre"` in almost any case, but if you want to change config variables for another plugin, or maybe modify its environment, `"post"` could definitely be useful. + +Also, note that dependencies should *also* be listed in your package.json, so they can be `npm install`'d automagically when your plugin gets installed. + +## Package definition +Your plugin must also contain a [package definition file](http://npmjs.org/doc/json.html), called package.json, in the project root - this file contains various metadata relevant to your plugin, such as the name and version number, author, project hompage, contributors, a short description, etc. If you publish your plugin on npm, these metadata are used for package search etc., but it's necessary for Etherpad-lite plugins, even if you don't publish your plugin. + +```json +{ + "name": "ep_PLUGINNAME", + "version": "0.0.1", + "description": "DESCRIPTION", + "author": "USERNAME (REAL NAME) ", + "contributors": [], + "dependencies": {"MODULE": "0.3.20"}, + "engines": { "node": ">= 0.6.0"} +} +``` + +## Templates +If your plugin adds or modifies the front end HTML (e.g. adding buttons or changing their functions), you should put the necessary HTML code for such operations in `templates/`, in files of type ".ejs", since Etherpad-Lite uses EJS for HTML templating. See the following link for more information about EJS: . \ No newline at end of file diff --git a/doc/template.html b/doc/template.html index 2eb93987..6416da94 100644 --- a/doc/template.html +++ b/doc/template.html @@ -2,12 +2,12 @@ - __SECTION__ Etherpad-Lite Manual & Documentation - + __SECTION__ - Etherpad Lite v__VERSION__ Manual & Documentation +
diff --git a/src/node/server.js b/src/node/server.js index b91b0e17..327fa166 100755 --- a/src/node/server.js +++ b/src/node/server.js @@ -21,31 +21,49 @@ * limitations under the License. */ +var log4js = require('log4js') + , async = require('async') + ; + // set up logger -var log4js = require('log4js'); log4js.replaceConsole(); -var settings = require('./utils/Settings'); - -//set loglevel -log4js.setGlobalLogLevel(settings.loglevel); - -var db = require('./db/DB'); -var async = require('async'); -var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); -var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks"); +var settings + , db + , plugins + , hooks; var npm = require("npm/lib/npm.js"); -hooks.plugins = plugins; - async.waterfall([ + // load npm + function(callback) { + npm.load({}, function(er) { + callback(er) + }) + }, + + // load everything + function(callback) { + settings = require('./utils/Settings'); + db = require('./db/DB'); + plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); + hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks"); + hooks.plugins = plugins; + + //set loglevel + log4js.setGlobalLogLevel(settings.loglevel); + callback(); + }, + //initalize the database function (callback) { db.init(callback); }, - plugins.update, + function(callback) { + plugins.update(callback) + }, function (callback) { console.info("Installed plugins: " + plugins.formatPlugins()); diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index dd34ac5e..3d7894d5 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -37,7 +37,7 @@ exports.ip = "0.0.0.0"; /** * The Port ep-lite should listen to */ -exports.port = 9001; +exports.port = process.env.PORT || 9001; /* * The Type of the database */ diff --git a/src/package.json b/src/package.json index 504b88c2..c3c4968a 100644 --- a/src/package.json +++ b/src/package.json @@ -5,9 +5,10 @@ "keywords" : ["etherpad", "realtime", "collaborative", "editor"], "author" : "Peter 'Pita' Martischka - Primary Technology Ltd", "contributors" : [ - { "name": "John McLear", - "name": "Hans Pinckaers", - "name": "Robin Buse" } + { "name": "John McLear" }, + { "name": "Hans Pinckaers" }, + { "name": "Robin Buse" }, + { "name": "Marcel Klehr" } ], "dependencies" : { "yajsml" : "1.1.6", @@ -25,7 +26,8 @@ "log4js" : "0.5.x", "jsdom-nocontextifiy" : "0.2.10", "async-stacktrace" : "0.0.2", - "npm" : "1.1.24", + "npm" : "1.1.x", + "npm-registry-client" : "0.2.10", "ejs" : "0.6.1", "graceful-fs" : "1.1.5", "slide" : "1.1.3", diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 6a75de43..dd4fd1e5 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -311,7 +311,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class ['insertorder', 'first'] ].concat( _.map(state.lineAttributes,function(value,key){ - if (window.console) console.log([key, value]) + if (typeof(window)!= 'undefined' && window.console) console.log([key, value]) return [key, value]; }) ); diff --git a/src/static/js/pluginfw/installer.js b/src/static/js/pluginfw/installer.js index e7c6fb80..d668e549 100644 --- a/src/static/js/pluginfw/installer.js +++ b/src/static/js/pluginfw/installer.js @@ -1,7 +1,12 @@ var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks"); var npm = require("npm"); -var registry = require("npm/lib/utils/npm-registry-client/index.js"); +var RegClient = require("npm-registry-client") + +var registry = new RegClient( +{ registry: "http://registry.npmjs.org" +, cache: npm.cache } +); var withNpm = function (npmfn, final, cb) { npm.load({}, function (er) { @@ -72,7 +77,7 @@ exports.search = function(query, cache, cb) { cb(null, exports.searchCache); } else { registry.get( - "/-/all", null, 600, false, true, + "/-/all", 600, false, true, function (er, data) { if (er) return cb(er); exports.searchCache = data; diff --git a/src/static/js/pluginfw/plugins.js b/src/static/js/pluginfw/plugins.js index 12ba94a2..e02c1331 100644 --- a/src/static/js/pluginfw/plugins.js +++ b/src/static/js/pluginfw/plugins.js @@ -1,7 +1,5 @@ var npm = require("npm/lib/npm.js"); var readInstalled = require("./read-installed.js"); -var relativize = require("npm/lib/utils/relativize.js"); -var readJson = require("npm/lib/utils/read-json.js"); var path = require("path"); var async = require("async"); var fs = require("fs"); diff --git a/src/static/js/pluginfw/read-installed.js b/src/static/js/pluginfw/read-installed.js index cc03b357..800ee32c 100644 --- a/src/static/js/pluginfw/read-installed.js +++ b/src/static/js/pluginfw/read-installed.js @@ -94,8 +94,21 @@ var npm = require("npm/lib/npm.js") , path = require("path") , asyncMap = require("slide").asyncMap , semver = require("semver") - , readJson = require("npm/lib/utils/read-json.js") - , log = require("npm/lib/utils/log.js") + , log = require("log4js").getLogger('pluginfw') + +function readJson(file, callback) { + fs.readFile(file, function(er, buf) { + if(er) { + callback(er); + return; + } + try { + callback( null, JSON.parse(buf.toString()) ) + } catch(er) { + callback(er) + } + }) +} module.exports = readInstalled @@ -274,7 +287,7 @@ function findUnmet (obj) { } }) - log.verbose([obj._id], "returning") + log.debug([obj._id], "returning") return obj } diff --git a/src/templates/index.html b/src/templates/index.html index 4a45d6a5..40d46fc8 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -2,6 +2,29 @@ Etherpad Lite + @@ -9,9 +32,11 @@