zyne v1.1.3
Zyne Language
Zyne is a templating language that allows you to add plugins that control the behavior and code generation of the language. It has a simple plugin system, so if you wanted to you could write your own plugins that use this language. The easiest target for generation is JavaScript, since it's natively what the language accepts as part of its syntax, including the strings, regular expressions, and numbers. However, you could evaluate and escape the strings, etc for any language of your choice.
Example Usage
Here's an example of a script instance made with Zyne. You can add plugins to it as you like, and then run text on the script instance and get a transpiled result. For this example, we'll be using the RML plugin for Zyne.
// Dependencies for the language and plugins.
const zyne = require('zyne');
const rml = require('zyne-rml');
// Some source code to transpile.
const text = `
// Use the rml plugin.
@rml
// Define a template for the font.
font($size) -> {
// Assign the font size in pixels.
font-size: '\\($size)px'
// Set the font family to sans-serif.
font-family: sans-serif
}
// Use a font with a size of 16 pixels.
font(16)
// Create an h1 element.
h1 => {
// Set the id to header.
id = header
// Make the text aligned to the center.
text-align: center
// Set the color to red.
color: red
// Use a font with a size of 36 pixels.
font(36)
// Add some text to the element.
'Zyne Example'
}
`;
// Generate a JavaScript result from the source text and convert it to HTML.
const js = zyne.runString(text, {rml});
const html = eval(js);
// Log the result to the console.
console.log(html);Execution Methods
runFile(file, plugins)Runs a Zyne file with a set of plugins.runString(source, plugins, file)Runs a Zyne script with a set of plugins and a path.
Plugin Class
The constructor is simply new zyne.Plugin()
set(name, handler)Sets a directive on the plugin. Can be chained.on(name, handler)Adds a handler to the plugin. Can be chained.
The following handlers are available to be used.
init: scriptWhen the script is initialized.exit: scriptWhen the script is exitting.start: scriptWhen the plugin is added.stop: scriptWhen the plugin is removed.element: script, name, function, isBlockTranspiles an element literal.property: script, name, content, isBlockTranspiles a property literal.assignment: script, name, content, isBlockTranspiles a variable assignment literal.variable: script, name, indices, isBlockTranspiles a variable access literal.define: script, name, parameters, blocks, function, isBlockTranspiles a function definition literal.call: script, name, arguments, functions, isBlockTranspiles a function call literal.list: script, items, isBlockTranspiles a list literal.code: script, text, isBlockTranspiles a code block literal.string: script, text, isBlockTranspiles a string literal.identifier: script, text, isBlockTranspiles an identifier literal.number: script, text, isBlockTranspiles a number literal.color: script, text, isBlockTranspiles a color literal.boolean: script, text, isBlockTranspiles a boolean literal.regex: script, text, isBlockTranspiles a regular expression literal.