Permalink
Browse files

Implemented layout management.

  • Loading branch information...
1 parent d683dab commit aa4ace5e2e9e20ad03c88a46fd3e5d2a7b1b4eae @pedrofranceschi pedrofranceschi committed Dec 12, 2010
Showing with 111 additions and 2 deletions.
  1. +0 −1 README.markdown
  2. +63 −0 blogode.js
  3. +3 −0 public/stylesheet.css
  4. +2 −1 views/admin/panel.ejs
  5. +42 −0 views/admin/template/index.ejs
  6. +1 −0 views/layout.ejs
View
@@ -18,7 +18,6 @@ TODO
----
* Refactor with Tests
* Add other databases
-* Implement layout management (user view and admin view)
* Implement posts sharing for social networks (Twitter and Facebook)
* Implement plugins API
* Implement statistics
View
@@ -1,5 +1,6 @@
var express = require("express")
var sys = require("sys");
+var fs = require("fs");
var app = express.createServer();
var faye = require('faye');
@@ -155,6 +156,68 @@ app.get('/admin/posts/destroy/:id', adminLoginFilter, function(req, res) {
});
});
+app.get('/admin/template', adminLoginFilter, function(req, res) {
+ // returns the template file editor
+
+ res.render('admin/template/index', {
+ layout: false
+ });
+});
+
+app.get('/admin/template/get_file_content', adminLoginFilter, function(req, res) {
+ // returns a template file content
+
+ var fileToRead = ""
+ if(req.param('file_type') == 'layout') {
+ fileToRead = "./views/layout.ejs";
+ } else if(req.param('file_type') == 'index') {
+ fileToRead = "./views/posts/index.ejs";
+ } else if(req.param('file_type') == "post_show") {
+ fileToRead = "./views/posts/show.ejs";
+ } else if(req.param('file_type') == "stylesheet") {
+ fileToRead = "./public/stylesheet.css";
+ } else {
+ return res.send("File not found.");
+ }
+
+ fs.readFile(fileToRead, function(err, content) {
+ if (err) throw err;
+ return res.send(content);
+ });
+
+});
+
+app.put('/admin/template/set_file_content', adminLoginFilter, function(req, res) {
+ // sets a template file some content
+
+ if(req.param('content') == '' || req.param('content') == undefined) {
+ return res.send("Content can't be blank!");
+ }
+
+ var fileToWrite = ""
+ if(req.param('file_type') == 'layout') {
+ fileToWrite = "./views/layout.ejs";
+ } else if(req.param('file_type') == 'index') {
+ fileToWrite = "./views/posts/index.ejs";
+ } else if(req.param('file_type') == "post_show") {
+ fileToWrite = "./views/posts/show.ejs";
+ } else if(req.param('file_type') == "stylesheet") {
+ fileToWrite = "./public/stylesheet.css";
+ } else {
+ return res.send("File not found.");
+ }
+
+ fs.writeFile(fileToWrite, req.param('content'), function (err) {
+ if (err) throw err;
+ return res.redirect('/admin/template')
+ });
+
+ // fs.readFile(fileToRead, function(err, content) {
+ // return res.send(content);
+ // });
+
+});
+
app.get("/search", function(req, res){
// performs a search for a post
View
@@ -0,0 +1,3 @@
+body {
+ background-color: #FFFFFF;
+}
View
@@ -1,3 +1,4 @@
Admin panel.<br/><br/>
-<a href="/admin/posts">Manage posts</a>
+<a href="/admin/posts">Manage posts</a><br/><br/>
+<a href="/admin/template">Manage template</a>
@@ -0,0 +1,42 @@
+<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
+<script>
+ function updateCurrentEditFile() {
+ $("input[name=\"file_type\"]").val($("select#template_select_list").val());
+ $.get('/admin/template/get_file_content?file_type=' + $("select#template_select_list").val(), function(data) {
+ $('textarea#elm1').text(data);
+ });
+ }
+
+ function updateFileContent() {
+ $.ajax({
+ type: "PUT",
+ url: "/admin/template/set_file_content",
+ data: { content: $("textarea#elm1").val(), file_type: $("input[name=\"file_type\"]").val() },
+ success: function() {
+ }
+ });
+ }
+</script>
+
+<body onLoad="updateCurrentEditFile();">
+
+<h1>Template manager</h1>
+
+File to edit:
+<select id="template_select_list" onChange="updateCurrentEditFile();">
+ <option value="layout">Content template</option>
+ <option value="index">Index</option>
+ <option value="post_show">Post reading</option>
+ <option value="stylesheet">Stylesheet</option>
+</select>
+
+<br/><br/>
+
+Template editor:
+<br/><br/>
+
+<input type="hidden" name="file_type"/>
+<textarea id="elm1" name="content" rows="15" cols="80" style="550px; height:300px;">
+</textarea><br/><br/>
+
+<input type="submit" id="submit" value="Save" onClick="updateFileContent();"/>
View
@@ -3,6 +3,7 @@
<title>Blogode</title>
<script src="/faye.js"></script>
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
+ <link href="/stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>HEADER</h1>

0 comments on commit aa4ace5

Please sign in to comment.