@soleil-se/app-util 1.0.2 → 1.0.4

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 CHANGED
@@ -6,39 +6,66 @@
6
6
  ```javascript
7
7
  import { renderVue, getRouteUri, getResourceUri, renderTemplate, isOffline } from '@soleil-se/webapp-util';
8
8
  ```
9
- ### `renderVue`
10
- Prints bootstrap code for a Vue application.
11
- `name` has to match the name of the Vue application.
12
- `data` is an object that will be available in `$options`.
13
- `noScript` is a HTML-string that will be printed when JavaScript is not available.
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. |
19
+
14
20
  ```javascript
15
21
  router.get('/', (req, res) => {
16
22
  res.send(renderVue('AppName', data, noScript));
17
23
  });
18
24
  ```
19
- ### `getRouteUri`
20
- Get URI for a route.
25
+ ### `getRouteUri(route)` ⇒ `String`
26
+ Get URI for a route.
27
+
28
+ **Returns**: `String` - URI for route.
29
+
30
+ | Param | Type | Description |
31
+ | --- | --- | --- |
32
+ | route | `String` | A route. |
33
+
21
34
  ```javascript
22
35
  const routeUri = getRouteUri('/my-route');
23
36
  ```
24
- ### `getResourceUri`
37
+ ### `getResourceUri(resource)` ⇒ `String`
25
38
  Get URI for a resource.
39
+
40
+ **Returns**: `String` - URI for a resource.
41
+
42
+ | Param | Type | Description |
43
+ | --- | --- | --- |
44
+ | resource | `String` | A resource. |
45
+
26
46
  ```javascript
27
47
  const resourceUri = getResourceUri('file/in/resource.png');
28
48
  ```
29
- ### `renderTemplate`
30
- Renders a Underscore template to a string.
49
+ ### `renderTemplate(template, [values])` ⇒ `String`
50
+ Renders a Underscore template and returns a string.
51
+
52
+ **Returns**: `String` - Rendered template
53
+
54
+ | Param | Type | Default | Description |
55
+ | --- | --- | --- | --- |
56
+ | template | `String` | | Underscore template. |
57
+ | [values] | `Object` | `{}` | Values. |
58
+
31
59
  ```javascript
32
60
  const string = renderTemplate('<div><%= foo %></div>', {
33
61
  foo: 'bar',
34
62
  });
35
63
  ```
36
64
  ### `isOffline`
65
+ If the webapp is running in offline mode or not.
66
+
37
67
  ```javascript
38
68
  if(isOffline) {
39
69
  // Do something
40
70
  }
41
71
  ```
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.2",
3
+ "version": "1.0.4",
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) {