├── package.json └── README.md /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-tesl", 3 | "version": "0.0.1", 4 | "description": "Collection of Tesl libraries", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/are1000/hello-tesl.git" 12 | }, 13 | "author": "Artur Wojciechowski ", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/are1000/hello-tesl/issues" 17 | }, 18 | "homepage": "https://github.com/are1000/hello-tesl#readme" 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hello Tesl 2 | Hello Tesl is a bunch of libraries created as an important addition to Tesl language engine. It's not necessary for Tesl to work, but it's a good start if you are new to the language. 3 | 4 | ## Included libraries 5 | ### v2 6 | `v2` is a library that holds the most important functions that you will use, i.e. `fun` for function declaration, `def` for defining variables and `import`/`export` for importing files. 7 | 8 | It requires a little setup before you can use it - Tesl doesn't care if you run it through `node.js` or `webpack`, but it needs a way to get contents of imported files or parse the files. 9 | 10 | This is the preferred way of setting up `v2` (in this example using `webpack`): 11 | ```js 12 | const { Tesl } = require('tesl') 13 | const { createV2, web } = require('hello-tesl') 14 | 15 | const input = require('./src/index.tesl') 16 | // You can also write this if in node environment: 17 | // const fs = require('fs') 18 | // const input = fs.readFile('./src/index.tesl') 19 | 20 | function createContext() { 21 | const tesl = new Tesl() 22 | 23 | tesl.provide('v2', createV2(function (filename) { 24 | return require(`./src/${filename}.tesl`) 25 | // Same as above, you can use fs.readFile or whatever other method to get the desired file 26 | }, createContext)) 27 | 28 | tesl.provide('web', web) 29 | 30 | return tesl 31 | } 32 | 33 | let ctx = createContext() 34 | ctx.execute(input) 35 | 36 | ``` 37 | ### web 38 | `web` is a library that is dependent on a browser environment and provides a way to access DOM, create HTML elements or attributes. It also exposes `prog` command, which really simplifies the process of creating SPAs or widgets embedded in other frameworks. 39 | 40 | ```clojure 41 | (. 42 | (prog.dispatcher ; here we define our actions 43 | :changeText (fun [state:object dispatch:function text:string]:void 44 | '(@ state :key text) 45 | ) 46 | ) 47 | (prog "#app" ; this is a selector of the element we want to inject our app into 48 | (data.object ; here we declare our model 49 | :key "hello" 50 | ) 51 | 52 | '(html.div (state :key) " world!" ; and here we declare our view 53 | (html.button "say goodbye!" 54 | (dom.listen :click (dispatch :changeText "bye")) 55 | ) 56 | ) 57 | ) 58 | ) 59 | ``` 60 | 61 | Every time we update `state`, view rerenders automatically the portions of the dom that changed (using `virtual-dom` library). 62 | 63 | ### data 64 | `data` contains necessary functions to manipulate data and tpes. With it you can create objects and lists, transform them, convert from one type to another and many others. It also contains advanced mathematical stuff. 65 | 66 | # License 67 | MIT --------------------------------------------------------------------------------