Closed shuhaowu closed 12 years ago
Hi, this is weird, which version are you using?
I've tested right now and everything worked fine for me.
[15:30][nybras@nybras:/code]$ toaster -n simple_methods
Let's toast something fresh! :)
. With this as your basepath: /code/simple_methods
. Please tell me:
Where do you want your src folder? [src] :
Where do you want your release file? [www/js/app.js] :
Starting from your webroot '/', what's the folderpath to reach your release file? (i.e. javascript) (optional) :
Created /code/simple_methods
Created /code/simple_methods/src
Created /code/simple_methods/vendors
Created /code/simple_methods/www/js
Created /code/simple_methods/toaster.coffee
[15:30][nybras@nybras:/code]$ cd simple_methods/
[15:30][nybras@nybras:/code/simple_methods]$ echo "limit = (low, value, high) -> Math.max(low, Math.min(value, high))" >> src/main.coffee
[15:31][nybras@nybras:/code/simple_methods]$ toaster -wd
Compiled /code/simple_methods/www/js/app.js @ 15:31:3
Compiled /code/simple_methods/www/js/app-debug.js @ 15:31:3
[15:31][nybras@nybras:/code/simple_methods]$ cat www/js/app.js
var __t;
__t = function(ns) {
var curr, index, part, parts, _i, _len;
curr = null;
parts = [].concat = ns.split(".");
for (index = _i = 0, _len = parts.length; _i < _len; index = ++_i) {
part = parts[index];
if (curr === null) {
curr = eval(part);
continue;
} else {
if (curr[part] == null) {
curr = curr[part] = {};
} else {
curr = curr[part];
}
}
}
return curr;
};
(function() {
var limit;
limit = function(low, value, high) {
return Math.max(low, Math.min(value, high));
};
}).call(this);
Please, update to 0.6.2 and let me know if anything goes wrong for you, so I reopen this issue and we keep investigating the reason.
Thank you.
I have my directory as:
myapp/src/math/commons.coffee
I'm expecting that the function limit to be automatically put in to the math object, so when i call it from other places, it would be math.limit
Hi, currently you will have to work with classes to gain the benefits of the toaster packaging system.
In this case I bet you'll use static methods in a class, like:
# myapp/src/math.coffee
class math
@limit:( low, value, high ) -> Math.max low, ( Math.min value, high )
Anyway I'll check how to implement it in the current context and see if there's any drawbacks on doing this.
Thank you for the idea. :)
Yeah, i'm just doing math.limit = (low, value, high)
Functions in modules are definitely very useful indeed.
Also a separate suggestions is that instead of wrapping everything into an object for these functions, compile these functions like math_limit = function(low, value, high)
. Reason being that this is actually faster than object look ups in JavaScript. (See closure compiler..)
Only classes are included in the modules, functions are not..
Try under math/math.coffee
You have to do
math.limit = ....