bminer / node-blade Goto Github PK
View Code? Open in Web Editor NEWBlade - HTML Template Compiler, inspired by Jade & Haml
License: Other
Blade - HTML Template Compiler, inspired by Jade & Haml
License: Other
Blade functions should take a buffer parameter internally, so that they push to the correct spot in the buffer.
Model.get
does not work if the property has not yet been added.
Compiler bug - __.blocks, __.func, and __.chunk refer to the same Object when the view is compiled.
No good!
Need to return from the function once cb
is called. Will fix soon.
Rendering a block always appends the rendered content to the end of a block. Maybe create the ability to prepend and replace, as well?
Proposed Syntax:
render append block(args)
render replace block(args)
render prepend block(args)
render block(args)
will be the same as render append block(args)
.
Probably build a test library that does the following:
1.) Read data from a Blade template (i.e. /test/123.blade)
2.) Read options
data, including locals to be passed to the view (i.e. /test/123.js)
3a.) If the output HTML exists (i.e. /test/123.html), then compare it with rendered output; otherwise,
3b.) Write the HTML output (i.e. /test/123.html) and prompt the user to review the output for errors.
3b allows one to easily generate new test cases. :)
Newlines are prepended to text nodes or filtered_text nodes when the last node was one of the same. Unfortunately, this feature is not working correctly. Consider this example:
p this is
| a test
span of newlines
| . Cool.
renders as:
<p>this is
a test<span>
of newlines</span>. Cool.</p>
instead of
<p>this is
a test<span>of newlines</span>. Cool.</p>
Minor difference, but still a bug.
Why not allow a user to include a file based upon certain conditions?
include var_name
where var_name can be any variable within the view containing the filename to be included.
like if i have a outside teamplte
chunk template
table.data-users
thead
tbody
and a user loop template
chunk users(user)
tr
td= user.name
td= user.sex
td= user.age
how to combine above code to render together
$('.data-users tbody').html( Meteor.ui.render( Template.staffs ) );
File includes should be permitted in functions, blocks, and chunks. This can be fixed by making each function definition, chunk definition, block definition, block modification, or block render statement asynchronous.
For example, a file include within a block modifier:
append foobar(header, footer)
h1=header
include "foobar"
h1=footer
h1 Finally
compiles to:
//Standard template init code goes here... including try, with blocks
//__.line, __.col, __.base, __.rel removed for brevity
__.cb = cb;
cb = function(err, html, info) {if (!info.inc) info.r.done(info); __.cb.apply(this, arguments);};
__.r.blockMod("a", "foobar", __, function(__, cb, header, footer) {
__.push('<h1','>',header,'</h1>');
__.r.include('foobar', __, function(err) {
__.push('<h1','>',footer,'</h1>');
cb(); //This closing thingy was put here by the compiler in the blockMod function, as instructed by the include.
}); //This closing thingy was put here by the compiler in the blockMod function, as instructed by the include.
}, function() {
__.push('<h1','>','Finally','</h1>');
if(!__.inc) __.r.done(__); cb(); //This closing thingy was put here by the compiler when finishing up
}); //This closing thingy was put here by the compiler when finishing up, as instructed by the blockMod
As per the comment listed in the code above, the compiler needs to keep track of "closing snippets" that were added by child nodes, as appropriate. When the compiler is done with all of the nodes, it will inject any remaining "closing snippets". The final cb() call will be injected just before the final "closing snippets."
The runtime needs to capture errors more intelligently, as well. There is no sense in putting try, catch blocks in the template itself, except for the initial try, catch, as it is used to pass errors to the callback instead of the caller.
Just as personal reminders:
Templates use try, catch blocks to capture additional error information. The last line of the try block is cb(null, __.join(""), __)
;
If a runtime error occurs within a template, the catch block will do this: return cb(__.r.rethrow(err, __) );
If a runtime error occurs within an included template, the runtime is responsible for
passing it to the includer's callback like this:
cb(__.r.rethrow(err, __) );
BUT, the __ should be in the context of the includer (i.e. proper line number, filename, etc.)
In addition, the runtime should expect the include callback function to throw an error.
It should catch these errors and pass to the includer's callback function.
The same is true of callbacks to function calls, callbacks after block modifiers, etc. The
runtime must expect the callback function to throw an error and then rethrow it properly.
like
body
#wrapper
#blahblahblah
#script
script(src='/public/app.js')
Middleware should optionally serve up Blade runtime at a specific mount point
Legacy browsers don't know what 'const' means. Just change to 'var' in Blade runtime.
C++ style block comments should be supported, starting with /*
and ending with */
. These comments still need to be processed by the parser because text blocks might contain /* a comment */
, which should still be rendered, if needed. Therefore, block comments will be a regular node from the parser's perspective.
/* this comment will not output into the template */
/** this comment will output into the template */
will render to:
<!--this comment will output into the template-->
try, catch blocks get messed up here.
Add the ability to setup data validation functions for model properties like so:
model.validation.firstName = function(input) {
//Return true to be valid; false to be invalid
//return input.length > 0;
//Can also return an Object for more options
return {
"valid": input.length > 0,
"value": input.trim()
};
};
//Now set firstName
model.set("firstName", "Blake ");
//Now check to see if the input was valid
model.valid("firstName"); //true
//Now let's check what value was set...
model.peek("firstName") // "Blake"
Review Test Cases and Add More, as needed
Look for variable names in a string of text for interpolation. Do it just like Jade... #{var_name} will be replaced with the contents of var_name.
See https://github.com/bminer/node-blade/blob/master/meteor/package.js#L32
The Blade Meteor package currently injects the entire contents of /views/index.blade
into the body of the initially loaded HTML document. What about the head
tag? It looks like there is currently no way to override the head tag at this time.
This might need some more work / re-work.
Blade needs some benchmarks:
If anyone can tackle this, I'd greatly appreciate it!
There is a bug that occurs when you define a block within a function or "append/prepend/replace" block. Investigating...
Build express middleware to deliver compiled client-side templates. For example, you can set a mount point (i.e. "/views") and any GET request to "/views/view123.blade" will cause the Express middleware to compile the blade template and deliver the JavaScript code to the browser. No client-side caching of templates would be required; this would be handled automatically by the server (i.e. using 304 Not Modified weak caching or Expires headers and strong caching).
Removing "//" comments from JavaScript code would be nice, and it would fix a few bugs
For example, this doesn't work:
- console.log("Hello"); //foobar
See commit a4941f8
Add Stylus and Coffeescript filters & Improve Markdown filter
Need a if(err) throw err;
statement on line 25 of package.js. I'll get to this eventually.
Perhaps reconsider the syntax. Separating attributes with whitespace is nice, but it limits what your code looks like. Although probably rare, you may want to do:
div(attr=foo+" bar")
which is not allowed because the attribute value code contains a space. Maybe if the parser was smart enough to detect quoted strings within attribute value code?
it's really hard to get things working.
some examples are good.
if i make some new Meteor.Collection
and find() how to list all results in blade.
how to bind events?
Fix this.
... and it messes things up.
When I tried to install blade using node, I got this error message (with cmd and MSYS bash):
> ./postinstall.sh
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! [email protected] postinstall: `./postinstall.sh`
npm ERR! `cmd "/c" "./postinstall.sh"` failed with 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the blade package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./postinstall.sh
npm ERR! You can get their info via:
npm ERR! npm owner ls blade
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Windows_NT 6.0.6002
npm ERR! command "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "blade"
npm ERR! cwd c:\Program Files\nodejs
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.24
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] postinstall: `./postinstall.sh`
npm ERR! message `cmd "/c" "./postinstall.sh"` failed with 1
npm ERR! errno {}
npm ERR! Error: EPERM, open 'c:\Program Files\nodejs\npm-debug.log'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Windows_NT 6.0.6002
npm ERR! command "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodej
s\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "blade"
npm ERR! cwd c:\Program Files\nodejs
npm ERR! node -v v0.6.19
npm ERR! npm -v 1.1.24
npm ERR! path c:\Program Files\nodejs\npm-debug.log
npm ERR! code EPERM
npm ERR! message EPERM, open 'c:\Program Files\nodejs\npm-debug.log'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! c:\Program Files\nodejs\npm-debug.log
npm not ok
npm not ok
I had to open up the .tgz archive that npm downloaded and remove the postinstall script hook before it would install blade.
blade --help
output needs some more examples.
Blade functions are not yet implemented. Follow the spec outlined in the README file to implement these.
If there is a problem with the Blade compiler, or more likely, if there is a syntax error with the JavaScript code in a template, Node.js will not provide any line number or other information about the error. At the time of this writing, this is a limitation of the Google V8 engine; it cannot report line numbers in eval
ed JavaScript code.
Related upstream issues:
Node: nodejs/node-v0.x-archive#229, nodejs/node-v0.x-archive#2734
Google V8: http://code.google.com/p/v8/issues/detail?id=1914 (now somewhat fixed)
https://code.google.com/p/v8/issues/detail?id=1281
https://code.google.com/p/v8/issues/detail?id=2589
Progress is being made to improve this.
Create a Blade smart package for Meteor, with the ability to use Meteor.ui.chunk
http://docs.meteor.com/#livehtml
http://docs.meteor.com/#meteor_ui
In the "Using Blade with Meteor" wiki, there are references to __
such as __.chunk
. What do these double underscores mean?
The middleware does not parse the URL, which means that it is not sanitized for use.
__.push(a);
__.push(b);
__.push(c);
can be re-written as:
__.push(a,b,c);
which can make compiled templates much smaller - 9 or 10 characters per push. To implement, I was thinking about having a flag in the compiler inPush
. When set, we are in the middle of a push(...) call. Whenever we need to get out, we need to append a );
. Whenever, we need to get inside one, we need to append __.push(
. Should be simple enough.
replace
keyword currently does not allow you to replace a block with a parameterized block. It might be cool to be able to do this, and I don't think the implementation would be that bad.
Can we get support to interpret javascript portions as coffeescript? Maybe automatically interpret .bladec
files as coffeescript-backed blade files?
Templates generated by Blade and the Blade smart package are wrapped with Meteor.startup(function() {...});
This might be pointless at best and potentially harmful at worst. Need to look into the documenation for Meteor.startup
to see if this is necessary. I think this is what Handlebars does? I dunno.
This will not parse.
div(attr="prefix"+test)
Modify the runtime so that Blade-generated id attributes do not conflict with elements that already exists on the webpage (i.e. check to see if it exists first by using document.getElementById
.
A temple with: .card(style="left:0px")
will not crash but if between =
and the first "
a space exists like: .card(style= "left:0px")
then the app will crash.
Also a more complicated construction like: .card(style="left:"+card.left+"px;top:"+card.top+"px")
will crash:
SyntaxError: Parser error: Expected child node or newline but "(" found.
at /Users/michel/meteor/gaido/views/board.blade:6:7
Maybe build this?
I have installed blade within my meteor environment, but don't know how to use it and or how to set it up.
As an "hello world" I have to next template file:
views/hello.blade:
html
head
body
p Hello world!
Now if I kick off meteor I get the next errors:
Errors prevented startup:
Exception while bundling application:
TypeError: Cannot call method 'toString' of undefined
at /usr/lib/meteor/packages/blade/package.js:30:59
at /usr/lib/meteor/lib/node_modules/blade/lib/blade.js:37:19
at Compiler.compile (/usr/lib/meteor/lib/node_modules/blade/lib/compiler.js:90:10)
at compile (/usr/lib/meteor/lib/node_modules/blade/lib/blade.js:36:12)
at Object.compileFile (/usr/lib/meteor/lib/node_modules/blade/lib/blade.js:56:3)
at /usr/lib/meteor/packages/blade/package.js:18:8
at [object Object].add_file (/usr/lib/meteor/app/lib/bundler.js:196:5)
at /usr/lib/meteor/app/lib/bundler.js:97:16
at Array.forEach (native)
at Function.<anonymous> (/usr/lib/meteor/app/lib/third/underscore.js:76:11)
Your application is crashing. Waiting for file change.
Somehow tmpl
is undefined??
Create a :javascript filter similar to :coffeescript. Perhaps use UglifyJS for minification on :javascript and :coffeescript?
i had this step done
ln -s /path/to/blade/meteor /path/to/meteor/packages/blade
and when i execute meteor add blade
it just tells me
bogon:app crapthings$ meteor add blade
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'blade'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at /usr/local/meteor/packages/blade/package.js:2:13
at [object Object].init_from_library (/usr/local/meteor/app/lib/packages.js:104:5)
at Object.get (/usr/local/meteor/app/lib/packages.js:222:11)
at /usr/local/meteor/app/lib/packages.js:273:30
at Array.forEach (native)
at Function. (/usr/local/meteor/app/lib/third/underscore.js:76:11)
minify
compiler option should utilize uglifyjs
Need to finish client runtime and distribute *.js files. Possibly automate the build process of the client runtime (minify the code, etc.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.