https://github.com/onepointert/cacao
https://github.com/onepointert/cacao
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/onepointert/cacao
- Owner: onepointerT
- License: apache-2.0
- Created: 2024-03-16T21:51:29.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-19T16:49:45.000Z (about 1 year ago)
- Last Synced: 2024-03-20T05:05:29.088Z (about 1 year ago)
- Language: CoffeeScript
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cacao
### Concurrent Arbitrary Consent Artificial Objects
#### v0.1.0This small library is implemented to handle concurrent consent in arbitrary objects, operates on the alphabet with a simple syntax:
````cacao
* `###varname{}` stores the variable content from this position until the occurence of the next
variable or a delimiter in between into the environments variable's stack
* `##varname{$value}` defines a value at this position
* `#varname{}` inserts the current value of varname from environment variables at this position
* A second brace pair behind a variable definition then transforms and formats with the script
and cacao environment variables, e.g. `##varname{#body{}}{#html_full{}}` replaces `#body{}`
with the values from `cacao.env.html_full` on template substitution.
````To use the library, please import the index file
````coffeescript
import 'cacao/index'
````You can use the python file `cacaodev.py` to compile the coffeescript files or simply run `npm run dev`.
## Using
#### Setup
You might want to have a look at `examples/`. You might for example define your html template like this:
````js
html_tmpl = Cacao.Environment.Template.fromFile 'cacao/examples/html.cacao'
html_tmpl.readToEnv cacao.env
````to setup the environment with one template only.
#### Example 1
To get the content inside both html tags in the variable `cacao.env.body_html`, you can work like this
````html
html_text = """"""
Some text
````
````js
html_tmpl.transform html_text, cacao.env
````and you'll have the following variables in `cacao.env`:
````js
cacao.env.body_html == "Some text"
cacao.env.starttag == "div"
cacao.env.properties == """class="container""""
````#### Example 2
If using a programming or scripting language, it might be useful to know operands, tags and variables and transform them. In this example we'll see, how more dynamic [Jinja](https://jinja.palletsprojects.com/en/3.0.x/templates/) could work.
Therefore there is a `Cacao.Transition` class, that can be used to make a fourier transformation or to determine variables
just from there position in a string.````js
code_tmpl = Cacao.Transition.fromFile 'cacao/eamples/jinja_for.cacao'
code_tmpl.equiv.template_refactoring.readToEnv cacao.env
cacao.env.jinja_text = code_tmpl.template_refactoring.tmpl_str
````
````jinja
{% for elem in elements %}
#body_jinja{}
{% endfor %}
````
````js
code_tmpl.transform jinja_text, cacao.env
````should then give the following variables in the environment
````js
cacao.env.operand == "for"
cacao.env.what == "elem in elements"
cacao.env.varnames == "elem"
cacao.env.arrayname == "elements"
cacao.env.body_jinja == "#body_jinja{}"
````As we can see, the next substitution would introduce everything from `cacao.env.body_jinja` variable into the templates's string, so we could to some magic for dynamic loops.
````js
cacao.env.html_full = """<#{cacao.env.starttag} #{cacao.env.properties}>#body_jinja{}#{cacao.env.starttag}>"""
cacao.env.body_jinja = "#{cacao.env.hmtl_full}"
code_tmpl.transform jinja_text, cacao.env
````would then give a html container per loop iteration in jinja and insert everything from jinja inside.
Mode and not -- more advanced examples and tests might follow.
## Copyright
````
Copyright 2024 Sebastian LauLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.`
````