als-layout 0.2.0 → 0.3.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.
Files changed (3) hide show
  1. package/layout.js +12 -14
  2. package/package.json +1 -1
  3. package/readme.md +9 -9
package/layout.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = class Layout {
2
- constructor({title,body,description,image,lang='en',url,twiterName,scripts={},links={},favicon,footer='',header='',charset='UTF-8'}) {
2
+ constructor({title,body,description,image,lang='en',url,twiterName,scripts=[],links=[],favicon,footer='',header='',charset='UTF-8'}) {
3
3
  this.title = title
4
4
  this.body = body
5
5
  this.description = description
@@ -15,16 +15,16 @@ module.exports = class Layout {
15
15
  this.twiterName = twiterName
16
16
  }
17
17
 
18
- get({title,body,description,image,lang,url,favicon,footer='',header='',scripts={},links={},charset=this.charset}) {
19
- this.scripts = scripts
20
- this.links = links
18
+ get({title,body,description,image,lang,url,favicon,footer='',header='',scripts=[],links=[],charset=this.charset}) {
19
+ this.scripts = [...this.scripts,...scripts]
20
+ this.links = [...this.links,...links]
21
21
  if(title) this.title = title
22
22
  if(body) this.body = body
23
- if(description) this.description = description
24
- if(image) this.image = image
25
- if(lang) this.lang = lang
26
- if(url) this.url = url
27
- if(favicon) this.favicon = favicon
23
+ if(description && description !== '') this.description = description
24
+ if(image && image !== '') this.image = image
25
+ if(lang && lang !== '') this.lang = lang
26
+ if(url && url !== '') this.url = url
27
+ if(favicon && favicon !== '') this.favicon = favicon
28
28
  this.footer = footer
29
29
  this.header = header
30
30
  let {footerScripts,headerScripts} = this._scripts()
@@ -71,7 +71,7 @@ module.exports = class Layout {
71
71
  }
72
72
 
73
73
  _footer(scripts) {
74
- return /*html*/`${scripts} ${this.footer}`
74
+ return /*html*/`${this.footer} ${scripts}`
75
75
  }
76
76
 
77
77
  _header(scripts) {
@@ -81,8 +81,7 @@ module.exports = class Layout {
81
81
  _scripts() {
82
82
  let footerScripts = ''
83
83
  let headerScripts = ''
84
- Object.keys(this.scripts).forEach(name => {
85
- let script = this.scripts[name]
84
+ this.scripts.forEach(script => {
86
85
  let {inner='',src='',async,crossorigin,defer,integrity,referrerpolicy,type,footer=false,v} = script
87
86
  v = v ? '?'+v : ''
88
87
  async = async ? ' async ' : ''
@@ -100,8 +99,7 @@ module.exports = class Layout {
100
99
  }
101
100
 
102
101
  _styles() {
103
- return Object.keys(this.links).map(name => {
104
- let link = this.links[name]
102
+ return this.links.map(link => {
105
103
  let {href,rel='stylesheet',crossorigin,hreflang,media,referrerpolicy,sizes,type,v} = link
106
104
  v = v ? '?'+v : ''
107
105
  crossorigin = crossorigin ? ` crossorigin="${crossorigin}" ` : ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "als-layout",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Being tested. create html layout with node",
5
5
  "main": "layout.js",
6
6
  "keywords": [],
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Als-layout
2
2
 
3
- **being tested**
3
+ * new in 0.3: scripts and links now array
4
4
 
5
5
  ## Syntax
6
6
  ```javascript
@@ -9,7 +9,7 @@ let Layout = require('als-layout')
9
9
  let layout = new Layout({
10
10
  title,body,description,image,
11
11
  lang='en',url,twiterName,
12
- scripts={},links={},
12
+ scripts=[],links=[],
13
13
  favicon,footer='',header='',
14
14
  charset='UTF-8'
15
15
  })
@@ -18,7 +18,7 @@ let pageLayout = layout.get({
18
18
  title,body,description,image,
19
19
  lang,url,favicon,
20
20
  footer='',header='',
21
- scripts={},links={},
21
+ scripts=[],links=[],
22
22
  charset=this.charset
23
23
  })
24
24
  ```
@@ -27,10 +27,10 @@ let pageLayout = layout.get({
27
27
  ## scripts and links
28
28
 
29
29
  ```javascript
30
- let scripts = {
31
- scriptName:{inner='',src='',async,crossorigin,defer,integrity,referrerpolicy,type,footer=false,v}
32
- }
33
- let links = {
34
- linkName:{href,rel='stylesheet',crossorigin,hreflang,media,referrerpolicy,sizes,type,v}
35
- }
30
+ let scripts = [
31
+ {inner='',src='',async,crossorigin,defer,integrity,referrerpolicy,type,footer=false,v}
32
+ ]
33
+ let links = [
34
+ {href,rel='stylesheet',crossorigin,hreflang,media,referrerpolicy,sizes,type,v}
35
+ ]
36
36
  ```