-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Template: add webclip template engine
[Issue] n/a [Problem] Templates are not implemented yet [Solution] - add template engine using Mustache templates - update webclips card according to template system Signed-off-by: Tomasz Lukawski <[email protected]>
- Loading branch information
1 parent
e3b364d
commit a1f9c32
Showing
22 changed files
with
380 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
examples/mobile/UIComponents/webclip/link-tab-template/css/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.test { | ||
font-size: 10px; | ||
} |
Binary file added
BIN
+91.9 KB
examples/mobile/UIComponents/webclip/link-tab-template/images/thumbnail_013.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
...bile/UIComponents/webclip/link-tab-template/images/tw_list_icon_connections.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
examples/mobile/UIComponents/webclip/link-tab-template/js/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/*global tau */ | ||
(function () { | ||
tau.log("app.js: template script"); | ||
})(); |
101 changes: 101 additions & 0 deletions
101
examples/mobile/UIComponents/webclip/link-tab-template/webclip.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<div class="ui-card ui-card-service"> | ||
<link data-template-rel="origin" href="css/style.css" rel="stylesheet" /> | ||
<script data-template-rel="origin" src="js/app.js"></script> | ||
<div class="ui-header"> | ||
<div class="ui-title">{{title}}</div> | ||
<div class="ui-icon app-icon"></div> | ||
<div class="ui-controls"> | ||
<button data-icon="down"></button> | ||
<button data-icon="reorder"></button> | ||
</div> | ||
</div> | ||
<div class="ui-content ui-tabs" style="height: 215px;"> | ||
<div class="ui-sub-tab ui-sub-tab-static"> | ||
<ul> | ||
<li class="ui-li-anchor"> | ||
<a class="ui-tab-active" href="#"> | ||
One | ||
</a> | ||
</li> | ||
<li class="ui-li-anchor"> | ||
<a href="#"> | ||
Two | ||
</a> | ||
</li> | ||
<li class="ui-li-anchor"> | ||
<a href="#"> | ||
Three | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="ui-section-changer"> | ||
<div> | ||
<section class="ui-content ui-section-active"> | ||
<ul class="ui-listview ui-content-area"> | ||
<li class="ui-li-divider"> | ||
<div class="ui-li-text"> | ||
<span class="ui-li-text-title"> | ||
Main text 01 | ||
</span> | ||
<span class="ui-li-text-sub ui-li-text-value"> | ||
Value text | ||
</span> | ||
</div> | ||
</li> | ||
<li class="ui-li-divider"> | ||
<div class="ui-li-text"> | ||
<span class="ui-li-text-title"> | ||
Main text 02 | ||
</span> | ||
</div> | ||
</li> | ||
</ul> | ||
</section> | ||
<section class="ui-content"> | ||
<ul class="ui-listview ui-content-area"> | ||
{{#images}} | ||
<li class="ui-li-has-icon ui-li-divider"> | ||
<div class="ui-li-icon"> | ||
<img data-template-rel="origin" src="{{img}}"/> | ||
</div> | ||
<div class="ui-li-text"> | ||
<span class="ui-li-text-title"> | ||
Main text 01 | ||
</span> | ||
<span class="ui-li-text-sub"> | ||
Subtitle on list item | ||
</span> | ||
</div> | ||
</li> | ||
{{/images}} | ||
</ul> | ||
</section> | ||
<section class="ui-content"> | ||
<ul class="ui-listview ui-content-area"> | ||
<li class="ui-li-divider"> | ||
<div class="ui-li-text"> | ||
<span class="ui-li-text-title"> | ||
Main text 03 | ||
</span> | ||
<span class="ui-li-text-sub"> | ||
Subtitle on list item | ||
</span> | ||
</div> | ||
</li> | ||
<li> | ||
<div class="ui-li-text"> | ||
<span class="ui-li-text-title"> | ||
Main text 04 | ||
</span> | ||
</div> | ||
</li> | ||
</ul> | ||
</section> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="ui-footer"> | ||
<button data-inline="true" data-action="{{action.main.name}}">View more</button> | ||
</div> | ||
</div> |
3 changes: 3 additions & 0 deletions
3
examples/mobile/UIComponents/webclip/link-video-template/css/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.test { | ||
font-size: 10px; | ||
} |
6 changes: 6 additions & 0 deletions
6
examples/mobile/UIComponents/webclip/link-video-template/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"video": "https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4", | ||
"actionText": "View More", | ||
"title": "Title", | ||
"description": "description" | ||
} |
4 changes: 4 additions & 0 deletions
4
examples/mobile/UIComponents/webclip/link-video-template/js/app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/*global tau */ | ||
(function () { | ||
tau.log("app.js: template script"); | ||
})(); |
17 changes: 17 additions & 0 deletions
17
examples/mobile/UIComponents/webclip/link-video-template/webclip.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
`<div class="ui-card ui-card-ads"> | ||
<link href="css/style.css" rel="stylesheet" /> | ||
<div class="ui-content"> | ||
<script src="js/app.js"></script> | ||
<video src="{{video}}" id="video" style="width: 100%;"></video> | ||
<div class="ui-title">{{title}}</div> | ||
<div class="ui-subtitle">{{description}}</div> | ||
<script> | ||
document.getElementById("video").addEventListener("click", function () { | ||
this.play(); | ||
}); | ||
</script> | ||
</div> | ||
<div class="ui-footer"> | ||
<button data-inline="true">{{actionText}}</button> | ||
</div> | ||
</div>` |
3 changes: 3 additions & 0 deletions
3
examples/mobile/UIComponents/webclip/link-video/css/style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.test { | ||
font-size: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/*global tau */ | ||
(function () { | ||
tau.log("app.js: template script"); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+91.9 KB
examples/mobile/UIComponents/webclip/template-base-path/images/thumbnail_013.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions
17
...ile/UIComponents/webclip/template-base-path/images/tw_list_icon_connections.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
templateFunctions = {}, | ||
globalOptions = { | ||
"pathPrefix": "", | ||
"default": "" | ||
"default": "html" | ||
}; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*global define, ns, Mustache*/ | ||
|
||
/** | ||
* #HTML template engine | ||
* | ||
* Parser for HTML files. | ||
* | ||
* This class hasn't public interface. This class is registered as template engine | ||
* in template manager. | ||
* | ||
* This engine give support of load HTML(Webclip) files for give URL. | ||
* | ||
* @class ns.template.webclip | ||
* @author Tomasz Lukawski <[email protected]> | ||
*/ | ||
(function () { | ||
"use strict"; | ||
//>>excludeStart("tauBuildExclude", pragmas.tauBuildExclude); | ||
define( | ||
[ | ||
"../template", | ||
"../util/path" | ||
], | ||
function () { | ||
//>>excludeEnd("tauBuildExclude"); | ||
var template = ns.template; | ||
|
||
function fillMarkup(text, data) { | ||
if (Mustache) { | ||
return Mustache.render(text, data); | ||
} else { | ||
ns.warn("Mustache library is required (https://github.com/janl/mustache.js)"); | ||
} | ||
} | ||
|
||
/** | ||
* Callback for event load and error on XMLHttpRequest | ||
* @param {Function} callback Function called after parse response | ||
* @param {Object} data Data passed to render function | ||
* @param {Event} event event object | ||
*/ | ||
function callbackFunction(callback, data, event) { | ||
var request = event.target, | ||
status = {}, | ||
text, | ||
doc, | ||
element; | ||
|
||
if (request.readyState === 4) { | ||
status.success = (request.status === 200 || (request.status === 0 && request.responseXML)); | ||
text = request.responseText; | ||
|
||
text = fillMarkup(text, data); | ||
doc = document.implementation.createHTMLDocument("for-create-webclip-elements"); | ||
element = doc.createElement("div"); | ||
element.innerHTML = text; | ||
|
||
element = element.firstElementChild; | ||
element.parentElement.removeChild(element); | ||
element.setAttribute("data-template-html", encodeURI(request.responseText)); | ||
callback(status, element); | ||
} | ||
} | ||
|
||
/** | ||
* Function process given path, get file by XMLHttpRequest and return | ||
* HTML element. | ||
* @param {Object} globalOptions | ||
* @param {string} path | ||
* @param {Object} data | ||
* @param {Function} callback | ||
*/ | ||
function webclipTemplate(globalOptions, path, data, callback) { | ||
var absUrl = path, | ||
request, | ||
eventCallback = callbackFunction.bind(null, callback, data); | ||
|
||
// Load the new content. | ||
request = new XMLHttpRequest(); | ||
request.responseType = "text"; | ||
request.overrideMimeType("text/html"); | ||
request.open("GET", absUrl); | ||
request.addEventListener("error", eventCallback); | ||
request.addEventListener("load", eventCallback); | ||
request.send(); | ||
} | ||
|
||
template.register("webclip", webclipTemplate); | ||
//>>excludeStart("tauBuildExclude", pragmas.tauBuildExclude); | ||
} | ||
); | ||
//>>excludeEnd("tauBuildExclude"); | ||
}()); |
Oops, something went wrong.