Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit a34318dbb3b9f3d57bed0f842daa8a8daf3cbdda @kriszyp kriszyp committed Apr 21, 2010
@@ -0,0 +1,11 @@
+This is an example Wiki built with Persevere 2.0. It is recommended that you
+use [Nodules](http://github.com/kriszyp/nodules) on Node to run this example so that
+all dependencies will be automatically resolved, or you can also use the nightly
+build that bundles with Narwhal. Once installed, you can download this package and from
+the root folder simply run:
+
+ node /path/to/nodules
+
+or for Narwhal:
+
+ jackup
@@ -0,0 +1 @@
+These are the scripts for running from Narwhal
@@ -0,0 +1,50 @@
+
+if [ -z "${BASH_ARGV[0]}" ]; then
+
+ # as a last recourse, use the present working directory
+ PACKAGE_HOME=$(pwd)
+
+else
+
+ # get the absolute path of the executable
+ SELF_PATH=$(
+ cd -P -- "$(dirname -- "${BASH_ARGV[0]}")" \
+ && pwd -P
+ ) && SELF_PATH=$SELF_PATH/$(basename -- "${BASH_ARGV[0]}")
+
+ # resolve symlinks
+ while [ -h "$SELF_PATH" ]; do
+ DIR=$(dirname -- "$SELF_PATH")
+ SYM=$(readlink -- "$SELF_PATH")
+ SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+ done
+
+ PACKAGE_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")")
+
+fi
+
+export PACKAGE_HOME
+
+# which -s narwhal doesn't work (os x 10.5, kriskowal)
+if [ -f "$PACKAGE_HOME"/bin/narwhal ]; then
+ NARWHAL="$PACKAGE_HOME"/bin/narwhal
+elif [ -f "$PACKAGE_HOME"/packages/narwhal/bin/narwhal ]; then
+ NARWHAL="$PACKAGE_HOME"/packages/narwhal/bin/narwhal
+else
+ env narwhal -e '' >/dev/null 2>&1
+ if [ "$?" -ne 127 ]; then
+ NARWHAL=narwhal
+ else
+ echo "ERROR: narwhal is not in your PATH nor in $PACKAGE_HOME/bin." >&2
+ fi
+fi
+
+if [ -f "$PACKAGE_HOME"/narwhal.conf ]; then
+ source "$PACKAGE_HOME"/narwhal.conf
+ export NARWHAL_DEFAULT_ENGINE
+fi
+
+if [ "$NARWHAL" ]; then
+ export PATH="$("$NARWHAL" --package "$PACKAGE_HOME" --path :)"
+fi
+
@@ -0,0 +1,50 @@
+
+if [ -z "${BASH_ARGV[0]}" ]; then
+
+ # as a last recourse, use the present working directory
+ PACKAGE_HOME=$(pwd)
+
+else
+
+ # get the absolute path of the executable
+ SELF_PATH=$(
+ cd -P -- "$(dirname -- "${BASH_ARGV[0]}")" \
+ && pwd -P
+ ) && SELF_PATH=$SELF_PATH/$(basename -- "${BASH_ARGV[0]}")
+
+ # resolve symlinks
+ while [ -h "$SELF_PATH" ]; do
+ DIR=$(dirname -- "$SELF_PATH")
+ SYM=$(readlink -- "$SELF_PATH")
+ SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+ done
+
+ PACKAGE_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")")
+
+fi
+
+export PACKAGE_HOME
+
+# which -s narwhal doesn't work (os x 10.5, kriskowal)
+if [ -f "$PACKAGE_HOME"/bin/narwhal ]; then
+ NARWHAL="$PACKAGE_HOME"/bin/narwhal
+elif [ -f "$PACKAGE_HOME"/packages/narwhal/bin/narwhal ]; then
+ NARWHAL="$PACKAGE_HOME"/packages/narwhal/bin/narwhal
+else
+ env narwhal -e '' >/dev/null 2>&1
+ if [ "$?" -ne 127 ]; then
+ NARWHAL=narwhal
+ else
+ echo "ERROR: narwhal is not in your PATH nor in $PACKAGE_HOME/bin." >&2
+ fi
+fi
+
+if [ -f "$PACKAGE_HOME"/narwhal.conf ]; then
+ source "$PACKAGE_HOME"/narwhal.conf
+ export NARWHAL_DEFAULT_ENGINE
+fi
+
+if [ "$NARWHAL" ]; then
+ export PATH="$("$NARWHAL" --package "$PACKAGE_HOME" --path :)"
+fi
+
@@ -0,0 +1,3 @@
+@echo off
+
+set PATH=%~dp0;%PATH%
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# this script is intended to work both in narwhal/bin and in
+# any project's bin dir; it's copied by tusk --init.
+
+# get the absolute path of the executable
+SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
+
+# resolve symlinks
+while [ -h "$SELF_PATH" ]; do
+ DIR=$(dirname -- "$SELF_PATH")
+ SYM=$(readlink -- "$SELF_PATH")
+ SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+done
+
+export PACKAGE_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")")
+
+source "$PACKAGE_HOME/bin/activate.bash"
+
+export OLDSEA="$SEA"
+export SEA="$PACKAGE_HOME"
+export SEALVL="$((SEALVL + 1))"
+
+if [ "$#" -lt 1 ]; then
+ echo PATH="$PATH" >&2
+ echo SEA="$SEA" >&2
+ echo SEALVL="$SEALVL" >&2
+ "$SHELL"
+else
+ "$SHELL" -c "$*"
+fi
+if [ "$OLDSEA" != "" ]; then
+ echo SEA="$OLDSEA" >&2
+fi
+echo SEALVL="$((SEALVL - 1))" >&2
+
@@ -0,0 +1,25 @@
+@echo off
+setlocal
+
+set SHELL=cmd.exe
+
+set PACKAGE_HOME=%~dp0\..
+
+call %PACKAGE_HOME%\bin\activate.cmd
+
+set OLDSEA=%SEA%
+set SEA=%PACKAGE_HOME%
+set /a SEALVL=%SEALVL% + 1
+
+if "%1" == "" (
+ echo SEALVL=%SEALVL%
+ echo SEA=%SEA%
+ echo PATH=%PATH%
+ %SHELL%
+) else (
+ %SHELL% %*
+)
+
+set /a SEALVL=%SEALVL% - 1
+echo SEALVL=%SEALVL%
+echo SEA=%OLDSEA%
@@ -0,0 +1 @@
+This is the default location for data files
@@ -0,0 +1,48 @@
+/**
+ * The starting point for Pintura running as a Jack app.
+ */
+try{
+ var pintura = require("pintura/pintura");
+}catch(e){
+ // old loaders need to use this type of access, pintura will fix things from there
+ pintura = require("pintura");
+}
+
+var File = require("file"),
+ transporter = require("pintura/jsgi/transporter");
+
+require("app");
+
+// setup the Jack application
+exports.app =
+ // this will provide module wrapping for the server side CommonJS libraries for the client
+ transporter.Transporter({},
+ // make the root url redirect to /Page/Root
+ require("pintura/jsgi/redirect-root").RedirectRoot(
+ // main Pintura handler
+ pintura.app
+ )
+ );
+
+// now setup the development environment, handle static files before reloading the app
+// for better performance
+exports.development = function(app, options){
+ return require("jack/cascade").Cascade([
+ // cascade from static to pintura REST handling
+/* // this will provide module wrapping for the Dojo modules for the client
+ transporter.Transporter({
+ urlPrefix:"/js/",
+ paths:["../../persevere/public/js/"],
+ converter: transporter.Dojo
+ }),*/
+ // the main place for static files accessible from the web
+ require("jack/static").Static(null, {urls:[""],root:"public"}),
+ // the typical reloader scenario
+ (!options || options.reload) ? require("jack/reloader").Reloader(File.join(File.cwd(), "jackconfig"), "app") :
+ exports.app
+ ]);
+};
+
+// we start the REPL (the interactive JS console) because it is really helpful
+new (require("worker").SharedWorker)("narwhal/repl");
+
@@ -0,0 +1,18 @@
+/**
+ * Defines the capabilities of different users
+ */
+var pageFacets = require("facet/page"),
+ pageChangeFacets = require("facet/page-change"),
+ admins = require("commonjs-utils/settings").admins,
+ Register = require("pintura/security").Register,
+ security = require("pintura/pintura").config.security;
+
+security.getAllowedFacets = function(user, request){
+ if(user){
+ if(admins.indexOf(user.name)>-1){
+ return [pageFacets.AdminFacet, pageChangeFacets.AdminFacet];
+ }
+ return [pageFacets.UserFacet, pageChangeFacets.PublicFacet];
+ }
+ return [pageFacets.PublicFacet, pageChangeFacets.PublicFacet, Register];
+};
@@ -0,0 +1,8 @@
+/**
+ * This is an example Wiki web application written on Pintura
+ */
+
+// registers the HTML representation handler that generates HTML from wiki content
+require("media/wiki-html");
+// Defines the capabilities of the users
+require("access");
@@ -0,0 +1,92 @@
+require("json");
+var pageName = location.search.match(/page=([^&]+)/);
+pageName = pageName && pageName[1];
+document.title = "Editing " + pageName;
+var request = require("commonjs-utils/jsgi-client").request;
+document.getElementById("main-header").innerHTML = escapeHTML("Editing " + pageName);
+request({
+ uri: "Page/" + pageName,
+ headers: {
+ "accept": "application/javascript, application/json"
+ }
+}).then(function(response){
+ if(!response.headers.username){
+ login();
+ }
+ var page = eval("(" + response.body.join("") + ")");
+ if(typeof page !== "object"){
+ page = {
+ id: pageName,
+ content: ""
+ };
+ }
+ var contentArea = document.getElementById("content-area");
+ contentArea.value = page.content;
+
+ document.getElementById("save-button").onclick = function(){
+ page.content = contentArea.value;
+ request({
+ uri: "/Page/" + pageName,
+ method: "PUT",
+ body: JSON.stringify(page),
+ headers: {
+ "accept": "application/javascript, application/json",
+ "content-type": "application/json"
+ }
+ }).then(function(){
+ // redirect to the page once it is saved
+ location = "/Page/" + pageName;
+ }, errorHandler);
+ };
+
+}, errorHandler);
+
+function login(){
+ document.getElementById("login-form").style.display="block";
+ document.getElementById("sign-in").onclick = function(){
+ userRpc("authenticate").then(function(){
+ document.getElementById("login-form").style.display="none";
+ alert("Logged in");
+ }, errorHandler);
+ };
+ document.getElementById("register").onclick = function(){
+ userRpc("createUser").then(function(){
+ alert("Registered");
+ }, errorHandler);
+ };
+}
+
+function userRpc(method, params){
+ return request({
+ uri: "Class/User",
+ method: "POST",
+ body: JSON.stringify({
+ id:"call-id",
+ method: method,
+ params: [
+ document.getElementById("user").value,
+ document.getElementById("password").value
+ ]
+ }),
+ headers: {
+ "accept": "application/javascript, application/json",
+ "content-type": "application/json"
+ }
+ }).then(function(response){
+ response = eval('(' + response.body.join("") + ')');
+ if(response.error){
+ throw response.error;
+ }
+ return response.result;
+ });
+
+}
+
+function errorHandler(error){
+ alert(error);
+}
+
+
+function escapeHTML(html){
+ return html.replace(/&/g, "&")
+ .replace(/</g, "&lt;");
@@ -0,0 +1,26 @@
+/**
+ * These are the page facets for the Wiki example application (in progress)
+ */
+
+var PageChange = require("model/page-change").PageChange,
+ Permissive = require("facet").Permissive,
+ Restrictive = require("facet").Restrictive;
+
+
+// These are the different facets that are available for accessing this data
+// This facet uses the Restrictive constructor, so any modifying action must be explicilty
+// be enabled (by defining a handler)
+exports.PublicFacet = Restrictive(PageChange, {
+ prototype: {
+ },
+ quality:0.5
+
+});
+// note that general users can't change page history
+
+// This facet is for administrators and grants full access to data
+exports.AdminFacet = Permissive(PageChange, {
+ properties: {
+ },
+ quality: 1
+});
Oops, something went wrong. Retry.

0 comments on commit a34318d

Please sign in to comment.