Skip to content

Commit

Permalink
templify wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Machi committed Sep 30, 2010
1 parent 430055b commit ea3e50b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 50 deletions.
3 changes: 1 addition & 2 deletions lib/app.js
Expand Up @@ -14,8 +14,7 @@ var pageFacets = require("./facet/page"),
User = pinturaConfig.security.getAuthenticationFacet();

// registers the HTML representation handler that generates HTML from wiki content
//require("media/wiki-html");

require("media/wiki-html");
// Defines the data model for the given user by request
pinturaConfig.getDataModel = function(request){
var user = request.remoteUser;
Expand Down
52 changes: 10 additions & 42 deletions lib/media/wiki-html.js
Expand Up @@ -4,51 +4,19 @@

var Media = require("pintura/media").Media,
escapeHTML = require("narwhal/html").escape,
wikiToHtml = require("wiky/wiky").toHtml,
template = require("promised-io/fs").read("templates/wiki.html");

wikiToHtml = require("wiky/wiky").toHtml

Media({
mediaType:"text/html",
getQuality: function(object){
return 0.95;
},
serialize: function(object, parameters, request, response){
var pageName = escapeHTML(decodeURIComponent(request.pathInfo.substring(6)));
var action;
if(response.status === 404){
action = "create";
object = "This page does not exist yet" +
// make sure it shows up on browsers that alternately show "friendly 404's for small responses
" ";
}
else if(response.status === 200){
action = "edit";
}
var content;
if(typeof object === "object"){
content = wikiToHtml(object.content);
}
else{
content = "<p>" + object + "</p>\n";
}
if(action){
action = '<p><a href="/edit.html?page=' + pageName + '">' + action + ' this page</a></p>\n';
}else{
action = '';
}
var props = {
pageName: pageName,
content: content,
action: action,
require("pintura/media/html").setupMediaHandler({
defaultQuality:1,
createContext: function(object, mediaParams, request, response){
return {
pageName: escapeHTML(decodeURIComponent(request.pathInfo.substring(6))),
content: (typeof object=='object')?wikiToHtml(object.content):"<p>"+object+"</p>",
location: response.headers.location
};
return [template.replace(/\$\{(\w+)\}/g, function(t, prop){
return props[prop];
})];
}
}
});

});
var rules = require("wiky/wiky").rules,
store = require("wiky/wiky").store;
// add a rule for [[target page]] style links
Expand Down
18 changes: 13 additions & 5 deletions templates/Error/404
@@ -1,8 +1,16 @@
<html>
<head>
<title>{{$data}} Not Found</title>
</head>
<title>{{pageName}}</title>
<link rel="stylesheet" href="/css/common.css" />
<link rel="stylesheet" href="/css/wikiContent.css" />
<script src="/lib/transporter/receiver.js"></script>
<script src="/lib/monitor.js"></script>
<body>
<h1>Custom 404 Page</h1>
<div id="headerContainer"><span class="pageName">{{pageName}}<span></div>
<div id="content">
<p>This page does not yet exist. Click below to create the page.</p>
</div>
<div id="action">
<a href="/edit.html?page={{pageName}}">Create this page</a>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion templates/Page
Expand Up @@ -7,7 +7,7 @@
<body>
<div id="headerContainer"><span class="pageName">{{pageName}}<span></div>
<div id="content">
<p>{{require("wiky").toHtml(content)}}</p>
<p>{{content}}</p>
</div>
<div id="action">
<a href="/edit.html?page={{pageName}}">Edit this page</a>
Expand Down

0 comments on commit ea3e50b

Please sign in to comment.