Skip to content

Instantly share code, notes, and snippets.

@jakerb
Created October 9, 2015 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakerb/7d4893b723b09a55afdd to your computer and use it in GitHub Desktop.
Save jakerb/7d4893b723b09a55afdd to your computer and use it in GitHub Desktop.
Suited is JS library for rendering websites and apps.
/* Example Tasche Application */
tasche.init("tasche.json");
tasche.page("about", {
fullWidthHeader: {
header: "An About Page",
subheader: "Welcome to this page",
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit sint quasi explicabo!"
},
textPost: {
header: "An About Page",
subheader: "Welcome to this page",
body: "Lorem ipsum dolor sit amet, consectetur adipisicing elit sint quasi explicabo!"
}
});
tasche.run();
<!-- fullWidthHeader Component -->
<div class="fullWidthHeader">
<p>{{header}}</p>
</div>
<!-- fullWidthHeader Component -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A Suited Example</title>
</head>
<body>
<div class="tasche-page" data-tasche-page="index" data-tasche-require="fullWidthHeader, subscribeBar, textPost"></div>
<div class="tasche-page" data-tasche-page="about" data-tasche-require="fullWidthHeader, textPost"></div>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="tasche.js"></script>
<script src="app.js"></script>
</body>
</html>
<!-- subscribeBar Component -->
<div class="subscribeBar"></div>
<!-- subscribeBar Component -->
/*
* Created by Jake Bown (@jakebown1)
* For support, see my Github (https://github.com/jakerb)
* Feel free to drop me a line at jake@jakebown.com
* Suited.js has been built out of Tasche.js (also by me)
*/
var object = {};
var appData = {};
var tasche = {
init:function(config) {
var that = this;
if(config) {
appData = that.newApp(config);
console.log(appData);
} else {
console.warn("Not config found");
}
},
run:function() {
var that = this;
$('.tasche-page').each(function() {
var elem = $(this);
var page = elem.data('tasche-page');
var req = elem.data('tasche-require');
req = req.split(',')
for (var i = req.length - 1; i >= 0; i--) {
req[i] = req[i].replace(' ', '');
if(appData.components[req[i]] && appData.pages[page][req[i]]) {
that.render({template: appData.views + appData.components[req[i]], data: appData.pages[page][req[i]], element: page});
}
};
});
},
newApp:function(config) {
var tmp = null;
$.ajax({
url: config,
async: false,
dataType: "json",
success: function(app) {
tmp = app.tasche;
},
});
return tmp;
},
render:function(tasche, callback) {
var page;
var that = this;
$.ajax({
url: tasche.template,
success: function(html) {
var view = $('div[data-tasche-page="' + tasche.element + '"]');
view.html(view.html() + that.process(html, tasche.data, callback));
},
dataType: "html"
});
},
page:function(a, b) {
appData.pages[a] = b;
},
process:function(html, tasche, callback) {
find = html.match(/([^}{]+)(?=})/g);
var page;
if (find != null && find.length > 0) {
console.log(tasche);
$.each(tasche, function(k, v) {
html = html.replace("{{"+k+"}}", v);
});
}
if(callback) { callback(); }
return html;
}
}
{
"tasche": {
"app": "Demo Application",
"author": "Jake Bown",
"email": "jakebown@gmail.com",
"views": "",
"components": {
"fullWidthHeader": "fullWidthHeader.html",
"subscribeBar": "subscribeBar.html",
"textPost": "textPost.html"
},
"pages": {
"index": {
"fullWidthHeader": {
"header": "Hello World",
"subheader": "All your base are belong to us.",
"intro": "Welcome to this example"
},
"subscribeBar": {
"header": "Subscribe Now",
"email": "sameple@gmail.com",
"action": "/post/to/form"
},
"textPost": {
"header": "A simple text post",
"body": "Lorem ipsum dolor sit amet, consectetur adipisicing elit sint quasi explicabo!"
}
}
}
}
}
<!-- textPost Component -->
<div class="textPost"></div>
<!-- textPost Component -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment