|
|
$ curl https://install.meteor.com | /bin/sh
$ meteor create myapp
$ cd myapp
$ meteor
=> Meteor server running on: http://localhost:3000/
if (Meteor.isClient) {
someFunction = function() {
// your code goes here
};
...
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
...
}
/myapp/...
/myapp/lib/...
/myapp/somefolder/...
/myapp/server/lib/...
/myapp/server/someLib.js
/myapp/server/main.js
/myapp/client/lib/...
/myapp/client/someLib.js
/myapp/client/main.js
/myapp/public/...
/myapp/test/...
Messages = new Meteor.Collection("messages");
Messages.find();
Messages.findOne();
Messages.insert();
Messages.update();
Messages.remove();
...
// server: publish the messages collection
Meteor.publish("messages", function () {
return Messages.find();
});
// client: subscribe to the published messages
Meteor.subscribe("messages");
Meteor.methods({
foo: function (arg1, arg2) {
// .. do stuff ..
if (you want to throw an error)
throw new Meteor.Error(404, "Can't find my pants");
return "some return value";
},
bar: function () {
// .. do other stuff ..
return "baz";
}
});
// async call
Meteor.call('foo', 1, 2, function (error, result) { ... } );
// sync call
var result = Meteor.call('foo', 1, 2);
$ meteor add accounts-ui
$ meteor add accounts-*
* = password, facebook, twitter, google, github, ...
OAuth2
{{> login-buttons}}
Messages.allow({
insert: function (userId, msg) {
// only logged-in users can insert a new message that they own
return (userId && msg.owner == userId);
},
fetch: ['owner']
});
Messages.deny({
remove: function (userId, msg) {
//can't remove locked messages
return msg.locked;
},
fetch: ['locked']
});
<head>
<title>myapp</title>
</head>
<body>
{{> hello}}
</body>
<template name="hello">
<h1>Hello World!</h1>
{{greeting}}
<input type="button" value="click" />
</template>
Template.hello.greeting = function() {
return Session.get("welcome_message");
};
// somewhere in the code...
Session.set("welcome_message", "Welcome to myapp.");
$ meteor deploy myapp.meteor.com
$ meteor deploy www.myapp.com
$ meteor bundle myapp.tgz
<!-- app.html -->
<body>
{{>postList}}
</body>
<template name="postList">
<h1>Post List</h1>
<ul>
{{#each posts}}
<li>{{title}}</li>
{{/each}}
</ul>
</template>
// app.js
Posts = new Meteor.Collection('posts');
if(Meteor.isClient) {
Template.postList.posts = function () {
return Posts.find();
};
}
// body content
var bodyContent = Template.__body__.__contentParts;
bodyContent.push(Blaze.View('body_content_'+ bodyContent.length, (function() {
var view = this;
return [
Spacebars.include(view.lookupTemplate("postList"))
];
})));
// loading body when page loaded
Meteor.startup(Template.__body__.__instantiate);
// postList template
Template.__define__(postList, (function() {
var view = this;
return [
HTML.Raw("<h1>Post List</h1>\n "),
HTML.UL("\n ", Blaze.Each(function() {
return Spacebars.call(view.lookup("posts"));
},
function() {
return [ "\n ", HTML.LI(Blaze.View(function() {
return Spacebars.mustache(view.lookup("title"));
})), "\n " ];
}), "\n ")
];
}));
Package.on_test(function (api) {
api.use(['meteor-file', 'tinytest', 'test-helpers'], ['client', 'server']);
api.add_files('meteor-file-test.js', ['client', 'server']);
});
Tinytest.add('MeteorFile - read', function (test) {
test.equal(1, 1, 'Expected values to be equal');
var obj = null;
test.isNull(obj, 'Expected object to be null');
});
> cd packages/meteor-file
> meteor test-packages ./
Posts = new Meteor.Collection('posts');
var assert = require('assert');
suite('Posts', function() {
test('in the server', function(done, server) {
server.eval(function() {
Posts.insert({title: 'hello title'});
var docs = Posts.find().fetch();
emit('docs', docs);
});
server.once('docs', function(docs) {
assert.equal(docs.length, 1);
done();
});
});
});
(process.env.NODE_ENV === "development")
JSFiddle for Meteor