Hello 👋, I'm Oussama Essamadi, EOussama for short.
eoussama / temme.js Goto Github PK
View Code? Open in Web Editor NEWEmmet, but for JavaScript.
Home Page: https://eoussama.github.io/temme.js/
License: MIT License
Emmet, but for JavaScript.
Home Page: https://eoussama.github.io/temme.js/
License: MIT License
This package doesn't have a default file set. You can set it via jsdelivr
, browser
, or main
field in package.json
Adding support for a new option called templates
that will hold templating objects that are not created as HTML elements and only exists for the sake of other elements referencing them.
Syntax
templates: [
{
ref: 'temp-1',
classes: ['red', 'bold'],
dataset: {
id: 100
}
// ...
// Any other options aside from `name` and `children`.
}
// Other templates if needed...
]
Data structure
templates
option must be an array, and each object in it must have a ref
option, otherwise, it's invalid.name
option.children
option.Referencing a template
Referencing templates works the same as referencing other elements.
{
templates: [
{
ref: 'temp-1',
classes: ['bold', 'italic']
}
],
children: [
{
from: {
ref: 'temp-1',
mode: 'append'
},
classes: ['red']
}
]
}
<div>
<div class="bold italic red" />
</div>
In some cases, you'd want to reuse another element in a said skeleton, be it somewhere on the DOM or part of the same hierarchy object.
We should be able to reference other elements without having to copy all the code again, after all, Temme exists to solve problems like that.
Things to consider:
Suggested syntax:
const hierarchy = {
children: [
{
ref: 'reusable-paragraph',
name: 'p',
classes: ['bold', 'red']
},
{
name: 'div',
children: [
{
from: {
ref: 'reusable-paragraph'
}
},
{
from: {
ref: 'reusable-paragraph',
mode: 'append'
},
id: 'some-id',
classes: ['red', 'shadow', 'title'],
text: 'content'
}
]
},
{
from: {
ref: 'reusable-paragraph',
mode: 'override'
},
id: 'some-id',
classes: ['red', 'italic', 'title']
}
]
}
The output:
<div>
<p class="bold red"></p>
<div>
<p class="bold red"></p>
<p class="bold red shadow title">content</p>
</div>
<p class="red italic title"></p>
</div>
Simply convert an HTML tree into a valid hierarchy.
Temme.convert(htmlTree: HTMLElement);
Take into account the following HTML tree:
<div id="parent-id" class="red">
<h1 class="red bold">Heading</h1>
</div>
That would simply be converted into the following:
{
temmeIds: [],
ref: "parent",
id: "parent-id",
name: "div",
classes: ["red"],
childNodes: [
{
temmeIds: [],
ref: "",
id: "",
name: "h1",
classes: ["bold"],
childNodes: [],
templates: [],
attributes: {},
dataset: {},
content:{
type: "text",
value: "Heading"
},
from:{
ref: "parent",
mode: "append",
include:["name", "id", "classes", "attributes", "dataset", "content", "childNodes"],
exclude:[],
children: {
allow: false,
placement: "after"
}
}
}
],
templates: [],
attributes: {},
dataset: {},
content:{
type: "text",
value: ""
},
from:{
ref: "",
mode: "append",
include:["name", "id", "classes", "attributes", "dataset", "content", "childNodes"],
exclude:[],
children: {
allow: false,
placement: "after"
}
}
}
Notice how Temme has to figure out how to cleverly set inheritances on its own.
Add a way to explicitly tell Temme to clone a specific hierarchy a number of times.
That could be used in case of generating a long list where it's preferred to remain as short as you can when putting together a hierarchy object.
This change will introduce a new option that will take care of duplication through a sub-option of its own, and eventually house other sub-options in the future that don't alter how a hierarchy is defined per se but do add some extra instruction on how to deal with it.
The suggested names would respectively be meta and repeat.
{
meta: {
repeat: 5
},
name: 'span',
classes: ['cls-1', 'cls-2']
}
That simply instructs Temme to clone the hierarchy 5 times (5 clones + 1 original = 6 duplicates) and eventually end up with the following;
<span class="cls-1 cls-2" />
<span class="cls-1 cls-2" />
<span class="cls-1 cls-2" />
<span class="cls-1 cls-2" />
<span class="cls-1 cls-2" />
<span class="cls-1 cls-2" />
meta
option is not inherited.repeat
should of course be:
As the library is growing, and as it becomes harder to maintain, modularity has become more of an option.
We could have gone with simple ES6
modules and called it a day, however, why stop there?
The library is currently being re-written in Typescript
if you want to follow along, refer to the typescript branch.
Gulp is probbaly getting disposed of, and Webpack is used instead in bundling.
I believe this is the better direction to go from here, as it offers better testing for individual modules.
Adding the ability to specify what to inherit and what to ignore. Sometimes you would want to inherit only the classes and ignore all other options, some other times you would want to inherit everything except for a certain option.
include
and exclude
are both options that go along the from
option and give control over option inheritance.
Syntax
{
children: [
{
ref: 'some-ref',
name: 'input',
classes: ['bold', 'red'],
attributes: {
type: 'button',
name: 'form-input'
}
},
{
from: {
ref: 'some-ref',
mode: 'append',
include: ['classes']
}
}
]
}
Data structure
from
option can either have an include
option or exclude
option, but never both at the same time.from
option can have none of the options above, in that case, it should include all by default (exclude nothing).Make it possible for the users to be able to use Temme's internal process of evaluation Hierarchy objects.
Temme.eval(hierarchy: Object);
It evaluates the passed hierarchy object and returns true if it was valid, else, it returns some information about either of the following:
False: If the hierarchy is not valid.
An object: An object that has both the name and the message of the first encountered error.
An array: An array that includes descriptive objects about all of the errors found in the hierarchy object.
Temme.eval({
id: true
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.