Lettuce是一个小的(~6kb)、强大的移动开发框架 for Romantic.
在线演示 http://phodal.github.io/lettuce.
Usage(用法)
Class(类)
javascript
var L = new lettuce(); var zero = function(){ }; var sub = new L.Class(zero);
Template(模板)
javascript
var L = new lettuce(); var data = { "title": "JavaScript Templates" }; var result = L.Template.tmpl("
{%=o.title%}
\n!@#$%^&*()-=", data);
Router(路由)
javascript
var L = new lettuce(); var check = L.Router .add(/#about/,log) .add(/#what/, log) .add(/#why/, log) .load();;
Promise
javascript
function late(n) { var L = new lettuce(); var p = new L.Promise(); return p; } late(100).then( ).then( ).done();
Ajax
javascript
lettuce.get('/bower.json', function(result){ equal(result["name"], "lettuce"); done(); })
javascript
lettuce.post("http://127.0.0.1:5000/some", "something", function(data){ console.log(data) })
Single Page Application Example(单页面应用)
1.创建实例
javascript
var L = new lettuce();
2.定义数据
javascript
var data = { about: "Template", what: "This about A Mobile Framework For Romantic", why: "Why is a new Framework" };
3.创建路由函数
javascript
var aboutPage = function(){ var aboutPage = new L.SimpleView(); var templates = L.Template.tmpl("
{%=o.about%}
", data); return aboutPage.render(templates, "results"); }; var whyPage = function(){ var whyPage = new L.SimpleView(); var templates = L.Template.tmpl("{%=o.why%}
", data); return whyPage.render(templates, "results"); }; var whatPage = function(){ var whatPage = new L.SimpleView(); var templates = L.Template.tmpl("{%=o.what%}
", data); return whatPage.render(templates, "results"); };
4.添加路由
javascript
L.Router .add(/#about/, about) .add(/#what/, what) .add(/#why/, why) .load();
示例
http://valentine.phodal.com/
http://lettuce.phodal.com/
其他
Github: https://github.com/phodal/lettuce
待我代码编成,娶你为妻可好