Skip to content

Commit

Permalink
Remove mustache.to_html() (#735)
Browse files Browse the repository at this point in the history
In the spirit of keeping the public API of mustache.js as small as
possible for maintainence reasons, the undocumented and un-tested
`.to_html()` method is removed.

The functionality involved, where it can rather invoke an optional
function provided with the result of `.render()`, instead of returning
it as a string like `.render()` does, is something that using projects
very easily can do themselfs -- it does not have to be provided by
mustache.js.
  • Loading branch information
phillipj authored Jan 15, 2020
1 parent 5938104 commit f3012a2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 31 deletions.
15 changes: 0 additions & 15 deletions mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@
escape: undefined,
parse: undefined,
render: undefined,
to_html: undefined,
Scanner: undefined,
Context: undefined,
Writer: undefined,
Expand Down Expand Up @@ -727,20 +726,6 @@
return defaultWriter.render(template, view, partials, tags);
};

// This is here for backwards compatibility with 0.4.x.,
/*eslint-disable */ // eslint wants camel cased function name
mustache.to_html = function to_html (template, view, partials, send) {
/*eslint-enable*/

var result = mustache.render(template, view, partials);

if (isFunction(send)) {
send(result);
} else {
return result;
}
};

// Export the escaping function so that the user may override it.
// See https://github.com/janl/mustache.js/issues/244
mustache.escape = escapeHtml;
Expand Down
Loading

3 comments on commit f3012a2

@Thorium
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a breaking change for me. Can you provide some migration help, what is the new to_html?
For now, I just revert to old version.

@phillipj
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide some migration help, what is the new to_html?

Absolutely!

First of all, is it important for you to provide a function that will get the rendered output as an argument? Or would it be a viable solution to use const renderedOutput = mustache.render() directly instead?

@phillipj
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If indeed you do indeed have a requirement for a function to be provided the rendered output, that could be implemented in your project as well I assume?

const mustache = require('mustache');

const view = {
  title: "Joe",
  calc: function () {
    return 2 + 4;
  }
};

// pre v4.0
mustache.to_html("{{title}} spends {{calc}}", view, null, function (output) {
  console.log(output);
});


// v4.0 and later
function to_html(template, view, partials, fn) {
  fn(mustache.render(template, view, partials))
}

to_html("{{title}} spends {{calc}}", view, null, function (output) {
  console.log(output);
});

Please sign in to comment.