@podium/utils
Advanced tools
Comparing version 4.0.0-next.4 to 4.0.0-next.5
@@ -14,22 +14,14 @@ 'use strict'; | ||
const document = ({ | ||
head = '', | ||
body = '', | ||
encoding = 'utf-8', | ||
locale = 'en-US', | ||
title = '', | ||
js = [], | ||
css = [], | ||
} = {}) => { | ||
let scripts = js; | ||
let styles = css; | ||
const document = (incoming = {}, body = '', head = '') => { | ||
let scripts = incoming.js; | ||
let styles = incoming.css; | ||
// backwards compatibility for scripts and styles | ||
if (typeof js === 'string') scripts = [{ type: 'default', value: js }]; | ||
if (typeof css === 'string') styles = [{ type: 'default', value: css }]; | ||
if (typeof incoming.js === 'string') scripts = [{ type: 'default', value: incoming.js }]; | ||
if (typeof incoming.css === 'string') styles = [{ type: 'default', value: incoming.css }]; | ||
return `<!doctype html> | ||
<html lang="${locale}"> | ||
<html lang="${incoming.context.locale ? incoming.context.locale : 'en-US'}"> | ||
<head> | ||
<meta charset="${encoding}"> | ||
<meta charset="${incoming.view.encoding ? incoming.view.encoding : 'utf-8'}"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
@@ -39,3 +31,3 @@ <meta http-equiv="X-UA-Compatible" content="IE=Edge"> | ||
${scripts.map(buildScriptTag).join('\n ')} | ||
<title>${title}</title> | ||
<title>${incoming.view.title ? incoming.view.title : ''}</title> | ||
${head} | ||
@@ -42,0 +34,0 @@ </head> |
'use strict'; | ||
const originalUrl = require('original-url'); | ||
const assert = require('assert'); | ||
const { URL } = require('url'); | ||
@@ -19,4 +18,2 @@ | ||
const noop = ({ body }) => body; | ||
const PodiumHttpIncoming = class PodiumHttpIncoming { | ||
@@ -34,3 +31,3 @@ constructor(request = {}, response = {}, params = {}) { | ||
this[_name] = ''; | ||
this[_view] = noop; | ||
this[_view] = {}; | ||
this[_url] = url.full ? new URL(url.full) : {}; | ||
@@ -135,30 +132,2 @@ this[_css] = []; | ||
render(data) { | ||
const type = Object.prototype.toString.call(data); | ||
assert( | ||
type === '[object String]' || type === '[object Object]', | ||
`data argument given to HttpIncoming.render must be either an object or a string`, | ||
); | ||
let ctx = data; | ||
if (typeof data === 'string') { | ||
ctx = { body: data }; | ||
} | ||
const context = { | ||
head: '', | ||
body: '', | ||
locale: | ||
this.context && this.context.locale | ||
? this.context.locale | ||
: 'en-US', | ||
title: this.name, | ||
js: this.js, | ||
css: this.css, | ||
...ctx, | ||
}; | ||
return this.view(context); | ||
} | ||
toJSON() { | ||
@@ -170,2 +139,3 @@ return { | ||
proxy: this.proxy, | ||
view: this.view, | ||
name: this.name, | ||
@@ -172,0 +142,0 @@ url: this.url, |
{ | ||
"name": "@podium/utils", | ||
"version": "4.0.0-next.4", | ||
"version": "4.0.0-next.5", | ||
"description": "Common generic utility methods shared by @podium modules.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25753
8
519