Skip to content

Commit

Permalink
Skeleton start
Browse files Browse the repository at this point in the history
  • Loading branch information
pointful-mikkel committed Jan 19, 2015
1 parent d89c5d9 commit 221dff7
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 4 deletions.
18 changes: 16 additions & 2 deletions bin/miso.bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ try {
});
});

} else if(argv.n) {
} else if(argv.n || argv.s) {
// Check for absolute path
if(argv.n.indexOf("/") !== 0) {
projectPath = userPath + "/" + argv.n;
Expand All @@ -79,11 +79,25 @@ try {
if(!fs.existsSync(projectPath)) {
console.log("Create new project: '" +argv.n + "'...");
fs.mkdirSync(projectPath);

// TODO: We want to exclude ["bin", "skeletons"]
fs.copySync(misoPath, projectPath);

console.log("Project successfully created.");
} else {
console.log("Project already exists:", argv.n, "use -u to update");
}


// We can also apply a skeleton when creating a new project
if(argv.s) {

}





} else {
// Show the help screen
var helpText = [
Expand All @@ -93,7 +107,7 @@ try {
"Commands:",
" -? Shows help for a particular command, eg: '"+name+" -? n' shows help for creating a new project",
" -n Create a new project",
//" -u Update a project to the current version",
" -s Create a skeleton app, valid skeletons: 'todo'",
" run Runs the project in the current directory"
];
_.each(helpText, function(txt){
Expand Down
2 changes: 1 addition & 1 deletion client/miso.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports.index = {
var t = ctrl.model;
return [
m.e("style", ".done{text-decoration: line-through;}"),
m.e("h1", "Mithril bindings Todos - " + t.left() + " of " + t.todos().length + " remaining"),
m.e("h1", "Todos - " + t.left() + " of " + t.todos().length + " remaining"),
m.e("button", { onclick: t.archive }, "Archive"),
m.e("ul", [
t.todos().map(function(todo, idx){
Expand Down
2 changes: 1 addition & 1 deletion mvc/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports.index = {
var t = ctrl.model;
return [
m.e("style", ".done{text-decoration: line-through;}"),
m.e("h1", "Mithril bindings Todos - " + t.left() + " of " + t.todos().length + " remaining"),
m.e("h1", "Todos - " + t.left() + " of " + t.todos().length + " remaining"),
m.e("button", { onclick: t.archive }, "Archive"),
m.e("ul", [
t.todos().map(function(todo, idx){
Expand Down
91 changes: 91 additions & 0 deletions skeletons/todo/mvc/todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
var m = require('mithril'),
miso = require('../server/miso.util.js'),
store = require('../server/store.js')(this),
bindings = require('../server/mithril.bindings.node.js')(m);

// Basic todo app
module.exports.index = {
model: function() {
var self = this;
self.todos = m.p([
{ text: "learn mithril", done: m.p(true) },
{ text: "build a mithril app", done: m.p(false) }
]);
self.input = m.p("");
self.left = function(){
var count = 0;
self.todos().map(function(todo) {
count += todo.done() ? 0 : 1;
});
return count;
};
self.archive = function(){
var list = [];
self.todos().map(function(todo) {
if(!todo.done()) { list.push(todo); }
});
self.todos(list);
};
},
controller: function(params) {
var ctrl = this;

var model = this.model = new function() {
var self = this;
self.todos = m.p([
{ text: "learn mithril", done: m.p(true) },
{ text: "build a mithril app", done: m.p(false) }
]);
self.input = m.p("");
self.left = function(){
var count = 0;
self.todos().map(function(todo) {
count += todo.done() ? 0 : 1;
});
return count;
};
self.archive = function(){
var list = [];
self.todos().map(function(todo) {
if(!todo.done()) { list.push(todo); }
});
self.todos(list);
};
}();

this.addTodo = function(){
var value = model.input();
if(value) {
console.log('add', value);
// Using bindings model push for arrays
model.todos.push({text: model.input(), done: m.p(false)});
model.input("");
store.save('user', model);
}
return false;
};

store.load('todo', 1).then(function(loadedTodos) {
console.log('loadedTodos', loadedTodos);
});

return this;
},
view: function(ctrl) {
var t = ctrl.model;
return [
m.e("style", ".done{text-decoration: line-through;}"),
m.e("h1", "Todos - " + t.left() + " of " + t.todos().length + " remaining"),
m.e("button", { onclick: t.archive }, "Archive"),
m.e("ul", [
t.todos().map(function(todo, idx){
return m.e("li", { class: todo.done()? "done": "", toggle: todo.done }, todo.text);
})
]),
m.e("form", { onsubmit: ctrl.addTodo }, [
m.e("input", { type: "text", value: t.input, placeholder: "Add todo"}),
m.e("button", { type: "submit"}, "Add")
])
];
}
};

0 comments on commit 221dff7

Please sign in to comment.