Skip to content

Commit b5d98db

Browse files
committed
1.20.1-SNAPSHOT Documentation improvements
1 parent 2f1022d commit b5d98db

File tree

3 files changed

+172
-10
lines changed

3 files changed

+172
-10
lines changed

README.md

Lines changed: 170 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,159 @@
11
# ![Logo](render-js.png?raw=true "Title") [Render-js](https://github.com/ComLock/render-js) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![npm version](https://img.shields.io/npm/v/react.svg?style=flat)](https://www.npmjs.com/package/render-js)
22

3-
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.
44

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.
8+
9+
Render-js keeps specificity extremely low by generating tachyons (single purpose classes).
10+
11+
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.
47+
48+
```js
49+
tagName(
50+
tagName()
51+
);
52+
```
53+
54+
For example:
55+
```js
56+
p({
57+
class: 'className'
58+
}, [
59+
'Text before ',
60+
a({href: 'https://www.example.com'}, 'link'),
61+
' text after.'
62+
]);
63+
```
64+
65+
### HTML attribute object
66+
67+
An html attribute looks like this (EBNF):
68+
```ebnf
69+
<html-attribute> :== <name> <equalSign> <quoteMark> <value> <quoteMark>
70+
<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.
692

7-
This library can be imported and used in at least 3 ways: dom, ncss and index
93+
### Style attribute object
894

9-
### Dom (ECMAscript 2015)
95+
An html style attribute consists of is a semicolon seperated key value pair list. (EBNF):
96+
97+
```ebnf
98+
<style-attribute> ::= <declaration> {<semicolon> <declaration>}
99+
<declaration> ::= <property> <colon> <value>
100+
<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.
111+
112+
```js
113+
{
114+
color: 'white',
115+
backgroundColor: 'black'
116+
}
117+
```
118+
119+
```html
120+
style="color:white;background-color:black"
121+
```
122+
123+
124+
###### HTML: ECMAscript 2015 example
125+
126+
```js
127+
import {p, render} from 'render-js/html.es';
128+
render(p({style: {backgroundColor: 'white'}}, 'Hello world'));
129+
```
130+
131+
###### HTML: Javascript 1.6 example
132+
133+
```js
134+
var R = require('render-js/dist/html.js');
135+
var render = R.render;
136+
var p = R.p;
137+
render(p({style: {backgroundColor: 'white'}}, 'Hello world'));
138+
```
139+
140+
###### HTML: Result
141+
```html
142+
<p style="background-color:white">Hello world</p>
143+
```
144+
145+
146+
## Generation 2: NCSS
147+
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
10157

11158
```js
12159
import { Dom, doctype, html, head, title, style,
@@ -95,16 +242,27 @@ Which will give you this html (without whitespace and indentation):
95242
</html>
96243
```
97244

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+
99257

100258
### How to include in Enonic XP app (does not apply to Node.js)
101259
```groovy
102260
dependencies {
103-
include 'com.enonic.lib:render-js:1.0.0'
261+
include 'com.enonic.lib:render-js:1.20.0'
104262
}
105263
```
106264

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)
108266

109267
```js
110268
var R = require('/lib/render-js/index.js');
@@ -127,7 +285,7 @@ exports.get = function(request) {
127285
} // exports.get
128286
```
129287

130-
### How to use it in ECMAscript 2015 (Node.js, Enonic XP 7)
288+
###### HTML: How to use it in ECMAscript 2015 (Node.js, Enonic XP 7)
131289

132290
```js
133291
import R, { render, doctype, html, head, title, body, main, h1, form } from 'render-js';
@@ -206,6 +364,10 @@ In terms of extendability, returning an object with named properties should be t
206364

207365
## Changelog
208366

367+
### 1.20.1-SNAPSHOT
368+
369+
* Documentation improvements
370+
209371
### 1.20.0
210372

211373
* Class FEATURE: addClass()

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ projectName = render-js
33
appName = com.enonic.lib.render-js
44
displayName = Render JS
55
xpVersion = 6.12.2
6-
version = 1.20.0
6+
version = 1.20.1-SNAPSHOT

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@
4848
"mocha": "node_modules/.bin/mocha -c --require babel-core/register",
4949
"test": "npm run mocha -- test/*.es* test/*/*.es*"
5050
},
51-
"version": "1.20.0"
51+
"version": "1.20.1-SNAPSHOT"
5252
}

0 commit comments

Comments
 (0)