Skip to content

Commit

Permalink
Switch to using node-config
Browse files Browse the repository at this point in the history
  • Loading branch information
guyht committed Oct 20, 2012
1 parent 1765535 commit 82a1fd0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
7 changes: 6 additions & 1 deletion README.md
@@ -1,5 +1,8 @@
[![Build Status](https://secure.travis-ci.org/guyht/Glog.png)](http://travis-ci.org/guyht/Glog) [![Build Status](https://secure.travis-ci.org/guyht/Glog.png)](http://travis-ci.org/guyht/Glog)


### Upgrading to version 2x
As of version 2, Glog is using the [node-config](https://github.com/lorenwest/node-config) module to handle configuration. While this is a step forward for Glog, allowing you to easily fine tune configuration for your environments, it means that the name and location of the config file has changed. See the configuration section below.

The Glog Blog The Glog Blog
============= =============


Expand Down Expand Up @@ -79,7 +82,9 @@ The entire blog content is parsed and loaded into memory. Whenever a new articl




# Configuration options # Configuration options
These options should be placed in glog_cofig.json and should be valid JSON Glog has recently switched to using [node-config](https://github.com/lorenwest/node-config). This new library makes handling different configuration for different environments a breze. To get you up and running, the following instructions are all you need, but if you would like to setup different configurations for different environments, take a peek at the node-config documentation.

These options should be placed in config/default.json (the default configuration file) and should be valid JSON


blog_repository - The url of the blog repository (e.g. git@github.com:guyht/Guido.git) blog_repository - The url of the blog repository (e.g. git@github.com:guyht/Guido.git)
author - The default blog author (will be used if author is not specified in an individual post) author - The default blog author (will be used if author is not specified in an individual post)
Expand Down
File renamed without changes.
43 changes: 19 additions & 24 deletions lib/glog.js
Expand Up @@ -7,7 +7,8 @@ var path = require('path'),
jade = require('jade'), jade = require('jade'),
exec = require('child_process').exec, exec = require('child_process').exec,
rss = require('rss'), rss = require('rss'),
async = require('async'); async = require('async'),
config = require('config');




/* /*
Expand Down Expand Up @@ -40,35 +41,29 @@ Glog.prototype.load_configs = function(cb) {
fn = this, fn = this,
key; key;


fs.readFile(path.join('glog_config.json'), 'UTF-8', function(err, data) { // Check mandatory configs
if(err) { if(!config.port) {
fn.handle_error('Could not load configuration file. This should be named glog_config.json. Err: ' + err); fn.handle_error('port is not defined in glog_config.json. This should be set to the port number you wish the blog to run on');
} process.exit();

}
var configs = JSON.parse(data);


// Check mandatory configs if(!config.blog_repository) {
if(!configs.port) { fn.handle_error('blog_repository is not defined in glog_config.json. This should point to the git repository of the blog content');
fn.handle_error('port is not defined in glog_config.json. This should be set to the port number you wish the blog to run on'); process.exit();
process.exit(); }
}


if(!configs.blog_repository) { if(!config.author) {
fn.handle_error('blog_repository is not defined in glog_config.json. This should point to the git repository of the blog content'); fn.handle_error('author is not defined in glog_config.json. This should be the default blog author');
process.exit(); process.exit();
} }


if(!configs.author) { for(key in config) {
fn.handle_error('author is not defined in glog_config.json. This should be the default blog author'); options[key] = config[key];
process.exit(); }
}


for(key in configs) { console.log(JSON.stringify(options));
options[key] = configs[key];
}


cb(options); cb(options);
});


} }


Expand Down
31 changes: 16 additions & 15 deletions package.json
@@ -1,17 +1,18 @@
{ {
"name" : "Glog", "name": "Glog",
"version" : "1.3.0", "version": "2.0.0",
"author" : "Guy Halford-Thompson", "author": "Guy Halford-Thompson",
"repository" : "git://github.com/guyht/Glog", "repository": "git://github.com/guyht/Glog",
"dependencies" : { "dependencies": {
"express":"~2", "express": "~2",
"marked" : ">= 0.1.4", "marked": ">= 0.1.4",
"jade" : ">= 0.19.0", "jade": ">= 0.19.0",
"mocha": ">= 0.8.2", "mocha": ">= 0.8.2",
"rss": ">= 0.0.3", "rss": ">= 0.0.3",
"async" : ">= 0.1.22" "async": ">= 0.1.22",
}, "config": "~0.4.17"
"scripts": { },
"test": "make test" "scripts": {
} "test": "make test"
}
} }

0 comments on commit 82a1fd0

Please sign in to comment.