Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support java javascript engine #32

Open
rmannibucau opened this issue Feb 17, 2016 · 0 comments
Open

support java javascript engine #32

rmannibucau opened this issue Feb 17, 2016 · 0 comments

Comments

@rmannibucau
Copy link

r.js is often used with nashorn but jade plugin doesn't support it yet. This mainly affect fetchText and can be solved adding this detection and impl:

if (typeof Packages !== 'undefined' && typeof java !== 'undefined') {

fetchText = function (url, callback) {
  var stringBuffer, line,
      encoding = "utf-8",
      file = new java.io.File(url),
      lineSeparator = java.lang.System.getProperty("line.separator"),
      input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
      content = '';
  try {
    stringBuffer = new java.lang.StringBuffer();
    line = input.readLine();

    // Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
    // http://www.unicode.org/faq/utf_bom.html

    // Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
    if (line && line.length() && line.charAt(0) === 0xfeff) {
      // Eat the BOM, since we've already found the encoding on this file,
      // and we plan to concatenating this buffer with others; the BOM should
      // only appear at the top of a file.
      line = line.substring(1);
    }

    if (line !== null) {
      stringBuffer.append(line);
    }

    while ((line = input.readLine()) !== null) {
      stringBuffer.append(lineSeparator);
      stringBuffer.append(line);
    }
    //Make sure we return a JavaScript string and not a Java string.
    content = String(stringBuffer.toString()); //String
  } finally {
    input.close();
  }
  callback(content);
};

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant