als-layout 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/0-change-log.md +2 -0
- package/index.js +0 -13
- package/package.json +1 -2
- package/readme.md +2 -50
- package/docs/4-render.md +0 -49
- package/tests/render/counter/App.js +0 -8
- package/tests/render/counter/Counter.js +0 -9
- package/tests/render/counter/build.js +0 -12
- package/tests/render/render/App.js +0 -10
- package/tests/render/render/Some.js +0 -8
- package/tests/render.test.js +0 -24
package/docs/0-change-log.md
CHANGED
package/index.js
CHANGED
|
@@ -2,7 +2,6 @@ const { Document, SingleNode, Node } = require('als-document');
|
|
|
2
2
|
const UglifyJS = require("uglify-js");
|
|
3
3
|
const uglifycss = require('uglifycss');
|
|
4
4
|
|
|
5
|
-
const render = require('als-render');
|
|
6
5
|
const onloadScript = /*js*/`document.addEventListener('DOMContentLoaded', function() {
|
|
7
6
|
const elements = document.querySelectorAll('[onload]');
|
|
8
7
|
elements.forEach(element => {
|
|
@@ -148,18 +147,6 @@ class Layout extends Document {
|
|
|
148
147
|
this.head.insert(2, linkElement)
|
|
149
148
|
return this
|
|
150
149
|
}
|
|
151
|
-
|
|
152
|
-
$(selector) {
|
|
153
|
-
const element = super.$(selector)
|
|
154
|
-
if (!element) return null
|
|
155
|
-
element.render = (path, data, includeBundle = true, contextName = 'context') => {
|
|
156
|
-
const { rawHtml, bundle } = render(path, data, contextName, false)
|
|
157
|
-
element.innerHTML = rawHtml
|
|
158
|
-
if (includeBundle) this.script({}, bundle, false)
|
|
159
|
-
return this
|
|
160
|
-
}
|
|
161
|
-
return element
|
|
162
|
-
}
|
|
163
150
|
}
|
|
164
151
|
|
|
165
152
|
module.exports = Layout
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "als-layout",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --experimental-test-coverage",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"description": "Html layout constructor",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"als-document": "^1.4.0",
|
|
15
|
-
"als-render": "^0.4.0",
|
|
16
15
|
"uglify-js": "^3.19.2",
|
|
17
16
|
"uglifycss": "^0.0.29"
|
|
18
17
|
}
|
package/readme.md
CHANGED
|
@@ -20,6 +20,8 @@ const Layout = require('als-layout')
|
|
|
20
20
|
|
|
21
21
|
## Change Log
|
|
22
22
|
|
|
23
|
+
* V4.1.0
|
|
24
|
+
* Render removed
|
|
23
25
|
* V4.0.0
|
|
24
26
|
* All code rebuilded and refactored
|
|
25
27
|
* No als-simple-css for style
|
|
@@ -144,53 +146,3 @@ In this example:
|
|
|
144
146
|
|
|
145
147
|
This advanced example illustrates how `als-layout` can be used to handle complex scenarios and requirements in web development, enhancing the flexibility and power at your disposal.
|
|
146
148
|
|
|
147
|
-
|
|
148
|
-
## Rendering
|
|
149
|
-
Since version 4.0 , `als-layout` using `als-render` for rendering.
|
|
150
|
-
Not for production use yet.
|
|
151
|
-
|
|
152
|
-
### Counter Example
|
|
153
|
-
To demonstrate dynamic interaction, consider a counter that can be increased or decreased through user input:
|
|
154
|
-
|
|
155
|
-
The App.js
|
|
156
|
-
```jsx
|
|
157
|
-
const Counter = require('./Counter')
|
|
158
|
-
function App() {
|
|
159
|
-
context.count = 0
|
|
160
|
-
return (<div>
|
|
161
|
-
<Counter count={0} />
|
|
162
|
-
</div>)
|
|
163
|
-
}
|
|
164
|
-
module.exports = App
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
Counter.js
|
|
168
|
-
```jsx
|
|
169
|
-
function Counter({count}) {
|
|
170
|
-
return (<div>
|
|
171
|
-
<button onclick={() => this.update({count:count+1})}>Increase</button>
|
|
172
|
-
<span>{count}</span>
|
|
173
|
-
<button onclick={() => this.update({count:count-1})}>Decrease</button>
|
|
174
|
-
</div>)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
module.exports = Counter
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
build.js
|
|
181
|
-
```js
|
|
182
|
-
const fs = require('fs')
|
|
183
|
-
const Layout = require('als-layout')
|
|
184
|
-
|
|
185
|
-
// Create and configure the layout
|
|
186
|
-
const host = 'http://somehost.com'
|
|
187
|
-
const minified = false
|
|
188
|
-
const layout = new Layout('',host,minified).title('Counter')
|
|
189
|
-
|
|
190
|
-
const data = {}, includeBundle = true;
|
|
191
|
-
layout.$('body').render('./App',data,includeBundle)
|
|
192
|
-
|
|
193
|
-
// Write the output to a file
|
|
194
|
-
fs.writeFileSync('counter.html', layout.rawHtml, 'utf-8')
|
|
195
|
-
```
|
|
196
|
-
|
package/docs/4-render.md
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
## Rendering
|
|
2
|
-
Since version 4.0 , `als-layout` using `als-render` for rendering.
|
|
3
|
-
Not for production use yet.
|
|
4
|
-
|
|
5
|
-
### Counter Example
|
|
6
|
-
To demonstrate dynamic interaction, consider a counter that can be increased or decreased through user input:
|
|
7
|
-
|
|
8
|
-
The App.js
|
|
9
|
-
```jsx
|
|
10
|
-
const Counter = require('./Counter')
|
|
11
|
-
function App() {
|
|
12
|
-
context.count = 0
|
|
13
|
-
return (<div>
|
|
14
|
-
<Counter count={0} />
|
|
15
|
-
</div>)
|
|
16
|
-
}
|
|
17
|
-
module.exports = App
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Counter.js
|
|
21
|
-
```jsx
|
|
22
|
-
function Counter({count}) {
|
|
23
|
-
return (<div>
|
|
24
|
-
<button onclick={() => this.update({count:count+1})}>Increase</button>
|
|
25
|
-
<span>{count}</span>
|
|
26
|
-
<button onclick={() => this.update({count:count-1})}>Decrease</button>
|
|
27
|
-
</div>)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = Counter
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
build.js
|
|
34
|
-
```js
|
|
35
|
-
const fs = require('fs')
|
|
36
|
-
const Layout = require('als-layout')
|
|
37
|
-
|
|
38
|
-
// Create and configure the layout
|
|
39
|
-
const host = 'http://somehost.com'
|
|
40
|
-
const minified = false
|
|
41
|
-
const layout = new Layout('',host,minified).title('Counter')
|
|
42
|
-
|
|
43
|
-
const data = {}, includeBundle = true;
|
|
44
|
-
layout.$('body').render('./App',data,includeBundle)
|
|
45
|
-
|
|
46
|
-
// Write the output to a file
|
|
47
|
-
fs.writeFileSync('counter.html', layout.rawHtml, 'utf-8')
|
|
48
|
-
```
|
|
49
|
-
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const Layout = require('../../../index')
|
|
3
|
-
|
|
4
|
-
// Create and configure the layout
|
|
5
|
-
const layout = new Layout('','',false).title('Counter')
|
|
6
|
-
const time1 = performance.now()
|
|
7
|
-
layout.$('body').render('./App')
|
|
8
|
-
const time2 = performance.now()
|
|
9
|
-
console.log(`${time2 - time1}ms`) // e.g., 1.0649ms
|
|
10
|
-
|
|
11
|
-
// Write the output to a file
|
|
12
|
-
fs.writeFileSync('counter.html', layout.rawHtml, 'utf-8')
|
package/tests/render.test.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const assert = require('assert');
|
|
2
|
-
const { describe, it,beforeEach } = require('node:test')
|
|
3
|
-
const Layout = require('../index')
|
|
4
|
-
|
|
5
|
-
describe('Basic tests', () => {
|
|
6
|
-
let layout
|
|
7
|
-
beforeEach(() => layout = new Layout())
|
|
8
|
-
it('Should render without bundle',() => {
|
|
9
|
-
layout.$('body').render('./render/render/App',{},false)
|
|
10
|
-
const expected =
|
|
11
|
-
'<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title></head><body><div component="App"><div>Hello from App!</div>\n' +
|
|
12
|
-
' <div component="Some">Hello From Some!</div></div></body></html>'
|
|
13
|
-
assert(layout.rawHtml === expected)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('Should render with bundle',() => {
|
|
17
|
-
layout.$('body').render('./render/render/App')
|
|
18
|
-
assert(layout.rawHtml.includes('<script>'))
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('Should do nothing if element not exists',() => {
|
|
22
|
-
assert.throws(() => layout.$('main').render('./render/render/App'))
|
|
23
|
-
})
|
|
24
|
-
})
|