@soleil-se/app-util 2.1.3 → 2.2.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/CHANGELOG.md +3 -0
- package/README.md +29 -1
- package/package.json +1 -1
- package/src/index.js +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [2.1.4] - 2020-04-07
|
|
8
|
+
### Fixed
|
|
9
|
+
- `getViewUri` had incorrect portlet ID.
|
|
7
10
|
## [2.1.3] - 2020-02-25
|
|
8
11
|
### Fixed
|
|
9
12
|
- Add timestamp to script url in edit mode as well.
|
package/README.md
CHANGED
|
@@ -123,7 +123,8 @@ Get URI for a resource.
|
|
|
123
123
|
const resourceUri = getResourceUri('file/in/resource.png');
|
|
124
124
|
```
|
|
125
125
|
### `renderTemplate(template, [values])` ⇒ `String`
|
|
126
|
-
Renders a Underscore template and returns a string.
|
|
126
|
+
Renders a Underscore template and returns a string.
|
|
127
|
+
This function is also available inside the template.
|
|
127
128
|
|
|
128
129
|
**Returns**: `String` - Rendered template
|
|
129
130
|
|
|
@@ -133,11 +134,38 @@ Renders a Underscore template and returns a string.
|
|
|
133
134
|
| [values] | `Object` | `{}` | Values. |
|
|
134
135
|
|
|
135
136
|
#### Example
|
|
137
|
+
**Simple example**
|
|
136
138
|
```javascript
|
|
137
139
|
const string = renderTemplate('<div><%= foo %></div>', {
|
|
138
140
|
foo: 'bar',
|
|
139
141
|
});
|
|
140
142
|
```
|
|
143
|
+
**Multiple templates**
|
|
144
|
+
```html
|
|
145
|
+
/* views/item.html */
|
|
146
|
+
<li>
|
|
147
|
+
<%- name %>
|
|
148
|
+
</li>
|
|
149
|
+
```
|
|
150
|
+
```html
|
|
151
|
+
/* views/main.html */
|
|
152
|
+
<ul>
|
|
153
|
+
<% items.forEach(function(item) { %>
|
|
154
|
+
<%= renderTemplate(itemTemplate, item) %>
|
|
155
|
+
<% }); %>
|
|
156
|
+
</ul>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
import { renderTemplate } from '@soleil-se/webapp-util';
|
|
161
|
+
import mainTemplate from './views/main.html';
|
|
162
|
+
import itemTemplate from './views/item.html';
|
|
163
|
+
|
|
164
|
+
const items = [{ name: 'Foo' }, { name: 'Bar' }, { name: 'Baz' }];
|
|
165
|
+
const string = renderTemplate(mainTemplate, { items, itemTemplate });
|
|
166
|
+
```
|
|
167
|
+
> **NOTE**
|
|
168
|
+
> Remember that the second argument must be an object and that objects properties are accessed directly in any child templates!
|
|
141
169
|
### `isOffline`
|
|
142
170
|
If the webapp is running in offline mode or not.
|
|
143
171
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -31,9 +31,9 @@ export function getResourceUri(resource) {
|
|
|
31
31
|
*/
|
|
32
32
|
export function renderTemplate(template, values = {}) {
|
|
33
33
|
if (typeof template === 'function') {
|
|
34
|
-
return template(values);
|
|
34
|
+
return template({ ...values, renderTemplate });
|
|
35
35
|
}
|
|
36
|
-
return _.template(template)(values);
|
|
36
|
+
return _.template(template)(({ ...values, renderTemplate }));
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -103,7 +103,8 @@ export function getRouteUri(route) {
|
|
|
103
103
|
*/
|
|
104
104
|
export function getViewUri(route) {
|
|
105
105
|
const currentPageUri = PropertyUtil.getString(PortletContextUtil.getCurrentPage(), 'URI');
|
|
106
|
-
|
|
106
|
+
const currentPortletId = PortletContextUtil.getCurrentPortlet().getIdentifier();
|
|
107
|
+
return `${currentPageUri}?sv.target=${currentPortletId}&sv.${currentPortletId}.route=${encodeURI(route)}`;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
export default {
|