Skip to content
Browse files

Implemented some local variables to theme designers.

  • Loading branch information...
1 parent 1d07b5a commit 492d411f5d24a681fe42ee25ce87bf0e65d4f86d @pedrofranceschi pedrofranceschi committed Dec 12, 2010
Showing with 63 additions and 32 deletions.
  1. +17 −0 blogode.js
  2. +1 −1 config/blog.json
  3. +11 −0 lib/config.js
  4. +32 −29 lib/posts.js
  5. +1 −1 views/layout.ejs
  6. +1 −1 views/posts/index.ejs
View
17 blogode.js
@@ -9,6 +9,11 @@ var users = require('./lib/users');
var comments = require('./lib/comments');
var config = require('./lib/config');
+var blogConfig;
+config.getAllBlogConfigKeyValues(function(value) {
+ blogConfig = value;
+});
+
app.configure(function() {
app.use(express.logger());
app.use(express.bodyDecoder());
@@ -23,6 +28,18 @@ app.configure(function() {
});
});
+app.dynamicHelpers({
+ blogName: function(){
+ return blogConfig['blog_name'];
+ },
+ blogAddress: function(){
+ return blogConfig['blog_address'];
+ },
+ blogDescription: function(){
+ return blogConfig['blog_description'];
+ }
+});
+
bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
View
2 config/blog.json
@@ -1 +1 @@
-{"current_template":"default_theme","blog_name":"Blogode"}
+{"current_template":"default_theme","blog_name":"Blogode","blog_address":"http://0.0.0.0:3000/","blog_description":"A Lorem Ipsum Blog!"}
View
11 lib/config.js
@@ -12,6 +12,17 @@ exports.getBlogConfigKeyValue = function(key, callback) {
});
}
+exports.getAllBlogConfigKeyValues = function(callback) {
+ fs.readFile('./config/blog.json', function(err, content) {
+ if(err) {
+ throw err;
+ } else {
+ var configParser = JSON.parse(content);
+ callback(configParser);
+ }
+ });
+}
+
exports.setBlogConfigKeyValue = function(key, value, callback) {
fs.readFile('./config/blog.json', function(err, content) {
if(err) {
View
61 lib/posts.js
@@ -1,4 +1,5 @@
var sys = require('sys'),
+ config = require('./config.js'),
database = require('./database.js');
database.initialize();
@@ -125,33 +126,35 @@ exports.destroyPost = function(id, callback) {
exports.generatePostsXML = function(jsonObject, callback) {
- var unescapedXML = '' +
- '<?xml version="1.0" ?>' +
- '<rss version="2.0">' +
- ' <channel>' +
- ' <title>The Blog Name</title>' +
- ' <link>http://0.0.0.0:3000/</link>' +
- ' <description>The Blog Description</description>' +
- ' <image>' +
- ' <url>http://www.xul.fr/xul-icon.gif</url>' +
- ' <link>http://www.xul.fr/en/index.php</link>' +
- ' </image>';
-
- for (var i=0; i < jsonObject.length; i++) {
- var thisObject = jsonObject[i];
- unescapedXML += '' +
- '<item>' +
- ' <title>' + unescape(thisObject.title) + '</title>' +
- ' <link>/' + unescape(thisObject.id) + '</link>' +
- ' <author>' + thisObject.user_name + '</author>' +
- ' <pubDate>' + thisObject.created_at + '</pubDate>' +
- ' <description>' + unescape(thisObject.body) + '</description>' +
- '</item>';
- }
-
- unescapedXML += '' +
- '</channel>' +
- '</rss>';
-
- callback(unescapedXML);
+ config.getAllBlogConfigKeyValues(function(value) {
+ var unescapedXML = '' +
+ '<?xml version="1.0" ?>' +
+ '<rss version="2.0">' +
+ ' <channel>' +
+ ' <title>' + value['blog_name'] + '</title>' +
+ ' <link>' + value['blog_address'] + '</link>' +
+ ' <description>' + value['blog_description'] + '</description>' +
+ ' <image>' +
+ ' <url>http://www.xul.fr/xul-icon.gif</url>' +
+ ' <link>http://www.xul.fr/en/index.php</link>' +
+ ' </image>';
+
+ for (var i=0; i < jsonObject.length; i++) {
+ var thisObject = jsonObject[i];
+ unescapedXML += '' +
+ '<item>' +
+ ' <title>' + unescape(thisObject.title) + '</title>' +
+ ' <link>/' + unescape(thisObject.id) + '</link>' +
+ ' <author>' + thisObject.user_name + '</author>' +
+ ' <pubDate>' + thisObject.created_at + '</pubDate>' +
+ ' <description>' + unescape(thisObject.body) + '</description>' +
+ '</item>';
+ }
+
+ unescapedXML += '' +
+ '</channel>' +
+ '</rss>';
+
+ callback(unescapedXML);
+ });
}
View
2 views/layout.ejs
@@ -1,6 +1,6 @@
<html>
<head>
- <title>Blogode</title>
+ <title><%= blogName %></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" />
View
2 views/posts/index.ejs
@@ -1,4 +1,4 @@
-<link rel="alternate" type="application/rss+xml" title="My Blog Name's RSS" href="/feed" />
+<link rel="alternate" type="application/rss+xml" title="<%= blogName %>" href="/feed" />
<% if(posts != undefined) { %>
<% for (var i=0; i < posts.length; i++) { %>

0 comments on commit 492d411

Please sign in to comment.
Something went wrong with that request. Please try again.