Skip to content

Commit

Permalink
Auto fill the title when creating a page, if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio Cicali committed Feb 19, 2013
1 parent a4bc0e7 commit 05ee05d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion jingo
Expand Up @@ -14,7 +14,7 @@ var express = require('express')
, yaml = require("yaml")
, program = require('commander');

program.version('0.2.1')
program.version('0.2.2')
.option('-c, --config <path>', 'Specify the config file')
.option('-s, --sample-config', 'Dumps a config file template and exits')
.parse(process.argv);
Expand Down
27 changes: 24 additions & 3 deletions lib/namer.js
Expand Up @@ -4,18 +4,39 @@ var iconv = new Iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE');

var normalize = function(str) {

if (!str) {
var ret = str;

if (!ret || ret.trim() == "") {
return "";
}

str = iconv.convert(str)
ret = iconv.convert(ret)
.toString()
.replace(/\s/g, '-')
.replace(/\//g, '-')
.replace(/[^a-zA-Z0-9\- _]/g, "")
.toLowerCase();

return str;
return ret;
};

// Not symmetric by any chance, but still better than nothing
var denormalize = function(str) {

var ret = str;

if (!ret || ret.trim() == "") {
return "";
}

ret = ret.replace(/-/g, " ");

ret = ret.replace( /(^|\s)([a-z])/g , function(m,p1,p2) {
return p1+p2.toUpperCase();
});

return ret;
}

exports.normalize = normalize;
exports.denormalize = denormalize;
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "jingo",
"version": "0.2.1",
"description": "A nodejs based wiki engine",
"version": "0.2.2",
"description": "A nodejs based wiki engine (sort of Gollum port)",
"author": "Claudio Cicali <claudio.cicali@gmail.com>",
"main": "jingo",
"bin": {
Expand Down
2 changes: 2 additions & 0 deletions public/js/app.js
Expand Up @@ -13,6 +13,8 @@

var $hCol1 = $('.history td:first-child');

$("#pageTitle").focus();

toggleCompareCheckboxes();
$hCol1.find('input').on('click', function() {
toggleCompareCheckboxes();
Expand Down
3 changes: 2 additions & 1 deletion routes/index.js
Expand Up @@ -147,7 +147,8 @@ exports.pageNew = function(req, res) {
delete req.session.formData;

res.render('create', {
"title": "Create a new page"
"title": "Create a new page",
"pageTitle": Namer.denormalize(res.locals.pageName)
});
}

Expand Down
2 changes: 1 addition & 1 deletion views/create.jade
Expand Up @@ -16,7 +16,7 @@ block content

div
label Page title
input(type='text', name='pageTitle', value="#{coalesce(formData.pageTitle, '')}")#pageTitle
input(type='text', name='pageTitle', value="#{coalesce(formData.pageTitle, pageTitle)}")#pageTitle

div
textarea(name="content", rows=25)#editor #{coalesce(formData.content, '')}
Expand Down

0 comments on commit 05ee05d

Please sign in to comment.