Skip to content
Browse files

Fixed a bunch of Meteor stuff:

- Cleaned up Meteor `package.js` file to fix `require("blade")` hacks. Should fix #144.
- Now considering `client/views` folder to be in the root namespace. Closes #143.
- Fixed view helpers. They can now be used just like view locals. Also closes #136.
Push to version 3.0.0beta8
  • Loading branch information...
1 parent 08b5622 commit a050d0d4096fcdf6ec99ce4abe5b5e52d9798f99 @bminer committed Mar 6, 2013
Showing with 36 additions and 21 deletions.
  1. +34 −19 meteor/package.js
  2. +1 −1 package.json
  3. +1 −1 smart.json
View
53 meteor/package.js
@@ -1,21 +1,28 @@
-var path = require('path');
+var path = require("path");
var blade;
//Hopefully, sometime soon I'll be able to get rid of this horrible hack...
-try {
- blade = require('blade')
-}
-catch(e) {
+function requireBlade(path, requireFunc) {
+ if(blade) return;
+ if(!requireFunc) requireFunc = require;
try {
- //XXX super lame! we actually have to give paths relative to
- // app/lib/packages.js, since that's who's evaling us.
- // The next line is for the core Meteor-installed package
- blade = require('../../packages/blade/node_modules/blade');
- }
- catch(e) {
- //XXX super lame! The next line is for the Meteorite-installed package
- blade = require(process.cwd() + "/.meteor/meteorite/packages/blade/node_modules/blade");
- }
+ blade = requireFunc(path);
+ } catch(e) {}
+};
+requireBlade("blade");
+//It's likely that `__meteor_bootstrap__` will go away
+if(global.__meteor_bootstrap__)
+{
+ requireBlade("blade", global.__meteor_bootstrap__.require);
+ requireBlade("../", global.__meteor_bootstrap__.require);
}
+// This block is for the core Meteor-installed package.
+// We actually have to give paths relative to
+// app/lib/packages.js, since that's who's evaling us.
+requireBlade("../../packages/blade/node_modules/blade");
+//The following lines should handle the Meteorite-installed package.
+requireBlade(process.cwd() + "/.meteor/meteorite/packages/blade/node_modules/blade");
+requireBlade(process.cwd() + "/../");
+requireBlade("../");
//-- end of horrible hack
Package.describe({
@@ -27,9 +34,12 @@ Package.register_extension("blade", function(bundle, srcPath, servePath, where)
//The template name does not contain ".blade" file extension or a beginning "/"
var templateName = path.dirname(servePath).substr(1);
templateName += (templateName.length > 0 ? "/" : "") + path.basename(servePath, ".blade");
- //Templates are assumed to be stored in "views/", so remove this from the name, if needed
+ //Templates are assumed to be stored in "views/" or "client/views/"
+ //so remove this from the name, if needed
if(templateName.substr(0, 6) == "views/")
templateName = templateName.substr(6);
+ else if(templateName.substr(0, 13) == "client/views/")
+ templateName = templateName.substr(13);
//Finally, tell the Blade compiler where these views are stored, so that file includes work.
//The location of meteor project = srcPath.substr(0, srcPath.length - servePath.length)
var basedir = srcPath.substr(0, srcPath.length - servePath.length) + "/views";
@@ -61,10 +71,15 @@ Package.register_extension("blade", function(bundle, srcPath, servePath, where)
"Meteor._def_template(" + JSON.stringify(templateName) +
//when the template is called...
", function(data, obj) {data = data || {};" +
- //helpers work...
- "for(var i in obj.helpers)\n" +
- "if(typeof obj.helpers[i] == 'function') " +
- "data[i]=obj.helpers[i]();" +
+ //helpers work... even functions, thanks to Object.defineProperty!
+ "for(var i in obj.helpers){" +
+ "if(typeof obj.helpers[i] != 'function' || !Object.defineProperty)\n" +
+ "data[i]=obj.helpers[i];\n" +
+ "else\n" +
+ "Object.defineProperty(data,i,{" +
+ "get:obj.helpers[i],configurable:true,enumerable:true" +
+ "});" +
+ "}" +
/*call the actual Blade template here, passing in data
`ret` is used to capture async results.
Note that since we are using caching for file includes,
View
2 package.json
@@ -15,7 +15,7 @@
"live binding",
"meteor"
],
- "version": "3.0.0rc1",
+ "version": "3.0.0beta8",
"homepage": "https://github.com/bminer/node-blade",
"repository": {
"type": "git",
View
2 smart.json
@@ -3,7 +3,7 @@
"author": "Blake Miner <miner.blake@gmail.com> (http://www.blakeminer.com/)",
"description": "Blade - HTML Template Compiler, inspired by Jade & Haml",
"homepage": "https://github.com/bminer/node-blade",
- "version": "3.0.0rc1",
+ "version": "3.0.0beta8",
"git": "https://github.com/bminer/node-blade.git",
"packages": {
}

0 comments on commit a050d0d

Please sign in to comment.
Something went wrong with that request. Please try again.