https://github.com/breuleux/quaint-javascript
Embed JavaScript in Quaint markup
https://github.com/breuleux/quaint-javascript
evaluator javascript quaint
Last synced: 2 months ago
JSON representation
Embed JavaScript in Quaint markup
- Host: GitHub
- URL: https://github.com/breuleux/quaint-javascript
- Owner: breuleux
- Created: 2015-08-22T03:35:57.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-02T04:04:59.000Z (almost 9 years ago)
- Last Synced: 2025-08-09T13:51:42.957Z (5 months ago)
- Topics: evaluator, javascript, quaint
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
quaint-javascript
=================
Allows inline JavaScript code in
[Quaint](http://breuleux.github.io/quaint)
markup.
Expressions in curly brackets will be evaluated in JavaScript.
## Install
quaint --setup javascript
## Usage
```
2 + 2 is {2 + 2}
```
### API
```javascript
var quaint = require("quaint");
var qjs = require("quaint-javascript");
var q = quaint(qjs);
q.toHTML("2 + 3 = {2 + 3}");
// ==> "2 + 3 = 5"
```
## Functionality
In embedded JavaScript, you can use the `h` function to create HTML
elements programmatically:
```javascript
q.toHTML("{h('a.cls#id', {href: 'there'}, 'A', 'B')}")
// ==> 'AB'
q.toHTML("{[1, 2, 3].map(function (x) { return h('b', x); })}")
// ==> "149"
```
## Options
### `sandbox`
An object to use as the global object for `eval`. All the properties
you set on that object will be available as top level variables in
scripts.
### `transform`
A function to use to preprocess the code before evaluating it. This
could be a compiler, for example.
### `vm`
The module to use for the virtualization (defaults to the standard
`vm` module, so you usally won't have to set it).
The module must implement these two methods:
* **vm.createContext(sandbox)**: "contextify" the object, i.e. make it
into a proper environment for the evaluator. If you implement your
own, you return the sandbox itself, or a copy.
* **vm.runInContext(code, sandbox)**: evaluate the code in the sandbox
returned by `createContext`.