Skip to content

Commit

Permalink
Merge branch 'master' of https://dev.naver.com/git/n4wiki
Browse files Browse the repository at this point in the history
Conflicts:
	lib/gitfs.js
	test/gitfs.test.js
  • Loading branch information
doortts committed Jun 24, 2012
2 parents 6b5fdeb + 26a4396 commit 4cac824
Show file tree
Hide file tree
Showing 14 changed files with 1,365 additions and 1,257 deletions.
12 changes: 12 additions & 0 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,15 @@ task('testWin', function(){
runner.on('fail', function(test){
});
})

desc("mocha test - build coverage report")
task('testCov', function(){
// spawn('mocha', ['-t', '5000', '-R', 'spec', '-u', 'tdd', '--compilers', 'coffee:coffee-script'], {customFds: [0, 1, 2]});
exec('jscoverage --no-highlight lib lib-cov').on('exit', function() {
process.env['LIB_COV'] = 1;
var proc = exec('mocha --colors -t 5000 -R html-cov -u tdd');
proc.on('exit', process.exit);
proc.stdout.pipe(process.stdout, { end: false });
proc.stderr.pipe(process.stderr, { end: false });
});
}, {async: true})
3 changes: 2 additions & 1 deletion app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ noop = ->
process.env.uploadDir = uploadDir = __dirname + '/public/attachment'
WIKINAME = 'note'
ROOT_PATH = '/wikis/' + WIKINAME
API_ROOT_PATH = '/apis/' + WIKINAME

app = express()
server = http.createServer app
Expand Down Expand Up @@ -108,7 +109,7 @@ app.post ROOT_PATH + '/pages', wikiApp.postNew # post new wik
app.del ROOT_PATH + '/pages/:name', wikiApp.postDelete # delete wikipage
app.put ROOT_PATH + '/subscribes/:name', wikiApp.postSubscribe # subscribe wikipage
app.del ROOT_PATH + '/subscribes/:name', wikiApp.postUnsubscribe # unsubscribe wikipage
app.post '/api/note/pages/:name', wikiApp.postRollback # wikipage rollback
app.post API_ROOT_PATH + '/pages/:name', wikiApp.postRollback # wikipage rollback

