@soleil-se/app-util 1.0.2 → 1.0.3
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/README.md +36 -13
- package/dist/index.js +24 -0
- package/package.json +5 -1
- package/src/index.js +24 -0
package/README.md
CHANGED
|
@@ -6,39 +6,62 @@
|
|
|
6
6
|
```javascript
|
|
7
7
|
import { renderVue, getRouteUri, getResourceUri, renderTemplate, isOffline } from '@soleil-se/webapp-util';
|
|
8
8
|
```
|
|
9
|
-
### `renderVue`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`
|
|
13
|
-
|
|
9
|
+
### `renderVue(name, data, [noScript])` ⇒ `String`
|
|
10
|
+
Get HTML for rendering a Vue application.
|
|
11
|
+
|
|
12
|
+
**Returns**: `String` - HTML for rendering a Vue application.
|
|
13
|
+
|
|
14
|
+
| Param | Type | Default | Description |
|
|
15
|
+
| --- | --- | --- | --- |
|
|
16
|
+
| name | `String` | | Name of the app, has to match the name of the Vue application. |
|
|
17
|
+
| data | `Object` | | Data that will be available in `$options`. |
|
|
18
|
+
| [noScript] | `String` | `''` | HTML that will be printed when JavaScript is not available. |
|
|
14
19
|
```javascript
|
|
15
20
|
router.get('/', (req, res) => {
|
|
16
21
|
res.send(renderVue('AppName', data, noScript));
|
|
17
22
|
});
|
|
18
23
|
```
|
|
19
|
-
### `getRouteUri`
|
|
20
|
-
Get URI for a route.
|
|
24
|
+
### `getRouteUri(route)` ⇒ `String`
|
|
25
|
+
Get URI for a route.
|
|
26
|
+
|
|
27
|
+
**Returns**: `String` - URI for route.
|
|
28
|
+
|
|
29
|
+
| Param | Type | Description |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| route | `String` | A route. |
|
|
21
32
|
```javascript
|
|
22
33
|
const routeUri = getRouteUri('/my-route');
|
|
23
34
|
```
|
|
24
|
-
### `getResourceUri`
|
|
35
|
+
### `getResourceUri(resource)` ⇒ `String`
|
|
25
36
|
Get URI for a resource.
|
|
37
|
+
|
|
38
|
+
**Returns**: `String` - URI for a resource.
|
|
39
|
+
|
|
40
|
+
| Param | Type | Description |
|
|
41
|
+
| --- | --- | --- |
|
|
42
|
+
| resource | `String` | A resource. |
|
|
26
43
|
```javascript
|
|
27
44
|
const resourceUri = getResourceUri('file/in/resource.png');
|
|
28
45
|
```
|
|
29
|
-
### `renderTemplate`
|
|
30
|
-
Renders a Underscore template
|
|
46
|
+
### `renderTemplate(template, [values])` ⇒ `String`
|
|
47
|
+
Renders a Underscore template and returns a string.
|
|
48
|
+
|
|
49
|
+
**Returns**: `String` - Rendered template
|
|
50
|
+
|
|
51
|
+
| Param | Type | Default | Description |
|
|
52
|
+
| --- | --- | --- | --- |
|
|
53
|
+
| template | `String` | | Underscore template. |
|
|
54
|
+
| [values] | `Object` | `{}` | Values. |
|
|
31
55
|
```javascript
|
|
32
56
|
const string = renderTemplate('<div><%= foo %></div>', {
|
|
33
57
|
foo: 'bar',
|
|
34
58
|
});
|
|
35
59
|
```
|
|
36
60
|
### `isOffline`
|
|
61
|
+
If the webapp is running in offline mode or not.
|
|
62
|
+
|
|
37
63
|
```javascript
|
|
38
64
|
if(isOffline) {
|
|
39
65
|
// Do something
|
|
40
66
|
}
|
|
41
67
|
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,24 @@ import VersionUtil from 'VersionUtil';
|
|
|
4
4
|
import app from 'app';
|
|
5
5
|
import _ from 'underscore';
|
|
6
6
|
|
|
7
|
+
/** If the webapp is running in offline mode or not. */
|
|
7
8
|
export var isOffline = VersionUtil.getCurrentVersion() === VersionUtil.OFFLINE_VERSION;
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Get URI for a resource.
|
|
12
|
+
* @param {String} resource A resource.
|
|
13
|
+
* @returns {String} URI for a resource.
|
|
14
|
+
*/
|
|
9
15
|
export function getResourceUri(resource) {
|
|
10
16
|
return ("/webapp-files/" + (app.webAppId) + "/" + (app.webAppVersion) + "/" + resource);
|
|
11
17
|
}
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Renders a Underscore template and returns a string.
|
|
21
|
+
* @param {String} template Underscore template.
|
|
22
|
+
* @param {Object} [values={}] Values.
|
|
23
|
+
* @returns {String} Rendered template
|
|
24
|
+
*/
|
|
13
25
|
export function renderTemplate(template, values) {
|
|
14
26
|
if ( values === void 0 ) values = {};
|
|
15
27
|
|
|
@@ -19,6 +31,13 @@ export function renderTemplate(template, values) {
|
|
|
19
31
|
return _.template(template)(values);
|
|
20
32
|
}
|
|
21
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Get HTML for rendering a Vue application.
|
|
36
|
+
* @param {String} name Name of the app, has to match the name of the Vue application.
|
|
37
|
+
* @param {Object} data Data that will be available in `$options`.
|
|
38
|
+
* @param {String} [noScript=''] HTML that will be printed when JavaScript is not available.
|
|
39
|
+
* @returns {String} HTML for rendering a Vue application.
|
|
40
|
+
*/
|
|
22
41
|
export function renderVue(name, data, noScript) {
|
|
23
42
|
if ( noScript === void 0 ) noScript = '';
|
|
24
43
|
|
|
@@ -29,6 +48,11 @@ export function renderVue(name, data, noScript) {
|
|
|
29
48
|
return html;
|
|
30
49
|
}
|
|
31
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Get URI for a route.
|
|
53
|
+
* @param {String} route A route.
|
|
54
|
+
* @returns {String} URI for route.
|
|
55
|
+
*/
|
|
32
56
|
export function getRouteUri(route) {
|
|
33
57
|
var currentPortlet = PortletContextUtil.getCurrentPortlet();
|
|
34
58
|
if (currentPortlet) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"author": "Soleil AB",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"private": false,
|
|
8
|
+
"homepage": "https://github.com/soleilit/server-monorepo/tree/master/packages/app-util",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"build": "npx buble ./src/index.js --output ./dist/index.js --no modules --objectAssign=Object.assign"
|
|
10
11
|
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"underscore": "^1.9.1"
|
|
14
|
+
},
|
|
11
15
|
"dependencies": {},
|
|
12
16
|
"devDependencies": {}
|
|
13
17
|
}
|
package/src/index.js
CHANGED
|
@@ -4,12 +4,24 @@ import VersionUtil from 'VersionUtil';
|
|
|
4
4
|
import app from 'app';
|
|
5
5
|
import _ from 'underscore';
|
|
6
6
|
|
|
7
|
+
/** If the webapp is running in offline mode or not. */
|
|
7
8
|
export const isOffline = VersionUtil.getCurrentVersion() === VersionUtil.OFFLINE_VERSION;
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Get URI for a resource.
|
|
12
|
+
* @param {String} resource A resource.
|
|
13
|
+
* @returns {String} URI for a resource.
|
|
14
|
+
*/
|
|
9
15
|
export function getResourceUri(resource) {
|
|
10
16
|
return `/webapp-files/${app.webAppId}/${app.webAppVersion}/${resource}`;
|
|
11
17
|
}
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Renders a Underscore template and returns a string.
|
|
21
|
+
* @param {String} template Underscore template.
|
|
22
|
+
* @param {Object} [values={}] Values.
|
|
23
|
+
* @returns {String} Rendered template
|
|
24
|
+
*/
|
|
13
25
|
export function renderTemplate(template, values = {}) {
|
|
14
26
|
if (typeof template === 'function') {
|
|
15
27
|
return template(values);
|
|
@@ -17,6 +29,13 @@ export function renderTemplate(template, values = {}) {
|
|
|
17
29
|
return _.template(template)(values);
|
|
18
30
|
}
|
|
19
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Get HTML for rendering a Vue application.
|
|
34
|
+
* @param {String} name Name of the app, has to match the name of the Vue application.
|
|
35
|
+
* @param {Object} data Data that will be available in `$options`.
|
|
36
|
+
* @param {String} [noScript=''] HTML that will be printed when JavaScript is not available.
|
|
37
|
+
* @returns {String} HTML for rendering a Vue application.
|
|
38
|
+
*/
|
|
20
39
|
export function renderVue(name, data, noScript = '') {
|
|
21
40
|
const options = { webapp: app, isOffline, ...data };
|
|
22
41
|
|
|
@@ -30,6 +49,11 @@ export function renderVue(name, data, noScript = '') {
|
|
|
30
49
|
return html;
|
|
31
50
|
}
|
|
32
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Get URI for a route.
|
|
54
|
+
* @param {String} route A route.
|
|
55
|
+
* @returns {String} URI for route.
|
|
56
|
+
*/
|
|
33
57
|
export function getRouteUri(route) {
|
|
34
58
|
const currentPortlet = PortletContextUtil.getCurrentPortlet();
|
|
35
59
|
if (currentPortlet) {
|