diff options
author | Egil Moeller <egil.moller@freecode.no> | 2010-03-25 18:21:35 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2010-03-25 18:21:35 +0100 |
commit | f7dd3aa34cad8a59ad00172339c565731ad80fbb (patch) | |
tree | 89bace287097a264736fa361ec0898bba420c0f8 | |
parent | e411a43b1b217e3d3f893bcbc0c23c6fd4ec0b6d (diff) | |
download | etherpad-f7dd3aa34cad8a59ad00172339c565731ad80fbb.tar.gz etherpad-f7dd3aa34cad8a59ad00172339c565731ad80fbb.tar.xz etherpad-f7dd3aa34cad8a59ad00172339c565731ad80fbb.zip |
Generalized linestylefilter.getURLFilter to a linestylefilter.getRegexpFilter
6 files changed, 178 insertions, 42 deletions
diff --git a/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js b/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js new file mode 100644 index 0000000..bf7c5b7 --- /dev/null +++ b/etherpad/src/plugins/twitterStyleTags/controllers/tagBrowser.js @@ -0,0 +1,57 @@ +/** + * Copyright 2009 RedHog, Egil Möller <egil.moller@piratpartiet.se> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS-IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import("faststatic"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); + +import("etherpad.utils.*"); +import("etherpad.collab.server_utils"); +import("etherpad.globals.*"); +import("etherpad.log"); +import("etherpad.pad.padusers"); +import("etherpad.pro.pro_utils"); +import("etherpad.helpers"); +import("etherpad.pro.pro_accounts.getSessionProAccount"); +import("sqlbase.sqlbase"); +import("sqlbase.sqlcommon"); +import("sqlbase.sqlobj"); + + +function onRequest() { + var isPro = pro_utils.isProDomainRequest(); + var userId = padusers.getUserId(); + + helpers.addClientVars({ + userAgent: request.headers["User-Agent"], + debugEnabled: request.params.djs, + clientIp: request.clientAddr, + colorPalette: COLOR_PALETTE, + serverTimestamp: +(new Date), + isProPad: isPro, + userIsGuest: padusers.isGuest(userId), + userId: userId, + }); + + var isProUser = (isPro && ! padusers.isGuest(userId)); + + renderHtml("tagBrowser.ejs", + { + isPro: isPro, + isProAccountHolder: isProUser, + account: getSessionProAccount(), // may be falsy + }, 'twitterStyleTags'); + return true; +} diff --git a/etherpad/src/plugins/twitterStyleTags/hooks.js b/etherpad/src/plugins/twitterStyleTags/hooks.js new file mode 100644 index 0000000..65aef83 --- /dev/null +++ b/etherpad/src/plugins/twitterStyleTags/hooks.js @@ -0,0 +1,12 @@ +import("etherpad.log"); +import("dispatch.{Dispatcher,PrefixMatcher,forward}"); +import("plugins.twitterStyleTags.controllers.tagBrowser"); + +function aceGetFilterStack() { + log.info("aceGetFilterStack"); + return []; +} + +function handlePath() { + return [[PrefixMatcher('/ep/tags/'), forward(tagBrowser)]]; +} diff --git a/etherpad/src/plugins/twitterStyleTags/main.js b/etherpad/src/plugins/twitterStyleTags/main.js new file mode 100644 index 0000000..686c863 --- /dev/null +++ b/etherpad/src/plugins/twitterStyleTags/main.js @@ -0,0 +1,23 @@ +import("etherpad.log"); +import("plugins.twitterStyleTags.hooks"); +import("plugins.twitterStyleTags.static.js.main"); + +function init() { + this.hooks = ['handlePath']; + this.client = new main.init(); + this.description = 'Twitter-style tags'; + this.handlePath = hooks.handlePath; + this.aceGetFilterStack = hooks.aceGetFilterStack; + + this.install = install; + this.uninstall = uninstall; +} + +function install() { + log.info("Installing Twitter-style tags"); +} + +function uninstall() { + log.info("Uninstalling Twitter-style tags"); +} + diff --git a/etherpad/src/plugins/twitterStyleTags/static/js/main.js b/etherpad/src/plugins/twitterStyleTags/static/js/main.js new file mode 100644 index 0000000..96be013 --- /dev/null +++ b/etherpad/src/plugins/twitterStyleTags/static/js/main.js @@ -0,0 +1,11 @@ +function init() { + this.hooks = ['aceGetFilterStack']; + this.aceGetFilterStack = aceGetFilterStack; +} + +function aceGetFilterStack() { + console.log('aceGetFilterStack'); +} + +/* used on the client side only */ +twitterStyleTags = new init(); diff --git a/etherpad/src/plugins/twitterStyleTags/templates/tagBrowser.ejs b/etherpad/src/plugins/twitterStyleTags/templates/tagBrowser.ejs new file mode 100644 index 0000000..aed5d9b --- /dev/null +++ b/etherpad/src/plugins/twitterStyleTags/templates/tagBrowser.ejs @@ -0,0 +1,28 @@ +<% /* Copyright 2009 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS-IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ %> +<% + helpers.setHtmlTitle("Test plugin"); + helpers.setBodyId("padbody"); + helpers.addBodyClass("limwidth nonpropad nonprouser"); + helpers.includeCss("pad2_ejs.css"); + helpers.setRobotsPolicy({index: false, follow: false}) + helpers.includeJQuery(); + helpers.includeCometJs(); + helpers.includeJs("json2.js"); + helpers.addToHead('\n<style type="text/css" title="dynamicsyntax"></style>\n'); +%> + +<div id="padpage"> + Welcome to the tag browser plugin +</div> diff --git a/infrastructure/ace/www/linestylefilter.js b/infrastructure/ace/www/linestylefilter.js index c493911..71bc30d 100644 --- a/infrastructure/ace/www/linestylefilter.js +++ b/infrastructure/ace/www/linestylefilter.js @@ -140,56 +140,61 @@ linestylefilter.getAtSignSplitterFilter = function(lineText, splitPoints); }; -linestylefilter.REGEX_WORDCHAR = /[\u0030-\u0039\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u1FFF\u3040-\u9FFF\uF900-\uFDFF\uFE70-\uFEFE\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFDC]/; -linestylefilter.REGEX_URLCHAR = new RegExp('('+/[-:@a-zA-Z0-9_.,~%+\/\\?=&#;()$]/.source+'|'+linestylefilter.REGEX_WORDCHAR.source+')'); -linestylefilter.REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source+linestylefilter.REGEX_URLCHAR.source+'*(?![:.,;])'+linestylefilter.REGEX_URLCHAR.source, 'g'); - -linestylefilter.getURLFilter = function(lineText, textAndClassFunc) { - linestylefilter.REGEX_URL.lastIndex = 0; - var urls = null; - var splitPoints = null; - var execResult; - while ((execResult = linestylefilter.REGEX_URL.exec(lineText))) { - if (! urls) { - urls = []; - splitPoints = []; +linestylefilter.getRegexpFilter = function (regExp, tag) { + return function (lineText, textAndClassFunc) { + regExp.lastIndex = 0; + var regExpMatchs = null; + var splitPoints = null; + var execResult; + while ((execResult = regExp.exec(lineText))) { + if (! regExpMatchs) { + regExpMatchs = []; + splitPoints = []; + } + var startIndex = execResult.index; + var regExpMatch = execResult[0]; + regExpMatchs.push([startIndex, regExpMatch]); + splitPoints.push(startIndex, startIndex + regExpMatch.length); } - var startIndex = execResult.index; - var url = execResult[0]; - urls.push([startIndex, url]); - splitPoints.push(startIndex, startIndex + url.length); - } - if (! urls) return textAndClassFunc; + if (! regExpMatchs) return textAndClassFunc; - function urlForIndex(idx) { - for(var k=0; k<urls.length; k++) { - var u = urls[k]; - if (idx >= u[0] && idx < u[0]+u[1].length) { - return u[1]; + function regExpMatchForIndex(idx) { + for(var k=0; k<regExpMatchs.length; k++) { + var u = regExpMatchs[k]; + if (idx >= u[0] && idx < u[0]+u[1].length) { + return u[1]; + } } + return false; } - return false; - } - var handleUrlsAfterSplit = (function() { - var curIndex = 0; - return function(txt, cls) { - var txtlen = txt.length; - var newCls = cls; - var url = urlForIndex(curIndex); - if (url) { - newCls += " url:"+url; - } - textAndClassFunc(txt, newCls); - curIndex += txtlen; - }; - })(); - - return linestylefilter.textAndClassFuncSplitter(handleUrlsAfterSplit, - splitPoints); + var handleRegExpMatchsAfterSplit = (function() { + var curIndex = 0; + return function(txt, cls) { + var txtlen = txt.length; + var newCls = cls; + var regExpMatch = regExpMatchForIndex(curIndex); + if (regExpMatch) { + newCls += " "+tag+":"+regExpMatch; + } + textAndClassFunc(txt, newCls); + curIndex += txtlen; + }; + })(); + + return linestylefilter.textAndClassFuncSplitter(handleRegExpMatchsAfterSplit, + splitPoints); + }; }; + +linestylefilter.REGEX_WORDCHAR = /[\u0030-\u0039\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u1FFF\u3040-\u9FFF\uF900-\uFDFF\uFE70-\uFEFE\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFDC]/; +linestylefilter.REGEX_URLCHAR = new RegExp('('+/[-:@a-zA-Z0-9_.,~%+\/\\?=&#;()$]/.source+'|'+linestylefilter.REGEX_WORDCHAR.source+')'); +linestylefilter.REGEX_URL = new RegExp(/(?:(?:https?|s?ftp|ftps|file|smb|afp|nfs|(x-)?man|gopher|txmt):\/\/|mailto:)/.source+linestylefilter.REGEX_URLCHAR.source+'*(?![:.,;])'+linestylefilter.REGEX_URLCHAR.source, 'g'); +linestylefilter.getURLFilter = linestylefilter.getRegexpFilter( + linestylefilter.REGEX_URL, 'url'); + linestylefilter.textAndClassFuncSplitter = function(func, splitPointsOpt) { var nextPointIndex = 0; var idx = 0; |