-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathhandlebars-helpers.htm
More file actions
198 lines (186 loc) · 8.38 KB
/
handlebars-helpers.htm
File metadata and controls
198 lines (186 loc) · 8.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>DataFormsJS - Samples - Strings and Dates</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<style>
/* Offset the body contents */
body { margin-top:50px; }
</style>
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="https://www.dataformsjs.com/">DataFormsJS</a></li>
<li><a href="https://www.dataformsjs.com/en/examples">All Examples</a></li>
</ul>
</div>
</div>
</div>
<div class="container text-center">
<div class="center-block" style="max-width: 400px;">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td><input id="name" class="form-control" placeholder="Enter your name" value="World" /></td>
</tr>
<tr>
<td><input id="date" class="form-control" placeholder="Enter a date" /></td>
</tr>
<tr>
<td><input id="date2" class="form-control" placeholder="Enter a date" /></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Container where the page is rendered -->
<div class="container" id="view"></div>
<!-- Template -->
<script id="view-template" type="text/x-template" data-engine="handlebars">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Expression</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>\{{format "Hello {0}" name}}</td>
<td>{{format "Hello {0}" name}}</td>
</tr>
<tr>
<td>\{{now}}</td>
<td>{{now}}</td>
</tr>
<tr>
<td>\{{moment (now) "YYYY.MM.DD"}}</td>
<td>{{moment (now) "YYYY.MM.DD"}}</td>
</tr>
<tr>
<td>\{{moment "MMMM Do YYYY, h:mm:ss A"}}</td>
<td>{{moment "MMMM Do YYYY, h:mm:ss A"}}</td>
</tr>
<tr>
<td>\{{moment date "MMMM Do YYYY"}}</td>
<td>{{moment date "MMMM Do YYYY"}}</td>
</tr>
<tr>
<td>\{{formatDate date}}</td>
<td>{{formatDate date}}</td>
</tr>
<tr>
<td>\{{formatDateTime date}}</td>
<td>{{formatDateTime date}}</td>
</tr>
<tr>
<td>\{{formatTime date}}</td>
<td>{{formatTime date}}</td>
</tr>
<tr>
<td>\{{formatDate date2}}</td>
<td>{{formatDate date2}}</td>
</tr>
<tr>
<td>\{{formatDateTime date2}}</td>
<td>{{formatDateTime date2}}</td>
</tr>
<tr>
<td>\{{formatTime date2}}</td>
<td>{{formatTime date2}}</td>
</tr>
<tr>
<td>\{{formatDate (now)}}</td>
<td>{{formatDate (now)}}</td>
</tr>
<tr>
<td>\{{formatDateTime (now)}}</td>
<td>{{formatDateTime (now)}}</td>
</tr>
<tr>
<td>\{{formatTime (now)}}</td>
<td>{{formatTime (now)}}</td>
</tr>
<tr>
<td>\{{format "Hello {0}, Today is {1}" name (now)}}</td>
<td>{{format "Hello {0}, Today is {1}" name (now)}}</td>
</tr>
<tr>
<td>\{{format "Today is {0}" (moment date "YYYY.MM.DD")}}</td>
<td>{{format "Today is {0}" (moment date "YYYY.MM.DD")}}</td>
</tr>
<tr>
<td>\{{format "Hello {name}, Date entered is {date}"}}</td>
<td>{{format "Hello {name}, Date entered is {date}"}}</td>
</tr>
<tr>
<td>\{{concat "Hello" name}}</td>
<td>{{concat "Hello" name}}</td>
</tr>
<tr>
<td>\{{concat "Hello " name ", Date entered is " date}}</td>
<td>{{concat "Hello " name ", Date entered is " date}}</td>
</tr>
<tr>
<td>\{{join ", " "1" "2" "3" "4" "5"}}</td>
<td>{{join ", " "1" "2" "3" "4" "5"}}</td>
</tr>
</tbody>
</table>
</script>
<!-- Handlebars and DataFormsJS -->
<script src="https://cdn.jsdelivr.net/npm/handlebars@4.7.6/dist/handlebars.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.24.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/DataFormsJS.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/pages/jsonData.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/extensions/handlebars-helpers.min.js"></script>
<script>
/* Validates with [jshint] */
/* global app */
/* jshint strict: true */
(function () {
'use strict';
// Model for the page
function AppModel() {
this.name = null;
this.date = null;
this.date2 = null;
}
// Update Model with User Input
function UpdateModel() {
this.name = document.getElementById("name").value;
this.date = document.getElementById("date").value;
this.date2 = document.getElementById("date2").value;
}
// Refresh the view every one second after it is rendered
function RefreshPage() {
window.setTimeout(function () { app.updateView(); }, 1000);
}
// Run once the page is ready
document.addEventListener("DOMContentLoaded", function () {
// On page load update the input control with today's date
var d = new Date();
document.getElementById("date").value = d.toUTCString();
document.getElementById("date2").value = (d.toLocaleString !== undefined ? d.toLocaleString() : d.toString());
// Setup the App
app
.addModel("Data", new AppModel())
.addController({ path: "/", viewId: "view-template", modelName: "Data", onBeforeRender: UpdateModel, onRendered: RefreshPage })
.setup();
});
})();
</script>
</body>
</html>