Commits

Anonymous committed fa9577f

Migrated to 0.2.

Comments (0)

Files changed (2)

__main__.js

-
-// Copyright (c) 2010, Anton Korenyushkin
-
-ak.use('ak', '0.1');
-ak.update(this, ak);
-
-
-function init() {
-  db.create('Post',
-            {
-              id: 'unique serial',
-              author: 'string',
-              date: 'date',
-              title: 'string',
-              text: 'string'
-            });
-  db.create('Comment',
-            {
-              id: 'unique serial',
-              post: 'integer -> Post.id',
-              author: 'string',
-              date: 'date',
-              text: 'string'
-            });
-}
-
-
-var IndexHandler = Handler.subclass(
-  {
-    get: function (request) {
-      return render(
-        'index.html',
-        {
-          request: request,
-          authors: rv.Post.all().get({attr: 'author', by: 'author'})
-        });
-    }
-  }).decorated(obtainingSession);
-
-
-var BlogHandler = IndexHandler.subclass(
-  {
-    get: function (request, author) {
-      var posts = rv.Post.where({author: author}).get({by: '-id'});
-      if (!posts.length && request.user != author)
-        throw NotFound(author + ' doesn\'t have a blog');
-      return render('blog.html',
-                    {
-                      request: request,
-                      author: author,
-                      posts: posts
-                    });
-    },
-
-    post: function (request, author) {
-      if (request.user != author)
-        throw Forbidden();
-      if (!request.post.title)
-        throw Failure('Empty title');
-      var post = rv.Post.insert(
-        {
-          author: author,
-          date: new Date(),
-          title: request.post.title,
-          text: request.post.text
-        });
-      return redirect(reverse('post', author, post.id));
-    }
-  });
-
-
-var PostHandler = BlogHandler.subclass(
-  function (request, author, postId) {
-    this._post = rv.Post.where({id: postId}).get()[0];
-    if (!this._post || this._post.author != author)
-      throw NotFound('No such post');
-  },
-  {
-    get: function (request, author, postId) {
-      return render(
-        'post.html',
-        {
-          request: request,
-          post: this._post,
-          comments: rv.Comment.where({post: this._post.id}).get({by: 'id'})
-        });
-    },
-
-    post: function (request, author, postId) {
-      if (!request.user)
-        throw Forbidden('Login first');
-      if (!request.post.text)
-        throw Failure('Empty comment text');
-      rv.Comment.insert(
-        {
-          post: this._post.id,
-          author: request.user,
-          date: new Date(),
-          text: request.post.text
-        });
-      return redirect('.');
-    }
-  });
-
-
-var __root__ = new URLMap(
-  IndexHandler, 'index',
-  ['', BlogHandler, 'blog',
-   [/(\d+)\//, PostHandler, 'post']]);
-
-
-var __main__ = defaultServe;
+
+// Copyright (c) 2010, Anton Korenyushkin
+
+require('ak', '0.2').setup();
+
+
+init = function () {
+  rv.Post.create(
+    {
+      id: 'unique serial',
+      author: 'string',
+      date: 'date',
+      title: 'string',
+      text: 'string'
+    });
+  rv.Comment.create(
+    {
+      id: 'unique serial',
+      post: 'integer -> Post.id',
+      author: 'string',
+      date: 'date',
+      text: 'string'
+    });
+};
+
+
+var IndexHandler = Handler.subclass(
+  {
+    get: function (request) {
+      return render(
+        'index.html',
+        {
+          request: request,
+          authors: rv.Post.all().get({attr: 'author', by: 'author'})
+        });
+    }
+  }).decorated(obtainingSession);
+
+
+var BlogHandler = IndexHandler.subclass(
+  {
+    get: function (request, author) {
+      var posts = rv.Post.where({author: author}).get({by: '-id'});
+      if (!posts.length && request.user != author)
+        throw NotFound(author + ' doesn\'t have a blog');
+      return render('blog.html',
+                    {
+                      request: request,
+                      author: author,
+                      posts: posts
+                    });
+    },
+
+    post: function (request, author) {
+      if (request.user != author)
+        throw Forbidden();
+      if (!request.post.title)
+        throw Failure('Empty title');
+      var post = rv.Post.insert(
+        {
+          author: author,
+          date: new Date(),
+          title: request.post.title,
+          text: request.post.text
+        });
+      return redirect(reverse('post', author, post.id));
+    }
+  });
+
+
+var PostHandler = BlogHandler.subclass(
+  function (request, author, postId) {
+    this._post = rv.Post.where({id: postId}).get()[0];
+    if (!this._post || this._post.author != author)
+      throw NotFound('No such post');
+  },
+  {
+    get: function (request, author, postId) {
+      return render(
+        'post.html',
+        {
+          request: request,
+          post: this._post,
+          comments: rv.Comment.where({post: this._post.id}).get({by: 'id'})
+        });
+    },
+
+    post: function (request, author, postId) {
+      if (!request.user)
+        throw Forbidden('Login first');
+      if (!request.post.text)
+        throw Failure('Empty comment text');
+      rv.Comment.insert(
+        {
+          post: this._post.id,
+          author: request.user,
+          date: new Date(),
+          text: request.post.text
+        });
+      return redirect('.');
+    }
+  });
+
+
+exports.root = new URLMap(
+  IndexHandler, 'index',
+  ['', BlogHandler, 'blog',
+   [/(\d+)\//, PostHandler, 'post']]);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.