als-layout 5.0.1 → 5.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/lib/layout.js +0 -12
- package/package.json +1 -1
- package/readme.md +8 -15
package/lib/layout.js
CHANGED
|
@@ -9,7 +9,6 @@ class Layout extends Document {
|
|
|
9
9
|
this.options = options
|
|
10
10
|
this.logger = options.logger || console
|
|
11
11
|
this.root = this.html
|
|
12
|
-
this.statusCode = 200
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
get rawHtml() { return this.innerHTML }
|
|
@@ -113,17 +112,6 @@ class Layout extends Document {
|
|
|
113
112
|
this.head.insert(2, linkElement)
|
|
114
113
|
return this
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
status(statusCode) { this.statusCode = statusCode; return this }
|
|
118
|
-
|
|
119
|
-
end(res,statusCode = this.statusCode, rawHtml = this.rawHtml) {
|
|
120
|
-
res.writeHead(statusCode);
|
|
121
|
-
if (res.set) res.set('Content-Type', 'text/html') // for Express
|
|
122
|
-
else res.setHeader('Content-Type', 'text/html') // for http
|
|
123
|
-
res.end(rawHtml)
|
|
124
|
-
return this
|
|
125
|
-
}
|
|
126
|
-
|
|
127
115
|
}
|
|
128
116
|
|
|
129
117
|
module.exports = Layout
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -17,8 +17,11 @@ npm i als-layout
|
|
|
17
17
|
```js
|
|
18
18
|
const Layout = require('als-layout')
|
|
19
19
|
```
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
## Change Log
|
|
22
|
+
* V5.1.0
|
|
23
|
+
* status and end methods removed
|
|
24
|
+
* status and end methods added to als-view
|
|
22
25
|
* V5.0.0
|
|
23
26
|
* constructor changed
|
|
24
27
|
* options object parameter instead separated parameters
|
|
@@ -50,7 +53,7 @@ const Layout = require('als-layout')
|
|
|
50
53
|
* render switched to als-render
|
|
51
54
|
* updated bug with meta tags after body
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
|
|
54
57
|
## Basic Usage
|
|
55
58
|
|
|
56
59
|
### Initialization
|
|
@@ -77,8 +80,6 @@ const layout = new Layout()
|
|
|
77
80
|
.link('/styles.css') // adding link[rel=stylesheet] if such href not exists
|
|
78
81
|
.script({src:'/app.js'}, '', true) // set script with src to head if such src not exists
|
|
79
82
|
.script({}, 'console.log("hello world")', false) // set script with script code to footer
|
|
80
|
-
.status(200)
|
|
81
|
-
.end(response);
|
|
82
83
|
|
|
83
84
|
// Accessors for document parts
|
|
84
85
|
layout.body // getter for body element (if not exists, created)
|
|
@@ -98,7 +99,7 @@ Example how it works:
|
|
|
98
99
|
```js
|
|
99
100
|
const layout = new Layout().viewport().title('On load').onload()
|
|
100
101
|
layout.body.innerHTML = /*html*/`<div onload="this.innerHTML = 'new content'">original content</div>`
|
|
101
|
-
```
|
|
102
|
+
```
|
|
102
103
|
## Cloning Functionality
|
|
103
104
|
|
|
104
105
|
### What is Cloning and Why is it Necessary?
|
|
@@ -118,7 +119,7 @@ const newLayout = layout.clone;
|
|
|
118
119
|
|
|
119
120
|
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.
|
|
120
121
|
|
|
121
|
-
|
|
122
|
+
|
|
122
123
|
## Advanced Usage
|
|
123
124
|
|
|
124
125
|
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:
|
|
@@ -166,7 +167,7 @@ In this example:
|
|
|
166
167
|
- We dynamically add a versioned link to a stylesheet in the `homePage`, demonstrating control over caching and resource management.
|
|
167
168
|
|
|
168
169
|
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.
|
|
169
|
-
|
|
170
|
+
|
|
170
171
|
## API
|
|
171
172
|
|
|
172
173
|
### Constructor
|
|
@@ -255,11 +256,3 @@ Adds a `<script>` tag to the document.
|
|
|
255
256
|
#### `link(href: string, attributes: object = { rel: "stylesheet", type: "text/css" }): this`
|
|
256
257
|
|
|
257
258
|
Adds a `<link>` tag for external stylesheets.
|
|
258
|
-
|
|
259
|
-
#### `status(statusCode: number): this`
|
|
260
|
-
|
|
261
|
-
Sets the HTTP status code for the response.
|
|
262
|
-
|
|
263
|
-
#### `end(res: object): this`
|
|
264
|
-
|
|
265
|
-
Sends the HTML response with the specified `statusCode` and sets `Content-Type` to `text/html`.
|