Permalink
Browse files

Auto fill the title when creating a page, if possible

  • Loading branch information...
1 parent a4bc0e7 commit 05ee05d713fae349cea8328bec925a1a6be973e6 Claudio Cicali committed Feb 19, 2013
Showing with 32 additions and 8 deletions.
  1. +1 −1 jingo
  2. +24 −3 lib/namer.js
  3. +2 −2 package.json
  4. +2 −0 public/js/app.js
  5. +2 −1 routes/index.js
  6. +1 −1 views/create.jade
View
2 jingo
@@ -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);
View
@@ -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;
View
@@ -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": {
View
@@ -13,6 +13,8 @@
var $hCol1 = $('.history td:first-child');
+ $("#pageTitle").focus();
+
toggleCompareCheckboxes();
$hCol1.find('input').on('click', function() {
toggleCompareCheckboxes();
View
@@ -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)
});
}
View
@@ -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, '')}

0 comments on commit 05ee05d

Please sign in to comment.