Permalink
Browse files

Start to refactor global api into lib/wiki.coffee

  • Loading branch information...
1 parent 54cf482 commit 50ba52ec0c2296022564b3c80f6165bc8581805b @nrn nrn committed Jan 4, 2013
View
1 client/client.coffee
@@ -1,2 +1,3 @@
+window.wiki = require('./lib/wiki')
require('./lib/legacy.coffee')
View
274 client/client.js
@@ -391,11 +391,138 @@ process.binding = function (name) {
});
-require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
- var active, pageHandler, plugin, refresh, resolveLinks, state, util,
+require.define("/lib/wiki.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+ var createSynopsis, wiki,
__slice = [].slice;
- window.wiki = {};
+ createSynopsis = require('./synopsis');
+
+ wiki = {
+ createSynopsis: createSynopsis
+ };
+
+ wiki.log = function() {
+ var things;
+ things = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ if ((typeof console !== "undefined" && console !== null ? console.log : void 0) != null) {
+ return console.log.apply(console, things);
+ }
+ };
+
+ wiki.asSlug = function(name) {
+ return name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase();
+ };
+
+ wiki.useLocalStorage = function() {
+ return $(".login").length > 0;
+ };
+
+ wiki.resolutionContext = [];
+
+ wiki.resolveFrom = function(addition, callback) {
+ wiki.resolutionContext.push(addition);
+ try {
+ return callback();
+ } finally {
+ wiki.resolutionContext.pop();
+ }
+ };
+
+ wiki.getData = function(vis) {
+ var idx, who;
+ if (vis) {
+ idx = $('.item').index(vis);
+ who = $(".item:lt(" + idx + ")").filter('.chart,.data,.calculator').last();
+ if (who != null) {
+ return who.data('item').data;
+ } else {
+ return {};
+ }
+ } else {
+ who = $('.chart,.data,.calculator').last();
+ if (who != null) {
+ return who.data('item').data;
+ } else {
+ return {};
+ }
+ }
+ };
+
+ wiki.getDataNodes = function(vis) {
+ var idx, who;
+ if (vis) {
+ idx = $('.item').index(vis);
+ who = $(".item:lt(" + idx + ")").filter('.chart,.data,.calculator').toArray().reverse();
+ return $(who);
+ } else {
+ who = $('.chart,.data,.calculator').toArray().reverse();
+ return $(who);
+ }
+ };
+
+ wiki.createPage = function(name, loc) {
+ if (loc && loc !== 'view') {
+ return $("<div/>").attr('id', name).attr('data-site', loc).addClass("page");
+ } else {
+ return $("<div/>").attr('id', name).addClass("page");
+ }
+ };
+
+ wiki.getItem = function(element) {
+ if ($(element).length > 0) {
+ return $(element).data("item") || $(element).data('staticItem');
+ }
+ };
+
+ wiki.resolveLinks = function(string) {
+ var renderInternalLink;
+ renderInternalLink = function(match, name) {
+ var slug;
+ slug = wiki.asSlug(name);
+ return "<a class=\"internal\" href=\"/" + slug + ".html\" data-page-name=\"" + slug + "\" title=\"" + (wiki.resolutionContext.join(' => ')) + "\">" + name + "</a>";
+ };
+ return string.replace(/\[\[([^\]]+)\]\]/gi, renderInternalLink).replace(/\[(http.*?) (.*?)\]/gi, "<a class=\"external\" target=\"_blank\" href=\"$1\" title=\"$1\" rel=\"nofollow\">$2 <img src=\"/images/external-link-ltr-icon.png\"></a>");
+ };
+
+ module.exports = wiki;
+
+}).call(this);
+
+});
+
+require.define("/lib/synopsis.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+
+ module.exports = function(page) {
+ var p1, p2, synopsis;
+ synopsis = page.synopsis;
+ if ((page != null) && (page.story != null)) {
+ p1 = page.story[0];
+ p2 = page.story[1];
+ if (p1 && p1.type === 'paragraph') {
+ synopsis || (synopsis = p1.text);
+ }
+ if (p2 && p2.type === 'paragraph') {
+ synopsis || (synopsis = p2.text);
+ }
+ if (p1 && (p1.text != null)) {
+ synopsis || (synopsis = p1.text);
+ }
+ if (p2 && (p2.text != null)) {
+ synopsis || (synopsis = p2.text);
+ }
+ synopsis || (synopsis = (page.story != null) && ("A page with " + page.story.length + " items."));
+ } else {
+ synopsis = 'A page with no story.';
+ }
+ return synopsis;
+ };
+
+}).call(this);
+
+});
+
+require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+ var active, pageHandler, plugin, refresh, state, util;
util = require('./util.coffee');
@@ -409,18 +536,12 @@ require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__
refresh = require('./refresh.coffee');
- require('./dom.coffee');
-
- resolveLinks = wiki.resolveLinks = util.resolveLinks;
-
- wiki.createSynopsis = util.createSynopsis;
-
Array.prototype.last = function() {
return this[this.length - 1];
};
$(function() {
- var $firstPage, LEFTARROW, RIGHTARROW, createTextElement, doInternalLink, finishClick, getItem, getTemplate, resolveFrom, sleep, textEditor, useLocalStorage;
+ var $firstPage, LEFTARROW, RIGHTARROW, createTextElement, doInternalLink, finishClick, getTemplate, sleep, textEditor;
window.dialog = $('<div></div>').html('This dialog will show every time!').dialog({
autoOpen: false,
title: 'Basic Dialog',
@@ -429,28 +550,9 @@ require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__
});
wiki.dialog = function(title, html) {
window.dialog.html(html);
- window.dialog.dialog("option", "title", resolveLinks(title));
+ window.dialog.dialog("option", "title", wiki.resolveLinks(title));
return window.dialog.dialog('open');
};
- wiki.log = function() {
- var things;
- things = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- if ((typeof console !== "undefined" && console !== null ? console.log : void 0) != null) {
- return console.log.apply(console, things);
- }
- };
- wiki.resolutionContext = [];
- resolveFrom = wiki.resolveFrom = function(addition, callback) {
- wiki.resolutionContext.push(addition);
- try {
- return callback();
- } finally {
- wiki.resolutionContext.pop();
- }
- };
- useLocalStorage = wiki.useLocalStorage = function() {
- return $(".login").length > 0;
- };
sleep = function(time, done) {
return setTimeout(done, time);
};
@@ -543,7 +645,7 @@ require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__
if (item.type === 'paragraph') {
sel = util.getSelectionPos(textarea);
if (e.which === $.ui.keyCode.BACKSPACE && sel.start === 0 && sel.start === sel.end) {
- prevItem = getItem(div.prev());
+ prevItem = wiki.getItem(div.prev());
if (prevItem.type !== 'paragraph') {
return false;
}
@@ -583,46 +685,11 @@ require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__
return textarea.focus();
}
};
- getItem = wiki.getItem = function(element) {
- if ($(element).length > 0) {
- return $(element).data("item") || $(element).data('staticItem');
- }
- };
- wiki.getData = function(vis) {
- var idx, who;
- if (vis) {
- idx = $('.item').index(vis);
- who = $(".item:lt(" + idx + ")").filter('.chart,.data,.calculator').last();
- if (who != null) {
- return who.data('item').data;
- } else {
- return {};
- }
- } else {
- who = $('.chart,.data,.calculator').last();
- if (who != null) {
- return who.data('item').data;
- } else {
- return {};
- }
- }
- };
- wiki.getDataNodes = function(vis) {
- var idx, who;
- if (vis) {
- idx = $('.item').index(vis);
- who = $(".item:lt(" + idx + ")").filter('.chart,.data,.calculator').toArray().reverse();
- return $(who);
- } else {
- who = $('.chart,.data,.calculator').toArray().reverse();
- return $(who);
- }
- };
doInternalLink = wiki.doInternalLink = function(name, page, site) {
if (site == null) {
site = null;
}
- name = util.asSlug(name);
+ name = wiki.asSlug(name);
if (page != null) {
$(page).nextAll().remove();
}
@@ -720,7 +787,7 @@ require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__
return finishClick(e, name);
} else {
$page = $(this).parents('.page');
- slug = util.asSlug($page.data('data').title);
+ slug = wiki.asSlug($page.data('data').title);
rev = $(this).parent().children().index($action);
if (!e.shiftKey) {
$page.nextAll().remove();
@@ -732,7 +799,7 @@ require.define("/lib/legacy.coffee",function(require,module,exports,__dirname,__
var item, pageElement, remoteSite;
pageElement = $(e.target).parents('.page');
if (pageElement.hasClass('local')) {
- if (!useLocalStorage()) {
+ if (!wiki.useLocalStorage()) {
item = pageElement.data('data');
pageElement.removeClass('local');
return pageHandler.put(pageElement, {
@@ -809,8 +876,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
module.exports = wiki.util = util = {};
- util.createSynopsis = require('./synopsis');
-
util.symbols = {
create: '',
add: '+',
@@ -820,16 +885,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
remove: ''
};
- util.resolveLinks = function(string) {
- var renderInternalLink;
- renderInternalLink = function(match, name) {
- var slug;
- slug = util.asSlug(name);
- return "<a class=\"internal\" href=\"/" + slug + ".html\" data-page-name=\"" + slug + "\" title=\"" + (wiki.resolutionContext.join(' => ')) + "\">" + name + "</a>";
- };
- return string.replace(/\[\[([^\]]+)\]\]/gi, renderInternalLink).replace(/\[(http.*?) (.*?)\]/gi, "<a class=\"external\" target=\"_blank\" href=\"$1\" title=\"$1\" rel=\"nofollow\">$2 <img src=\"/images/external-link-ltr-icon.png\"></a>");
- };
-
util.randomByte = function() {
return (((1 + Math.random()) * 0x100) | 0).toString(16).substring(1);
};
@@ -898,14 +953,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
return "" + (Math.floor(years)) + " years ago";
};
- util.asSlug = function(name) {
- return name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase();
- };
-
- if (typeof wiki !== "undefined" && wiki !== null) {
- wiki.asSlug = util.asSlug;
- }
-
util.emptyPage = function() {
return {
title: 'empty',
@@ -953,37 +1000,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
});
-require.define("/lib/synopsis.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
-
- module.exports = function(page) {
- var p1, p2, synopsis;
- synopsis = page.synopsis;
- if ((page != null) && (page.story != null)) {
- p1 = page.story[0];
- p2 = page.story[1];
- if (p1 && p1.type === 'paragraph') {
- synopsis || (synopsis = p1.text);
- }
- if (p2 && p2.type === 'paragraph') {
- synopsis || (synopsis = p2.text);
- }
- if (p1 && (p1.text != null)) {
- synopsis || (synopsis = p1.text);
- }
- if (p2 && (p2.text != null)) {
- synopsis || (synopsis = p2.text);
- }
- synopsis || (synopsis = (page.story != null) && ("A page with " + page.story.length + " items."));
- } else {
- synopsis = 'A page with no story.';
- }
- return synopsis;
- };
-
-}).call(this);
-
-});
-
require.define("/lib/pageHandler.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var addToJournal, pageFromLocalStorage, pageHandler, pushToLocal, pushToServer, recursiveGet, revision, state, util;
@@ -2049,8 +2065,6 @@ require.define("/lib/search.coffee",function(require,module,exports,__dirname,__
active = require('./active');
- require('./dom');
-
createSearch = function(_arg) {
var neighborhood, performSearch;
neighborhood = _arg.neighborhood;
@@ -2100,22 +2114,10 @@ require.define("/lib/search.coffee",function(require,module,exports,__dirname,__
});
-require.define("/lib/dom.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
-
- wiki.createPage = function(name, loc) {
- if (loc && loc !== 'view') {
- return $("<div/>").attr('id', name).attr('data-site', loc).addClass("page");
- } else {
- return $("<div/>").attr('id', name).addClass("page");
- }
- };
-
-}).call(this);
-
-});
-
require.define("/client.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+ window.wiki = require('./lib/wiki');
+
require('./lib/legacy.coffee');
}).call(this);
View
24 client/lib/addToJournal.coffee
@@ -0,0 +1,24 @@
+util = require './util'
+
+module.exports = (journalElement, action) ->
+ pageElement = journalElement.parents('.page:first')
+ prev = journalElement.find(".edit[data-id=#{action.id || 0}]") if action.type == 'edit'
+ actionTitle = action.type
+ actionTitle += " #{util.formatElapsedTime(action.date)}" if action.date?
+ actionElement = $("""<a href="#" /> """).addClass("action").addClass(action.type)
+ .text(util.symbols[action.type])
+ .attr('title',actionTitle)
+ .attr('data-id', action.id || "0")
+ .data('action', action)
+ controls = journalElement.children('.control-buttons')
+ if controls.length > 0
+ actionElement.insertBefore(controls)
+ else
+ actionElement.appendTo(journalElement)
+ if action.type == 'fork' and action.site?
+ actionElement
+ .css("background-image", "url(//#{action.site}/favicon.png)")
+ .attr("href", "//#{action.site}/#{pageElement.attr('id')}.html")
+ .data("site", action.site)
+ .data("slug", pageElement.attr('id'))
+
View
5 client/lib/dom.coffee
@@ -1,5 +0,0 @@
-wiki.createPage = (name, loc) ->
- if loc and loc isnt 'view'
- $("<div/>").attr('id', name).attr('data-site', loc).addClass("page")
- else
- $("<div/>").attr('id', name).addClass("page")
View
50 client/lib/legacy.coffee
@@ -1,14 +1,9 @@
-window.wiki = {}
util = require('./util.coffee')
pageHandler = wiki.pageHandler = require('./pageHandler.coffee')
plugin = require('./plugin.coffee')
state = require('./state.coffee')
active = require('./active.coffee')
refresh = require('./refresh.coffee')
-require ('./dom.coffee')
-
-resolveLinks = wiki.resolveLinks = util.resolveLinks
-wiki.createSynopsis = util.createSynopsis
Array::last = ->
this[@length - 1]
@@ -38,25 +33,11 @@ $ ->
.dialog { autoOpen: false, title: 'Basic Dialog', height: 600, width: 800 }
wiki.dialog = (title, html) ->
window.dialog.html html
- window.dialog.dialog "option", "title", resolveLinks(title)
+ window.dialog.dialog "option", "title", wiki.resolveLinks(title)
window.dialog.dialog 'open'
# FUNCTIONS used by plugins and elsewhere
- wiki.log = (things...) ->
- console.log things... if console?.log?
-
- wiki.resolutionContext = []
- resolveFrom = wiki.resolveFrom = (addition, callback) ->
- wiki.resolutionContext.push addition
- try
- callback()
- finally
- wiki.resolutionContext.pop()
-
- useLocalStorage = wiki.useLocalStorage = ->
- $(".login").length > 0
-
sleep = (time, done) -> setTimeout done, time
wiki.removeItem = ($item, item) ->
@@ -121,7 +102,7 @@ $ ->
if item.type is 'paragraph'
sel = util.getSelectionPos(textarea) # position of caret or selected text coords
if e.which is $.ui.keyCode.BACKSPACE and sel.start is 0 and sel.start is sel.end
- prevItem = getItem(div.prev())
+ prevItem = wiki.getItem(div.prev())
return false unless prevItem.type is 'paragraph'
prevTextLen = prevItem.text.length
prevItem.text += textarea.val()
@@ -151,29 +132,8 @@ $ ->
else
textarea.focus()
- getItem = wiki.getItem = (element) ->
- $(element).data("item") or $(element).data('staticItem') if $(element).length > 0
-
- wiki.getData = (vis) ->
- if vis
- idx = $('.item').index(vis)
- who = $(".item:lt(#{idx})").filter('.chart,.data,.calculator').last()
- if who? then who.data('item').data else {}
- else
- who = $('.chart,.data,.calculator').last()
- if who? then who.data('item').data else {}
-
- wiki.getDataNodes = (vis) ->
- if vis
- idx = $('.item').index(vis)
- who = $(".item:lt(#{idx})").filter('.chart,.data,.calculator').toArray().reverse()
- $(who)
- else
- who = $('.chart,.data,.calculator').toArray().reverse()
- $(who)
-
doInternalLink = wiki.doInternalLink = (name, page, site=null) ->
- name = util.asSlug(name)
+ name = wiki.asSlug(name)
$(page).nextAll().remove() if page?
wiki.createPage(name,site)
.appendTo($('.main'))
@@ -257,7 +217,7 @@ $ ->
finishClick e, name
else
$page = $(this).parents('.page')
- slug = util.asSlug($page.data('data').title)
+ slug = wiki.asSlug($page.data('data').title)
rev = $(this).parent().children().index($action)
$page.nextAll().remove() unless e.shiftKey
wiki.createPage("#{slug}_rev#{rev}", $page.data('site'))
@@ -268,7 +228,7 @@ $ ->
.delegate '.fork-page', 'click', (e) ->
pageElement = $(e.target).parents('.page')
if pageElement.hasClass('local')
- unless useLocalStorage()
+ unless wiki.useLocalStorage()
item = pageElement.data('data')
pageElement.removeClass('local')
pageHandler.put pageElement, {type: 'fork', item} # push
View
1 client/lib/search.coffee
@@ -1,6 +1,5 @@
util = require('./util')
active = require('./active')
-require('./dom')
createSearch = ({neighborhood})->
performSearch = (searchQuery)->
View
2 client/lib/synopsis.coffee
@@ -11,4 +11,4 @@ module.exports = (page) ->
else
synopsis = 'A page with no story.'
return synopsis
-
+
View
16 client/lib/util.coffee
@@ -1,7 +1,5 @@
module.exports = wiki.util = util = {}
-util.createSynopsis = require('./synopsis')
-
util.symbols =
create: ''
add: '+'
@@ -10,15 +8,6 @@ util.symbols =
move: ''
remove: ''
-util.resolveLinks = (string) ->
- renderInternalLink = (match, name) ->
- # spaces become 'slugs', non-alpha-num get removed
- slug = util.asSlug name
- "<a class=\"internal\" href=\"/#{slug}.html\" data-page-name=\"#{slug}\" title=\"#{wiki.resolutionContext.join(' => ')}\">#{name}</a>"
- string
- .replace(/\[\[([^\]]+)\]\]/gi, renderInternalLink)
- .replace(/\[(http.*?) (.*?)\]/gi, """<a class="external" target="_blank" href="$1" title="$1" rel="nofollow">$2 <img src="/images/external-link-ltr-icon.png"></a>""")
-
util.randomByte = ->
(((1+Math.random())*0x100)|0).toString(16).substring(1)
@@ -60,11 +49,6 @@ util.formatElapsedTime = (msSinceEpoch) ->
return "#{Math.floor months} months ago" if (years = days/365) < 2
return "#{Math.floor years} years ago"
-util.asSlug = (name) ->
- name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase()
-
-wiki?.asSlug = util.asSlug
-
# DEFAULTS for required fields
util.emptyPage = () ->
View
61 client/lib/wiki.coffee
@@ -0,0 +1,61 @@
+createSynopsis = require './synopsis'
+
+wiki = { createSynopsis }
+
+wiki.log = (things...) ->
+ console.log things... if console?.log?
+
+wiki.asSlug = (name) ->
+ name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase()
+
+
+wiki.useLocalStorage = ->
+ $(".login").length > 0
+
+wiki.resolutionContext = []
+
+wiki.resolveFrom = (addition, callback) ->
+ wiki.resolutionContext.push addition
+ try
+ callback()
+ finally
+ wiki.resolutionContext.pop()
+
+wiki.getData = (vis) ->
+ if vis
+ idx = $('.item').index(vis)
+ who = $(".item:lt(#{idx})").filter('.chart,.data,.calculator').last()
+ if who? then who.data('item').data else {}
+ else
+ who = $('.chart,.data,.calculator').last()
+ if who? then who.data('item').data else {}
+
+wiki.getDataNodes = (vis) ->
+ if vis
+ idx = $('.item').index(vis)
+ who = $(".item:lt(#{idx})").filter('.chart,.data,.calculator').toArray().reverse()
+ $(who)
+ else
+ who = $('.chart,.data,.calculator').toArray().reverse()
+ $(who)
+
+wiki.createPage = (name, loc) ->
+ if loc and loc isnt 'view'
+ $("<div/>").attr('id', name).attr('data-site', loc).addClass("page")
+ else
+ $("<div/>").attr('id', name).addClass("page")
+
+wiki.getItem = (element) ->
+ $(element).data("item") or $(element).data('staticItem') if $(element).length > 0
+
+wiki.resolveLinks = (string) ->
+ renderInternalLink = (match, name) ->
+ # spaces become 'slugs', non-alpha-num get removed
+ slug = wiki.asSlug name
+ "<a class=\"internal\" href=\"/#{slug}.html\" data-page-name=\"#{slug}\" title=\"#{wiki.resolutionContext.join(' => ')}\">#{name}</a>"
+ string
+ .replace(/\[\[([^\]]+)\]\]/gi, renderInternalLink)
+ .replace(/\[(http.*?) (.*?)\]/gi, """<a class="external" target="_blank" href="$1" title="$1" rel="nofollow">$2 <img src="/images/external-link-ltr-icon.png"></a>""")
+
+module.exports = wiki
+
View
343 client/test/testclient.js
@@ -391,13 +391,205 @@ process.binding = function (name) {
});
+require.define("/lib/wiki.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+ var createSynopsis, wiki,
+ __slice = [].slice;
+
+ createSynopsis = require('./synopsis');
+
+ wiki = {
+ createSynopsis: createSynopsis
+ };
+
+ wiki.log = function() {
+ var things;
+ things = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ if ((typeof console !== "undefined" && console !== null ? console.log : void 0) != null) {
+ return console.log.apply(console, things);
+ }
+ };
+
+ wiki.asSlug = function(name) {
+ return name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase();
+ };
+
+ wiki.useLocalStorage = function() {
+ return $(".login").length > 0;
+ };
+
+ wiki.resolutionContext = [];
+
+ wiki.resolveFrom = function(addition, callback) {
+ wiki.resolutionContext.push(addition);
+ try {
+ return callback();
+ } finally {
+ wiki.resolutionContext.pop();
+ }
+ };
+
+ wiki.getData = function(vis) {
+ var idx, who;
+ if (vis) {
+ idx = $('.item').index(vis);
+ who = $(".item:lt(" + idx + ")").filter('.chart,.data,.calculator').last();
+ if (who != null) {
+ return who.data('item').data;
+ } else {
+ return {};
+ }
+ } else {
+ who = $('.chart,.data,.calculator').last();
+ if (who != null) {
+ return who.data('item').data;
+ } else {
+ return {};
+ }
+ }
+ };
+
+ wiki.getDataNodes = function(vis) {
+ var idx, who;
+ if (vis) {
+ idx = $('.item').index(vis);
+ who = $(".item:lt(" + idx + ")").filter('.chart,.data,.calculator').toArray().reverse();
+ return $(who);
+ } else {
+ who = $('.chart,.data,.calculator').toArray().reverse();
+ return $(who);
+ }
+ };
+
+ wiki.createPage = function(name, loc) {
+ if (loc && loc !== 'view') {
+ return $("<div/>").attr('id', name).attr('data-site', loc).addClass("page");
+ } else {
+ return $("<div/>").attr('id', name).addClass("page");
+ }
+ };
+
+ wiki.getItem = function(element) {
+ if ($(element).length > 0) {
+ return $(element).data("item") || $(element).data('staticItem');
+ }
+ };
+
+ wiki.resolveLinks = function(string) {
+ var renderInternalLink;
+ renderInternalLink = function(match, name) {
+ var slug;
+ slug = wiki.asSlug(name);
+ return "<a class=\"internal\" href=\"/" + slug + ".html\" data-page-name=\"" + slug + "\" title=\"" + (wiki.resolutionContext.join(' => ')) + "\">" + name + "</a>";
+ };
+ return string.replace(/\[\[([^\]]+)\]\]/gi, renderInternalLink).replace(/\[(http.*?) (.*?)\]/gi, "<a class=\"external\" target=\"_blank\" href=\"$1\" title=\"$1\" rel=\"nofollow\">$2 <img src=\"/images/external-link-ltr-icon.png\"></a>");
+ };
+
+ module.exports = wiki;
+
+}).call(this);
+
+});
+
+require.define("/lib/synopsis.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+
+ module.exports = function(page) {
+ var p1, p2, synopsis;
+ synopsis = page.synopsis;
+ if ((page != null) && (page.story != null)) {
+ p1 = page.story[0];
+ p2 = page.story[1];
+ if (p1 && p1.type === 'paragraph') {
+ synopsis || (synopsis = p1.text);
+ }
+ if (p2 && p2.type === 'paragraph') {
+ synopsis || (synopsis = p2.text);
+ }
+ if (p1 && (p1.text != null)) {
+ synopsis || (synopsis = p1.text);
+ }
+ if (p2 && (p2.text != null)) {
+ synopsis || (synopsis = p2.text);
+ }
+ synopsis || (synopsis = (page.story != null) && ("A page with " + page.story.length + " items."));
+ } else {
+ synopsis = 'A page with no story.';
+ }
+ return synopsis;
+ };
+
+}).call(this);
+
+});
+
+require.define("/test/util.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
+ var timezoneOffset, util;
+
+ util = require('../lib/util.coffee');
+
+ timezoneOffset = function() {
+ return (new Date(1333843344000)).getTimezoneOffset() * 60;
+ };
+
+ module.exports = describe('util', function() {
+ it('should make random bytes', function() {
+ var a;
+ a = util.randomByte();
+ expect(a).to.be.a('string');
+ return expect(a.length).to.be(2);
+ });
+ it('should make random byte strings', function() {
+ var s;
+ s = util.randomBytes(4);
+ expect(s).to.be.a('string');
+ return expect(s.length).to.be(8);
+ });
+ it('should format unix time', function() {
+ var s;
+ s = util.formatTime(1333843344 + timezoneOffset());
+ return expect(s).to.be('12:02 AM<br>8 Apr 2012');
+ });
+ it('should format javascript time', function() {
+ var s;
+ s = util.formatTime(1333843344000 + timezoneOffset() * 1000);
+ return expect(s).to.be('12:02 AM<br>8 Apr 2012');
+ });
+ it('should format revision date', function() {
+ var s;
+ s = util.formatDate(1333843344000 + timezoneOffset() * 1000);
+ return expect(s).to.be('Sun Apr 8, 2012<br>12:02:24 AM');
+ });
+ it('should slug a name', function() {
+ var s;
+ s = wiki.asSlug('Welcome Visitors');
+ return expect(s).to.be('welcome-visitors');
+ });
+ it('should make emptyPage page with title, story and journal', function() {
+ var page;
+ page = util.emptyPage();
+ expect(page.title).to.be('empty');
+ expect(page.story).to.eql([]);
+ return expect(page.journal).to.eql([]);
+ });
+ return it('should make fresh empty page each call', function() {
+ var page;
+ page = util.emptyPage();
+ page.story.push({
+ type: 'junk'
+ });
+ page = util.emptyPage();
+ return expect(page.story).to.eql([]);
+ });
+ });
+
+}).call(this);
+
+});
+
require.define("/lib/util.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var util;
module.exports = wiki.util = util = {};
- util.createSynopsis = require('./synopsis');
-
util.symbols = {
create: '',
add: '+',
@@ -407,16 +599,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
remove: ''
};
- util.resolveLinks = function(string) {
- var renderInternalLink;
- renderInternalLink = function(match, name) {
- var slug;
- slug = util.asSlug(name);
- return "<a class=\"internal\" href=\"/" + slug + ".html\" data-page-name=\"" + slug + "\" title=\"" + (wiki.resolutionContext.join(' => ')) + "\">" + name + "</a>";
- };
- return string.replace(/\[\[([^\]]+)\]\]/gi, renderInternalLink).replace(/\[(http.*?) (.*?)\]/gi, "<a class=\"external\" target=\"_blank\" href=\"$1\" title=\"$1\" rel=\"nofollow\">$2 <img src=\"/images/external-link-ltr-icon.png\"></a>");
- };
-
util.randomByte = function() {
return (((1 + Math.random()) * 0x100) | 0).toString(16).substring(1);
};
@@ -485,14 +667,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
return "" + (Math.floor(years)) + " years ago";
};
- util.asSlug = function(name) {
- return name.replace(/\s/g, '-').replace(/[^A-Za-z0-9-]/g, '').toLowerCase();
- };
-
- if (typeof wiki !== "undefined" && wiki !== null) {
- wiki.asSlug = util.asSlug;
- }
-
util.emptyPage = function() {
return {
title: 'empty',
@@ -540,101 +714,6 @@ require.define("/lib/util.coffee",function(require,module,exports,__dirname,__fi
});
-require.define("/lib/synopsis.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
-
- module.exports = function(page) {
- var p1, p2, synopsis;
- synopsis = page.synopsis;
- if ((page != null) && (page.story != null)) {
- p1 = page.story[0];
- p2 = page.story[1];
- if (p1 && p1.type === 'paragraph') {
- synopsis || (synopsis = p1.text);
- }
- if (p2 && p2.type === 'paragraph') {
- synopsis || (synopsis = p2.text);
- }
- if (p1 && (p1.text != null)) {
- synopsis || (synopsis = p1.text);
- }
- if (p2 && (p2.text != null)) {
- synopsis || (synopsis = p2.text);
- }
- synopsis || (synopsis = (page.story != null) && ("A page with " + page.story.length + " items."));
- } else {
- synopsis = 'A page with no story.';
- }
- return synopsis;
- };
-
-}).call(this);
-
-});
-
-require.define("/test/util.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
- var timezoneOffset, util;
-
- util = require('../lib/util.coffee');
-
- timezoneOffset = function() {
- return (new Date(1333843344000)).getTimezoneOffset() * 60;
- };
-
- module.exports = describe('util', function() {
- it('should make random bytes', function() {
- var a;
- a = util.randomByte();
- expect(a).to.be.a('string');
- return expect(a.length).to.be(2);
- });
- it('should make random byte strings', function() {
- var s;
- s = util.randomBytes(4);
- expect(s).to.be.a('string');
- return expect(s.length).to.be(8);
- });
- it('should format unix time', function() {
- var s;
- s = util.formatTime(1333843344 + timezoneOffset());
- return expect(s).to.be('12:02 AM<br>8 Apr 2012');
- });
- it('should format javascript time', function() {
- var s;
- s = util.formatTime(1333843344000 + timezoneOffset() * 1000);
- return expect(s).to.be('12:02 AM<br>8 Apr 2012');
- });
- it('should format revision date', function() {
- var s;
- s = util.formatDate(1333843344000 + timezoneOffset() * 1000);
- return expect(s).to.be('Sun Apr 8, 2012<br>12:02:24 AM');
- });
- it('should slug a name', function() {
- var s;
- s = util.asSlug('Welcome Visitors');
- return expect(s).to.be('welcome-visitors');
- });
- it('should make emptyPage page with title, story and journal', function() {
- var page;
- page = util.emptyPage();
- expect(page.title).to.be('empty');
- expect(page.story).to.eql([]);
- return expect(page.journal).to.eql([]);
- });
- return it('should make fresh empty page each call', function() {
- var page;
- page = util.emptyPage();
- page.story.push({
- type: 'junk'
- });
- page = util.emptyPage();
- return expect(page.story).to.eql([]);
- });
- });
-
-}).call(this);
-
-});
-
require.define("/test/active.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var active;
@@ -1924,8 +2003,6 @@ require.define("/lib/search.coffee",function(require,module,exports,__dirname,__
active = require('./active');
- require('./dom');
-
createSearch = function(_arg) {
var neighborhood, performSearch;
neighborhood = _arg.neighborhood;
@@ -1975,20 +2052,6 @@ require.define("/lib/search.coffee",function(require,module,exports,__dirname,__
});
-require.define("/lib/dom.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
-
- wiki.createPage = function(name, loc) {
- if (loc && loc !== 'view') {
- return $("<div/>").attr('id', name).attr('data-site', loc).addClass("page");
- } else {
- return $("<div/>").attr('id', name).addClass("page");
- }
- };
-
-}).call(this);
-
-});
-
require.define("/test/plugin.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
var plugin;
@@ -2874,26 +2937,10 @@ require.define("/plugins/report/report.js",function(require,module,exports,__dir
});
require.define("/testclient.coffee",function(require,module,exports,__dirname,__filename,process,global){(function() {
- var util,
- __slice = [].slice;
mocha.setup('bdd');
- window.wiki = {};
-
- wiki.log = function() {
- var things;
- things = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- if ((typeof console !== "undefined" && console !== null ? console.log : void 0) != null) {
- return console.log(things);
- }
- };
-
- util = require('./lib/util.coffee');
-
- wiki.resolveLinks = util.resolveLinks;
-
- wiki.resolutionContext = ['view'];
+ window.wiki = require('./lib/wiki');
require('./test/util.coffee');
View
2 client/test/util.coffee
@@ -23,7 +23,7 @@ module.exports = describe 'util', ->
s = util.formatDate(1333843344000 + timezoneOffset() * 1000)
expect(s).to.be 'Sun Apr 8, 2012<br>12:02:24 AM'
it 'should slug a name', ->
- s = util.asSlug 'Welcome Visitors'
+ s = wiki.asSlug 'Welcome Visitors'
expect(s).to.be 'welcome-visitors'
it 'should make emptyPage page with title, story and journal', ->
page = util.emptyPage()
View
9 client/testclient.coffee
@@ -1,13 +1,6 @@
mocha.setup('bdd')
-window.wiki = {}
-
-wiki.log = (things...) ->
- console.log things if console?.log?
-
-util = require('./lib/util.coffee')
-wiki.resolveLinks = util.resolveLinks
-wiki.resolutionContext = ['view']
+window.wiki = require('./lib/wiki')
require('./test/util.coffee')
require('./test/active.coffee')

0 comments on commit 50ba52e

Please sign in to comment.