Skip to content

Commit

Permalink
fix(render.js): use ADO stream to handle UTF-8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Prcuvu committed Feb 21, 2018
1 parent 3edd85e commit 75999ec
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions render.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
})();

// main
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var objStream = WScript.CreateObject("ADODB.Stream");
var shell = WScript.CreateObject("Wscript.Shell");
var env = shell.Environment("Process");

function Render(filename, params) {
var ForReading = 1;
var templateFile = fso.OpenTextFile(filename + '.template', ForReading);
var input = templateFile.ReadAll();
templateFile.Close();
objStream.Charset = "utf-8";
objStream.Open();
objStream.LoadFromFile(filename + '.template');
var input = objStream.ReadText();
objStream.Close();

var output = input.template(params);
var outputFile = fso.CreateTextFile(filename, true);
outputFile.Write(output);
outputFile.Close();
objStream.Charset = "utf-8";
objStream.Open();
objStream.WriteText(output);
objStream.SaveToFile(filename, 2);
objStream.Close();
}

if (WScript.Arguments.length == 0) {
Expand Down

0 comments on commit 75999ec

Please sign in to comment.