mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added encoding option.
This commit is contained in:
parent
04bc22c2fa
commit
4820ac398d
2
main.js
2
main.js
@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
sourceFiles = jsdoc.src.getFilePaths(opts._);
|
sourceFiles = jsdoc.src.getFilePaths(opts._);
|
||||||
|
|
||||||
jsdoc.parser.parseFiles(sourceFiles);
|
jsdoc.parser.parseFiles(sourceFiles, opts.encoding);
|
||||||
|
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
var jsonSchema = require('sitepen/jsonSchema');
|
var jsonSchema = require('sitepen/jsonSchema');
|
||||||
|
|||||||
@ -6,31 +6,37 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var slash = java.lang.System.getProperty('file.separator') || '/',
|
var slash = java.lang.System.getProperty('file.separator') || '/',
|
||||||
File = Packages.java.io.File,
|
File = java.io.File,
|
||||||
defaultEncoding = java.lang.System.getProperty('file.encoding');
|
defaultEncoding = java.lang.System.getProperty('file.encoding');
|
||||||
|
|
||||||
exports.read = function(path, options) {
|
exports.read = function(path, encoding) {
|
||||||
var options = options || {},
|
var options = options || {},
|
||||||
encoding = options.encoding || defaultEncoding;
|
encoding = encoding || defaultEncoding,
|
||||||
|
input;
|
||||||
|
print('encoding is '+encoding);
|
||||||
|
input = new java.util.Scanner(
|
||||||
|
new File(path),
|
||||||
|
encoding
|
||||||
|
).useDelimiter("\\Z");
|
||||||
|
|
||||||
return readFile(path, encoding);
|
return String( input.next() );
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.write = function(path, content, options) {
|
exports.write = function(path, content, encoding) {
|
||||||
var options = options || {},
|
var options = options || {},
|
||||||
encoding = options.encoding || defaultEncoding,
|
encoding = encoding || defaultEncoding,
|
||||||
out;
|
output;
|
||||||
|
|
||||||
out = new Packages.java.io.PrintWriter(
|
output = new java.io.PrintWriter(
|
||||||
new Packages.java.io.OutputStreamWriter(
|
new java.io.OutputStreamWriter(
|
||||||
new Packages.java.io.FileOutputStream(path),
|
new java.io.FileOutputStream(path),
|
||||||
encoding
|
encoding
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
out.write(content);
|
output.write(content);
|
||||||
out.flush();
|
output.flush();
|
||||||
out.close();
|
output.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -18,9 +18,10 @@
|
|||||||
destination: 'jsdoc.xml'
|
destination: 'jsdoc.xml'
|
||||||
};
|
};
|
||||||
|
|
||||||
argsParser.addOption('t', 'template', true, 'The name of the template to use.');
|
argsParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template');
|
||||||
|
argsParser.addOption('e', 'encoding', true, 'Assume this encoding when reading all source files. Default: your system default encoding');
|
||||||
argsParser.addOption('T', 'test', false, 'Run unit tests and quit.');
|
argsParser.addOption('T', 'test', false, 'Run unit tests and quit.');
|
||||||
argsParser.addOption('d', 'destination', true, 'The path to output folder.');
|
argsParser.addOption('d', 'destination', true, 'The path to output folder. Default: ./jsdocs');
|
||||||
argsParser.addOption('h', 'help', false, 'Print help message and quit.');
|
argsParser.addOption('h', 'help', false, 'Print help message and quit.');
|
||||||
argsParser.addOption('V', 'validate', false, 'Validate the results produced by parsing the source code.');
|
argsParser.addOption('V', 'validate', false, 'Validate the results produced by parsing the source code.');
|
||||||
|
|
||||||
|
|||||||
@ -125,17 +125,17 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
exports.parseFiles = function(sourceFiles) {
|
exports.parseFiles = function(sourceFiles, encoding) {
|
||||||
var ast = getParser(),
|
var ast = getParser(),
|
||||||
fs = require('common/fs'),
|
fs = require('common/fs'),
|
||||||
source = '';
|
source = '';
|
||||||
|
|
||||||
for (i = 0, leni = sourceFiles.length; i < leni; i++) {
|
for (i = 0, leni = sourceFiles.length; i < leni; i++) {
|
||||||
try {
|
try {
|
||||||
source = fs.read(sourceFiles[i]);
|
source = fs.read(sourceFiles[i], encoding);
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
print('ERROR: ' + e);
|
print('FILE READ ERROR: ' + e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user