Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ The module includes a number of features on top of the standard [text/template](

* [x] [Support for JavaScript snippets in templates](#using-javascript).
* [x] ES5 Support provided by [goja](https://github.com/dop251/goja).
* [x] Built-in support for [underscore.js](http://underscorejs.org/).
* [x] Import JavaScripts scripts from other files and inline JavaScript snippets.
* [x] Modify the templating context from within JavaScript.
* [x] [Controlling the flow of templating within the engine](#controlling-the-flow-of-templating).
Expand Down Expand Up @@ -325,14 +324,6 @@ require("path/to/file.js");

Any functions or variables defined in the imported file will be available in the global scope.

### Using Underscore.js

The [underscore.js](http://underscorejs.org/) library is included by default and can be used in your JavaScript snippets/code.

```js
_.each([1, 2, 3], console.log);
```

### Importing External Javascript Libraries

Using `WithJSFiles` you can import external JavaScript libraries into the global scope. For example:
Expand Down
5 changes: 0 additions & 5 deletions internal/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
esbuild "github.com/evanw/esbuild/pkg/api"

"github.com/speakeasy-api/easytemplate/internal/utils"
"github.com/speakeasy-api/easytemplate/pkg/underscore"
)

var (
Expand Down Expand Up @@ -76,10 +75,6 @@ type program struct {
// New creates a new VM.
func New(randSource RandSource) (*VM, error) {
g := goja.New()
_, err := g.RunString(underscore.JS)
if err != nil {
return nil, utils.HandleJSError("failed to init underscore", err)
}

new(require.Registry).Enable(g)
console.Enable(g)
Expand Down
22 changes: 0 additions & 22 deletions pkg/underscore/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/underscore/underscore-min.js

This file was deleted.

10 changes: 0 additions & 10 deletions pkg/underscore/underscore.go

This file was deleted.

2 changes: 1 addition & 1 deletion testdata/scripts/logeach.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_.each(["a", "b", "c"], (v) => {
["a", "b", "c"].forEach((v) => {
console.log(v);
});
4 changes: 2 additions & 2 deletions testdata/scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require("scripts/include.js");

_.each(["a", "b", "c"], (v) => {
["a", "b", "c"].forEach((v) => {
console.log(v);
});

console.log("Hello easytemplate!");

let values = [1, 2, 3, 4, 5];

let reduced = _.reduce(values, (sum, value) => add(sum, value), 0);
let reduced = values.reduce((sum, value) => add(sum, value), 0);

templateFile("templates/test.stmpl", "test.txt", {
Test: "from test.js",
Expand Down
2 changes: 1 addition & 1 deletion testdata/templates/test4.stmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{.Local.Test}}
```sjs
require("scripts/logeach.js");
_.each(["z", "x", "y"], (v) => {
["z", "x", "y"].forEach((v) => {
console.log(v);
});
sjs```
Loading