diff --git a/rhino_modules/fs/index.js b/rhino_modules/fs/index.js index 11f0dd63..2cc5e18d 100644 --- a/rhino_modules/fs/index.js +++ b/rhino_modules/fs/index.js @@ -1,29 +1,7 @@ -function readFileSync(filename, encoding, callback) { - if (typeof arguments[1] === 'function') { - encoding = null; - callback = arguments[1]; - } - - // TODO: support other encodings - var lines = [], - reader, - input, - s; - - // see http://download.oracle.com/javase/1,5.0/docs/api/java/nio/charset/Charset.html - try { - reader = new java.io.InputStreamReader(new java.io.FileInputStream(filename), 'UTF-8'); - input = new java.io.BufferedReader(reader); - - while( (s = input.readLine()) != null) { - lines.push( new java.lang.String(s.getBytes('UTF-8')) ); - } - - return lines.join('\n'); - } - catch (e) { - throw('Cannot read module file '+filename+', '+e); - } +function readFileSync(filename, encoding) { + encoding = encoding || 'utf-8'; + + return readFile(filename, encoding); } function readdirSync(path) { @@ -149,7 +127,7 @@ function copyFile(inFile, outDir, fileName) { var bos = new Packages.java.io.BufferedOutputStream(new Packages.java.io.FileOutputStream(outFile), 4096); var theChar; while ((theChar = bis.read()) != -1) { - bos.write(theChar); + bos.write(theChar); } bos.close(); bis.close(); @@ -160,26 +138,33 @@ function toFile(path) { return parts.pop(); } -function write(path, content, encoding) { - var output = new java.io.BufferedWriter(new java.io.FileWriter(path)); +function writeFileSync(filename, data, encoding) { + encoding = encoding || 'utf-8'; + + var out = new Packages.java.io.PrintWriter( + new Packages.java.io.OutputStreamWriter( + new Packages.java.io.FileOutputStream(filename), + encoding + ) + ); try { - //FileWriter always assumes default encoding is OK! - output.write( content ); + out.write(data); } finally { - output.close(); + out.flush(); + out.close(); } } module.exports = { readFileSync: readFileSync, + writeFileSync: writeFileSync, readdirSync: readdirSync, stat: stat, ls: ls, mkPath: mkPath, toDir: toDir, - copyFile: copyFile, - write: write + copyFile: copyFile }; \ No newline at end of file diff --git a/templates/default/publish.js b/templates/default/publish.js index 1cf3da0f..2b360c73 100644 --- a/templates/default/publish.js +++ b/templates/default/publish.js @@ -283,7 +283,7 @@ var path = outdir + '/' + filename, html = containerTemplate.call(data, data); - fs.write(path, html, 'UTF-8') + fs.writeFileSync(path, html) } } diff --git a/templates/default/tmpl/container.tmpl b/templates/default/tmpl/container.tmpl index ebe5ab23..8d289a73 100644 --- a/templates/default/tmpl/container.tmpl +++ b/templates/default/tmpl/container.tmpl @@ -1,7 +1,7 @@ - + - + JSDoc: <?js= title ?> diff --git a/test/cases/utf8.js b/test/cases/utf8.js index e69639d0..ec6eea74 100644 --- a/test/cases/utf8.js +++ b/test/cases/utf8.js @@ -1,5 +1,6 @@ /** - * @desc テスト + * @constructor + * @desc Τεκμηρίωση είναι η επικοινωνία! */ -test = function() { +Test = function() { }; \ No newline at end of file diff --git a/test/runner.js b/test/runner.js index 15880813..a20ba5d7 100644 --- a/test/runner.js +++ b/test/runner.js @@ -145,5 +145,20 @@ testFile('test/t/cases/variations.js'); testFile('test/t/cases/versiontag.js'); -report(); +var os = java.lang.System.getProperty('os.name'), + isWin = !!os.startsWith('Windows'); +/** Add codes to display string in color (red) on the console (if OS supports). */ +function red(str) { + if (isWin) { return str; } + else { return '\033[031m' + str + '\033[0m'; } +} + +/** Add codes to display string in color (red) on the console (if OS supports). */ +function green(str) { + if (isWin) { return str; } + else { return '\033[032m' + str + '\033[0m'; } +} + + +report(); \ No newline at end of file