You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Render-js is library for generating html and sometimes css from js.
3
+
Render-js is library for generating html and non cascading styling in js.
4
4
5
-
## Examples
5
+
It's a can be used to build simple websites or advanced frontend frameworks, alleviating typical css complexity problems.
6
+
7
+
Typically a framework starts out simple, but quickly reaches a point where it becomes hard to change anything because of ever increasing CSS entanglement.
The programmer simply defines what css properties an HTML element should have. You can even define media queries for responsive styling.
12
+
13
+
## Genesis
14
+
15
+
I started programming Render-js as an alternative to thymeleaf, but it quickly grew into much more. Everytime I got a major idea I developed it as a new variant without changing the previous one:
16
+
17
+
## Generation 1: HTML
18
+
19
+
Use this if you only want to generate html. It should be highly performant.
20
+
21
+
### Core concepts (syntax)
22
+
23
+
#### HTML element functions
24
+
25
+
An HTML element consists of three things:
26
+
* tagName
27
+
* attributes
28
+
* content
29
+
30
+
Which rather naturally gives this syntax in js:
31
+
32
+
```js
33
+
tagName(attributes, content);
34
+
```
35
+
36
+
The attributes is an object with properties, while the content can be a string or a function reference or an array of them.
37
+
Both the attributes and content parameter are optional.
38
+
39
+
```js
40
+
tagName();
41
+
tagName('String');
42
+
tagName({key:'value'});
43
+
tagName({key:'value'}, 'String');
44
+
```
45
+
46
+
You build a dom by nesting html element functions.
<name> :== <case insensitive string sometimes with dashes>
71
+
<quoteMark> :== ' | "
72
+
```
73
+
74
+
Which lead to the following syntax in js:
75
+
76
+
```js
77
+
{ name: value, ... }
78
+
```
79
+
80
+
Too avoid having to quote js property names, any dashes must be removed.
81
+
This can be achieved since html attribute names are case insensitive, while js property names are case sensitive. So we use camelcase in JS and later dasherize into html attribute names.
82
+
83
+
```js
84
+
{dataProp:'value'}
85
+
```
86
+
87
+
```html
88
+
data-prop="value"
89
+
```
90
+
91
+
I have found an exception: The SVG attribute named viewBox. It is case-sensitive. So I simply don't dasherize that one. Make an issue on github if you run into any other case-sensitive HTML/SVG attributes.
6
92
7
-
This library can be imported and used in at least 3 ways: dom, ncss and index
93
+
### Style attribute object
8
94
9
-
### Dom (ECMAscript 2015)
95
+
An html style attribute consists of is a semicolon seperated key value pair list. (EBNF):
<property> :== <case insensitive string sometimes with dashes>
101
+
<value> :== <string>
102
+
```
103
+
104
+
Which lead to the following syntax in js:
105
+
106
+
```js
107
+
{ property: value, ... }
108
+
```
109
+
110
+
CSS property names contains dashes, which JS property names also can, but needs to be quotes. This can be avoided since CSS property names are case insensitive, while JS property names are case sensitive. So we use camelcase in JS and later dasherize into CSS property name.
This is when I figured out that it would be nice to generate css too.
148
+
149
+
All the features of this generation is present in the newest generation, so you should probably use that instead.
150
+
151
+
## Generation 3: DOM
152
+
This is when I figured out accessing and modify the dom could be useful.
153
+
154
+
All the features of this generation should be present in the newest generation, so you should probably use that instead.
155
+
156
+
###### DOM: ECMAscript 2015 example
10
157
11
158
```js
12
159
import { Dom, doctype, html, head, title, style,
@@ -95,16 +242,27 @@ Which will give you this html (without whitespace and indentation):
95
242
</html>
96
243
```
97
244
98
-
Yes the css is autogenerated.
245
+
## Generation 4: OBJ
246
+
This is when I started thinking about elements with "shared" styling, such as list elements. It would be wasteful to generate the same css many times. Which meant I needed to keep some state.
247
+
248
+
All the features of this generation should be present in the newest generation, so you should probably use that instead.
249
+
250
+
## Generation 5: CLASS (current generation)
251
+
This is when I started thinking about keeping the Dom object as small as possible so it could be transferred efficiently to the browser.
252
+
253
+
254
+
## Examples
255
+
256
+
99
257
100
258
### How to include in Enonic XP app (does not apply to Node.js)
101
259
```groovy
102
260
dependencies {
103
-
include 'com.enonic.lib:render-js:1.0.0'
261
+
include 'com.enonic.lib:render-js:1.20.0'
104
262
}
105
263
```
106
264
107
-
### How to use it in Javascript 1.6 (Enonic XP 6.12.2)
265
+
###### HTML: How to use it in Javascript 1.6 (Enonic XP 6.12.2)
0 commit comments