Initial commit, all currently broken.
This commit is contained in:
commit
24ef41ca34
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/keymap/*
|
||||
/lib/*
|
||||
/mode/*
|
||||
/note-data/*
|
||||
index.html
|
46
server.js
Normal file
46
server.js
Normal file
@ -0,0 +1,46 @@
|
||||
var express = require("express");
|
||||
var hbs = require('express-hbs');
|
||||
require('handlebars-form-helpers').register(hbs.handlebars);
|
||||
var bodyParser = require("body-parser");
|
||||
var app = express();
|
||||
var winston = require('winston');
|
||||
winston.add(winston.transports.File, { filename: './logs/notes.kaplon.us.log', maxsize: 5000000 }); // 5MB
|
||||
var fileSystem = require('fs');
|
||||
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: false })); // Not sure if both needed here.
|
||||
|
||||
// Use `.hbs` for extensions and find partials in `views/partials`.
|
||||
app.engine('hbs', hbs.express4({
|
||||
partialsDir: __dirname + '/views/partials'
|
||||
}));
|
||||
app.set('view engine', 'hbs');
|
||||
app.set('views', __dirname + '/views');
|
||||
|
||||
var notePath = __dirname + '/allNotes.txt';
|
||||
|
||||
app.get('/', function(req, res){
|
||||
winston.info("GET /");
|
||||
// Get curent text from allNotes.txt.
|
||||
// How to pass that text into index.html editor control??? Still need Handlebars???
|
||||
// i may be grokking it...need to keep handlebars, though.
|
||||
// read contents of allNotes.txt into a variable.
|
||||
// pass that variable as data to handlebars template, {{notetxt}}.
|
||||
res.render('index', {notetxt: noteTxt}, function(err, html) {
|
||||
if(err !== null) {
|
||||
winston.error(err);
|
||||
} else {
|
||||
res.send(html);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.post('/', function(req, res){
|
||||
winston.info(req.body);
|
||||
// Stage and commit changes to allNotes.txt.
|
||||
res.status(204).send('POST received');
|
||||
});
|
||||
|
||||
app.listen(3000, function() {
|
||||
winston.info("Started on PORT 3000");
|
||||
});
|
43
views/index.hbs
Normal file
43
views/index.hbs
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Jody's CodeMirror</title>
|
||||
<link rel="stylesheet" href="lib/codemirror.css">
|
||||
<script src="lib/codemirror.js"></script>
|
||||
<script src="mode/markdown/markdown.js"></script>
|
||||
<script src="keymap/vim.js"></script>
|
||||
<style type="text/css">
|
||||
.CodeMirror {
|
||||
border: 1px solid #eee;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form><textarea id="editor" name="editor">
|
||||
{{notetxt}}
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
|
||||
mode: "markdown",
|
||||
lineNumbers: "true",
|
||||
keyMap: "vim",
|
||||
viewportMargin: Infinity
|
||||
});
|
||||
|
||||
var typingTimer;
|
||||
editor.on("changes", function() {
|
||||
//console.log("changes fired");
|
||||
clearTimeout(typingTimer);
|
||||
typingTimer = setTimeout(
|
||||
function() {
|
||||
alert("saved now!");
|
||||
},
|
||||
2000
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user