als-layout 6.0.0 → 6.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/2-cloning.md +16 -0
- package/lib/layout.js +5 -1
- package/package.json +1 -1
- package/readme.md +21 -6
package/docs/2-cloning.md
CHANGED
|
@@ -17,3 +17,19 @@ const newLayout = layout.clone;
|
|
|
17
17
|
|
|
18
18
|
Cloning is particularly useful in scenarios where templates or base layouts are used repeatedly with slight variations, providing a robust and scalable solution for web page generation.
|
|
19
19
|
|
|
20
|
+
|
|
21
|
+
### propsToClone
|
|
22
|
+
|
|
23
|
+
You can add properties to add when cloning the object, by adding name of properties to `Layout.propsToClone` which is array.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
Layout.propsToClone.push('projectName')
|
|
29
|
+
|
|
30
|
+
const layout = new Layout()
|
|
31
|
+
layout.projectName = 'Cool project'
|
|
32
|
+
|
|
33
|
+
const cloned = layout.clone
|
|
34
|
+
console.log(cloned.projectName) // 'Cool project'
|
|
35
|
+
```
|
package/lib/layout.js
CHANGED
|
@@ -14,7 +14,11 @@ class Layout extends Document {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
get rawHtml() { return this.innerHTML }
|
|
17
|
-
get clone() {
|
|
17
|
+
get clone() {
|
|
18
|
+
const clone = new this.constructor(new Document(this, this.URL), this.options)
|
|
19
|
+
Layout.propsToClone.forEach(prop => clone[prop] = this[prop])
|
|
20
|
+
return clone
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
__status = 200;
|
|
20
24
|
status(status) { this.__status = status; return this }
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -17,7 +17,7 @@ npm i als-layout
|
|
|
17
17
|
```js
|
|
18
18
|
const Layout = require('als-layout')
|
|
19
19
|
```
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
## Change Log for V6
|
|
22
22
|
|
|
23
23
|
The code refactored.
|
|
@@ -28,7 +28,7 @@ The code refactored.
|
|
|
28
28
|
### Added
|
|
29
29
|
* status
|
|
30
30
|
* end(res)
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
## Basic Usage
|
|
33
33
|
|
|
34
34
|
### Initialization
|
|
@@ -66,7 +66,7 @@ layout.rawHtml // raw HTML of the document
|
|
|
66
66
|
layout.clone // creates a new layout object clone for current object
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
## Cloning Functionality
|
|
71
71
|
|
|
72
72
|
### What is Cloning and Why is it Necessary?
|
|
@@ -86,7 +86,22 @@ const newLayout = layout.clone;
|
|
|
86
86
|
|
|
87
87
|
Cloning is particularly useful in scenarios where templates or base layouts are used repeatedly with slight variations, providing a robust and scalable solution for web page generation.
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
|
|
90
|
+
### propsToClone
|
|
91
|
+
|
|
92
|
+
You can add properties to add when cloning the object, by adding name of properties to `Layout.propsToClone` which is array.
|
|
93
|
+
|
|
94
|
+
Example:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
Layout.propsToClone.push('projectName')
|
|
98
|
+
|
|
99
|
+
const layout = new Layout()
|
|
100
|
+
layout.projectName = 'Cool project'
|
|
101
|
+
|
|
102
|
+
const cloned = layout.clone
|
|
103
|
+
console.log(cloned.projectName) // 'Cool project'
|
|
104
|
+
```
|
|
90
105
|
## Advanced Usage
|
|
91
106
|
|
|
92
107
|
The `als-layout` library allows for sophisticated manipulation of web page layouts, providing robust tools for creating dynamic and complex web pages. Below is an advanced example demonstrating various capabilities of the library:
|
|
@@ -135,7 +150,7 @@ In this example:
|
|
|
135
150
|
|
|
136
151
|
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.
|
|
137
152
|
|
|
138
|
-
|
|
153
|
+
|
|
139
154
|
## Response with status
|
|
140
155
|
|
|
141
156
|
In version 6, added two methods:
|
|
@@ -145,7 +160,7 @@ In version 6, added two methods:
|
|
|
145
160
|
2. runs `res.end(this.rawHtml)`
|
|
146
161
|
|
|
147
162
|
|
|
148
|
-
The main idea, is to add quick way to response with layout.
|
|
163
|
+
The main idea, is to add quick way to response with layout.
|
|
149
164
|
## API
|
|
150
165
|
|
|
151
166
|
### Constructor
|