Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When editing a template file, the original template will be edited too.

  • Loading branch information...
commit 1d07b5a0d93fb81e43d21b3b201c1acc961c4cac 1 parent b44e75a
@pedrofranceschi pedrofranceschi authored
Showing with 40 additions and 23 deletions.
  1. +31 −19 blogode.js
  2. +1 −1  config/blog.json
  3. +8 −3 views/admin/template/index.ejs
View
50 blogode.js
@@ -4,6 +4,11 @@ var fs = require("fs");
var app = express.createServer();
var faye = require('faye');
+var posts = require('./lib/posts');
+var users = require('./lib/users');
+var comments = require('./lib/comments');
+var config = require('./lib/config');
+
app.configure(function() {
app.use(express.logger());
app.use(express.bodyDecoder());
@@ -23,11 +28,6 @@ bayeux = new faye.NodeAdapter({
timeout: 45
});
-var posts = require('./lib/posts');
-var users = require('./lib/users');
-var comments = require('./lib/comments');
-var config = require('./lib/config');
-
app.get("/", function(req, res){
// return posts list
@@ -216,21 +216,33 @@ app.put('/admin/template/set_file_content', adminLoginFilter, function(req, res)
}
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.");
- }
+ var templateFileToWrite = ""
+
+ config.getBlogConfigKeyValue('current_template', function(value) {
+ if(req.param('file_type') == 'layout') {
+ fileToWrite = "./views/layout.ejs";
+ templateFileToWrite = "./public/templates/" + value + "/layout.html"
+ } else if(req.param('file_type') == 'index') {
+ fileToWrite = "./views/posts/index.ejs";
+ templateFileToWrite = "./public/templates/" + value + "/posts/index.html"
+ } else if(req.param('file_type') == "post_show") {
+ fileToWrite = "./views/posts/show.ejs";
+ templateFileToWrite = "./public/templates/" + value + "/posts/show.html"
+ } else if(req.param('file_type') == "stylesheet") {
+ fileToWrite = "./public/stylesheet.css";
+ templateFileToWrite = "./public/templates/" + value + "/stylesheet.css"
+ } else {
+ return res.send("File not found.");
+ }
+
+ fs.writeFile(fileToWrite, req.param('content'), function (err) {
+ if (err) throw err;
+ fs.writeFile(templateFileToWrite, req.param('content'), function (err) {
+ if (err) throw err;
+ return res.redirect('/admin/template')
+ });
+ });
- fs.writeFile(fileToWrite, req.param('content'), function (err) {
- if (err) throw err;
- return res.redirect('/admin/template')
});
});
View
2  config/blog.json
@@ -1 +1 @@
-{"current_template":"default_theme"}
+{"current_template":"default_theme","blog_name":"Blogode"}
View
11 views/admin/template/index.ejs
@@ -16,15 +16,20 @@
}
});
}
+
+ function changeTemplate() {
+ $('#change_template_form').submit();
+ }
+
</script>
<body onLoad="updateCurrentEditFile();">
<h1>Template manager</h1>
-<form method="post" action="/admin/template/apply_template">
+<form method="post" action="/admin/template/apply_template" id="change_template_form">
Change theme:
- <select id="template_select_list" name="name">
+ <select id="template_select_list" name="name" onChange="changeTemplate();">
<% for (var i=0; i < template_infos.length; i++) { %>
<option value="<%= template_infos[i].template_folder_name %>"
@@ -35,7 +40,7 @@
><%= template_infos[i].template_name %></option>
<% } %>
</select>
- <input type="submit" value="Apply">
+ <!-- <input type="submit" value="Apply"> -->
</form>
File to edit:
Please sign in to comment.
Something went wrong with that request. Please try again.