Integrated hooks into templates and provided a blokc/hook for the left and right editbar menu

This commit is contained in:
Egil Moeller 2012-03-13 20:32:56 +01:00
parent 05c2e0fde5
commit a5366a0a16
5 changed files with 83 additions and 57 deletions

View file

@ -25,7 +25,8 @@
"hooks": { "hooks": {
"somehookname": "ep_fintest/otherpart:somehook", "somehookname": "ep_fintest/otherpart:somehook",
"morehook": "ep_fintest/otherpart:morehook", "morehook": "ep_fintest/otherpart:morehook",
"expressCreateServer": "ep_fintest/otherpart:expressServer" "expressCreateServer": "ep_fintest/otherpart:expressServer",
"eejsBlock_editbarMenuLeft": "ep_fintest/otherpart:eejsBlock_editbarMenuLeft"
}, },
"client_hooks": { "client_hooks": {
"somehookname": "ep_fintest/static/js/test:bar" "somehookname": "ep_fintest/static/js/test:bar"

View file

@ -14,3 +14,12 @@ exports.expressServer = function (hook_name, args, cb) {
res.send("<em>Abra cadabra</em>"); res.send("<em>Abra cadabra</em>");
}); });
} }
exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {
args.content = args.content + '\
<li id="testButton" onClick="window.pad&amp;&amp;pad.editbarClick(\'clearauthorship\');return false;">\
<a class="buttonicon buttonicon-test" title="Test test test"></a>\
</li>\
';
return cb();
}

View file

@ -2,4 +2,6 @@
<% e.begin_define_block("foo"); %> <% e.begin_define_block("foo"); %>
YY YY
<% e.super(); %>
ZZ
<% e.end_define_block(); %> <% e.end_define_block(); %>

View file

@ -16,12 +16,13 @@
/* Basic usage: /* Basic usage:
* *
* require("./eejs").require("./examples/foo.ejs") * require("./index").require("./examples/foo.ejs")
*/ */
var ejs = require("ejs"); var ejs = require("ejs");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks.js");
exports.info = { exports.info = {
buf_stack: [], buf_stack: [],
@ -62,17 +63,26 @@ exports.begin_define_block = function (name) {
exports.begin_capture(); exports.begin_capture();
} }
exports.super = function () {
exports.info.buf.push('<!eejs!super!>');
}
exports.end_define_block = function () { exports.end_define_block = function () {
content = exports.end_capture(); content = exports.end_capture();
var name = exports.info.block_stack.pop(); var name = exports.info.block_stack.pop();
if (typeof exports.info.blocks[name].content == "undefined") if (typeof exports.info.blocks[name].content == "undefined")
exports.info.blocks[name].content = content; exports.info.blocks[name].content = content;
else if (typeof exports.info.blocks[name].content.indexOf('<!eejs!super!>'))
exports.info.blocks[name].content = exports.info.blocks[name].content.replace('<!eejs!super!>', content);
return exports.info.blocks[name].content; return exports.info.blocks[name].content;
} }
exports.end_block = function () { exports.end_block = function () {
var res = exports.end_define_block(); var name = exports.info.block_stack[exports.info.block_stack.length-1];
exports.info.buf.push(res); var args = {content: exports.end_define_block()};
hooks.callAll("eejsBlock_" + name, args);
exports.info.buf.push(args.content);
} }
exports.begin_block = exports.begin_define_block; exports.begin_block = exports.begin_define_block;

View file

@ -15,6 +15,7 @@
<div id="editbar"> <div id="editbar">
<ul id="menu_left"> <ul id="menu_left">
<% e.begin_block("editbarMenuLeft"); %>
<li id="bold" onClick="window.pad&amp;&amp;pad.editbarClick('bold');return false"> <li id="bold" onClick="window.pad&amp;&amp;pad.editbarClick('bold');return false">
<a class="buttonicon buttonicon-bold" title="Bold (ctrl-B)"></a> <a class="buttonicon buttonicon-bold" title="Bold (ctrl-B)"></a>
</li> </li>
@ -51,8 +52,10 @@
<li id="clearAuthorship" onClick="window.pad&amp;&amp;pad.editbarClick('clearauthorship');return false;"> <li id="clearAuthorship" onClick="window.pad&amp;&amp;pad.editbarClick('clearauthorship');return false;">
<a class="buttonicon buttonicon-clearauthorship" title="Clear Authorship Colors"></a> <a class="buttonicon buttonicon-clearauthorship" title="Clear Authorship Colors"></a>
</li> </li>
<% e.end_block(); %>
</ul> </ul>
<ul id="menu_right"> <ul id="menu_right">
<% e.begin_block("editbarMenuRight"); %>
<li id="settingslink" onClick="window.pad&amp;&amp;pad.editbarClick('settings');return false;"> <li id="settingslink" onClick="window.pad&amp;&amp;pad.editbarClick('settings');return false;">
<a class="buttonicon buttonicon-settings" id="settingslink" title="Settings of this pad"></a> <a class="buttonicon buttonicon-settings" id="settingslink" title="Settings of this pad"></a>
</li> </li>
@ -70,6 +73,7 @@
<span class="buttonicon buttonicon-showusers" id="usericonback"></span> <span class="buttonicon buttonicon-showusers" id="usericonback"></span>
<span id="online_count">1</span> <span id="online_count">1</span>
</li> </li>
<% e.end_block(); %>
</ul> </ul>
</div> </div>