# Login & Logout
app.post ROOT_PATH + '/users/login', userApp.postLogin # post login
Expand Down
6 changes: 4 additions & 2 deletions doc/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ Coding Convention
```
- 커밋 로그는 아래의 Style을 따릅니다.
- 첫줄은 50자 정도의 요약
- 다음에 공백이 한 줄 오고
- 그 다음에 본문이 옵니다.
- 부연설명이 더 필요한 경우,
- 한 줄을 띄고
- 그 다음에 본문이 옵니다.
- 한 줄의 너비는 72자로 제한합니다.
Achitechture
---
Expand Down
18 changes: 7 additions & 11 deletions lib/gitfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var _ = require('underscore');
var packutil = require('./packutil');
var WritableStream = require('./writablestream').WritableStream;
var jsdiff = require('diff');
var debug = require('debug');
var mkdirp = require('mkdirp');

var NUL = '\u0000';
var REPO_PATH = 'pages.git';
Expand All @@ -31,20 +31,16 @@ var MEMOIZE_ENTITY_MAXSIZE = 40960;

var init = function(repopath, callback) {
REPO_PATH = repopath;
fs.mkdir(REPO_PATH, function(err) {
if (err) {
if (err.code === 'EEXIST') {
return callback(new GitFsError(REPO_PATH + " already exists"));
}

throw err;
} else {
path.exists(REPO_PATH, function(exists) {
if (exists) return callback(new GitFsError(REPO_PATH + " already exists"));
mkdirp(REPO_PATH, function(err) {
if (err) return callback(err);
return async.series([
async.apply(async.map, [REPO_PATH + '/objects', REPO_PATH + '/refs'], fs.mkdir),
async.apply(fs.mkdir, REPO_PATH + '/refs/heads'),
async.apply(fs.writeFile, REPO_PATH + '/HEAD', 'ref: refs/heads/master')
], callback);
}
});
});
};

Expand Down Expand Up @@ -963,4 +959,4 @@ var GitFsError = function(message){
};

GitFsError.prototype = new GitFsError();
GitFsError.prototype.constructor = GitFsError;
GitFsError.prototype.constructor = GitFsError;
110 changes: 20 additions & 90 deletions lib/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ var jsdiff = require('diff');
var nodemailer = require('nodemailer');
var User = require('./users').User;
var async = require('async');
var path = require('path');

var init = function(wikiname, callback) {
var repopath = wikiname + '.pages.git';
var repopath = path.join('notes', wikiname + '.git');
return gitfs.init(repopath, callback);
};

Expand Down Expand Up @@ -50,13 +51,17 @@ var getPage = function(pagename, commitId_) {
var show = function(pagename, commitId, isEqual, callback) {
return gitfs.show(pagename, commitId, function(err, buffer, commit) {
if (err) return callback(err);
var page = {
content: buffer.toString(),
commitId: commitId,
commit: commit,
isOld: !isEqual
};
return callback(err, page);
if (typeof buffer == 'string' || buffer instanceof Buffer) {
var page = {
content: buffer.toString(),
commitId: commitId,
commit: commit,
isOld: !isEqual
};
return callback(err, page);
} else {
return callback(new Error('The file matched given pagename is not a regular file, but maybe a directory.'));
}
});
};

Expand Down Expand Up @@ -208,85 +213,6 @@ var diff = function(name, revSpec_, types_, callback) {
return callback(new Error('At least one revision is required.'));
};

var renderDiff = function(diff, inlineCss) {
var result = '';

diff.forEach(function(seg) {
var attr = '';
if (inlineCss) {
if (seg.added) {
attr = "style = 'background-color: #DFD;'";
} else if (seg.removed) {
attr = "style = 'background-color: #FDD:'";
}
} else {
if (seg.added) {
attr = "class = 'added'";
} else if (seg.removed) {
attr = "class = 'removed'";
}
}
result = _.reduce(
seg.value.split('\n'), function(a, b) {
return a + '<p ' + attr + '>' + b + '</p>';
}, result);
});

return result;
};

/**
* wiki.search 의 검색결과를 HTML로 렌더링한다.
* @param searched wiki.search 의 결과값
* @return result {
* <pagename>: <html>,
* ...,
* }
*/
var renderSearch = function(searched) {
var LIMIT = 120;
var result = {};

Object.keys(searched).forEach(function(name) {
var rendered = '';
var keyword, input, index, begin, end;

matched = searched[name];

if (matched instanceof Array) {
keyword = matched[0];
input = matched.input;
index = matched.index;
begin = Math.max(0, index - Math.floor((LIMIT - keyword.length) / 2));
end = Math.max(begin + LIMIT, begin + keyword.length);

if (begin > 0) {
rendered += '...';
}

rendered +=
input.substr(begin, index - begin) +
'<span class="matched">' + keyword +
'</span>' +
input.substr(index + keyword.length, end - (index + keyword.length));

if (end < input.length) {
rendered += '...';
}
} else {
if (LIMIT < matched.length) {
rendered = matched.substr(0, LIMIT) + '...';
} else {
rendered = matched;
}
}

result[name] = rendered;
});

return result;
};

var search = function(keyword, callback) {
var foundPages = {};

Expand All @@ -297,7 +223,12 @@ var search = function(keyword, callback) {
var matched;

gitfs.readObject(tree[name], function(err, content) {
content = content.toString();
if (typeof content === 'string' || content instanceof Buffer) {
content = content.toString();
} else {
content = '';
}

if (name.match(keyword)) {
foundPages[name] = content;
} else {
Expand Down Expand Up @@ -335,7 +266,6 @@ exports.getHistory = getHistory;
exports.queryHistory = queryHistory;
exports.rollback = rollback;
exports.diff = diff;
exports.renderDiff = renderDiff;
exports.search = search;
exports.renderSearch = renderSearch;
exports.readCommit = readCommit;
exports.getRepoPath = gitfs.getRepoPath;
20 changes: 1 addition & 19 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,7 @@ var i18n = require('../lib/i18n');
*/

exports.index = function(req, res){
res.render('index', {
title: 'N4Wiki',
messages: {
welcome: __('Welcome to %s', 'N4Wiki'),
note: __('Note'),
frontpage: __('frontpage'),
newNote: __('New Note'),
noteList: __('Note List'),
searchNotes: __('Search Notes'),
user: __('User'),
login: __('Login'),
userList: __('User List'),
newUser: __('New User'),
admin: __('Administration'),
sendMail: __('Send mail'),
configureMail: __('Configure mail'),
}

});
res.render('index', {title: 'N4Wiki'});
};

exports.addUserForm = function(req, res){
Expand Down
Loading

0 comments on commit 4cac824

Please sign in to comment.