Closure Templates (aka Soy) can be used either on the server or client-side. The recommended way to use them server-side is with SoyTofu, but there is a way to use them in pure javascript on the server with our new pal, NodeJS.
Suppose we have this blog.soy template to render a simple blog post with some comments:
{namespace blog} /** * Renders a post with comments. * @param post * @param comments */ {template .postPage} <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>blog</title> <meta name="generator" content="TextMate http://macromates.com/"> <meta name="author" content="Sean McCullough"> <!-- Date: 2009-11-28 --> </head> <body> {call .post} {param post: $post /} {/call} {call .comments} {param comments: $comments /} {/call} </body> </html> {/template} /** * Renders a Post. * @param post */ {template .post} <h2>{$post.title}</h2> {$post.body} {/template} /** * Renders a list of comments. * @param comments */ {template .comments} <h3>Comments:</h3> <ul> {foreach $comment in $comments} <li>{$comment}</li> {/foreach} </ul> {/template}
The Closure template compiler will take this input .soy file and create an output .js file that contains functions corresponding to the {template .functionName} sections above.
To compile:
java -jar SoyToJsSrcCompiler.jar --outputPathFormat templates-compiled/blog.js templates/blog.soy
The generated functions in templates-compiled/blog.js look like this:
blog.post = function(opt_data, opt_sb) { var output = opt_sb || new soy.StringBuilder(); output.append('<h2>', soy.$$escapeHtml(opt_data.post.title), '</h2>', soy.$$escapeHtml(opt_data.post.body)); if (!opt_sb) return output.toString(); };
Now, if you just try to require() this generated .js file, Node will complain because it doesn't know what soy.StringBuilder() is. We can fix that by shoehorning soyutils.js into node, of course.
First we need to make soyutils.js work with Node's require mechanism. require works in conjunction with process.mixin(), so you make soy require()-able by adding this to the bottom of soyutils.js (copied into your application code directory from the closure templates distribution):
process.mixin(exports, soy);
Then we need to require soyutils in the blog.js file (you can just paste these into the bottom of the file but it's probably better to implement this as a post-soy-compile step in a build script so you don't have to keep pasting every time you recompile the template)
var soy = require('../soyutils'); process.mixin(exports, blog);
That last process.mixin call will make the blog template functions available to other source files via require.
Now we're ready to use the soy template with our nodejs server code. You'd just require templates-compiled/blog.js and call the functions that it provides from within your event handlers (again, building on the blogging example from a previous post):
var sys = require("sys"), http = require("http"), blogTemplates = require("./templates-compiled/blog"); var handlers = { '/posts/{postId}' : { GET : function(request, response, args) { response.sendHeader(200, {"Content-Type": "text/html"}); var commentsPromise = getCommentsPromise(args.postId); var postPromise = getPostPromise(args.postId); var templateVars = {}; commentsPromise.addCallback(function(comments) { templateVars.comments = comments; }); postPromise.addCallback(function(post) { templateVars.post = post; }) var joinedPromise = join([commentsPromise, postPromise]); joinedPromise.addCallback(function() { var pageHtml = blogTemplates.postPage(templateVars); response.sendBody(pageHtml); response.finish(); }); } } } };
This is awfully clunky. I'd like to write a directory watcher that automatically compiles recently updated .soy files, appends the require and process.mixin calls, and reloads the result into Node.
Thoughts on Closure and NodeJS
I spent a little time trying to get the closure compiler to work with Node so that you could for instance, statically verify that the template function invocation parameters match up with the declared parameter types in the .soy file. Haven't gotten enough working there to blog about yet though.
I don't know if the closure compiler optimizations would help NodeJS much, but the static analysis would probably help catch a lot of easy-to-introduce but too-tedious-to-unit-test problems that crop up when you have lots of people working on the same code base.
Also, the Closure Library contains a lot of useful packages that could be applied server-side as well.
glad i found this as i have been working on the same thing.
ReplyDeleteI wonder if the main people behind NodeJS are doing this. I doubt that it can be done as a Module as it really needs to be baked into the core more.
Useful & Great Article for NodeJS Development
DeleteNode.js Training | Node js Online Course | Node.js Essential Training | Node.js Online Training | Node.js Training in Chennai
nike roshe run
ReplyDeletenba jerseys
soccer jerseys
ralph lauren,polo ralph lauren,ralph lauren outlet,ralph lauren italia,ralph lauren sito ufficiale
michael kors handbags
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
thomas sabo outlet
michael kors outlet
michael kors outlet
true religion canada
true religion outlet
beats by dre
michael kors outlet store
michael kors outlet store
prada shoes
true religion jeans
snapbacks wholesale
hermes belt
michael kors handbags
timberland boots
soccer jerseys wholesale
louis vuitton handbags
true religion jeans outlet
louis vuitton outlet
mbt shoes outlet
swarovski outlet
swarovski crystal
louis vuitton handbags outlet
links of london
longchamp handbags outlet
michael kors online outlet
adidas outlet
cheap mlb jerseys
cheap nhl jerseys
louis vuitton outlet store
20160224caihuali
AngularJS Training in Chennai AngularJS Training in Chennai Node.js Training in CHennai Angular 2 Training in Chennai Angular 2 Training in Chennai Node.js Training in CHennai Node.js Training in chennai MEAN Developer Training in Chennai
ReplyDeleteBackBoneJS Training in Chennai BackBoneJS Training in Chennai EmberJS Training in Chennai EmberJS Training in Chennai
Interesting Article
ReplyDeleteJavascript Training in Chennai | HTML5 Online Training
JavaScript Training Courses | Javascript Online Training | Angular 2 Training in Chennai
discount oakley sunglasses
ReplyDeleteugg boots
moncler outlet online
pandora charms
longchamp sale
nike blazer low pas cher
michael kors outlet online
jimmy choo shoes
hejixia20161202
guaranteed search engine rankings
ReplyDeleteairlie beach tours
whitsunday private yacht charters
famous brand slogans
ppc optimization
nike trainers uk
ReplyDeletemichael kors uk
christian louboutin outlet
under armour outlet
oakley sunglasses wholesale
converse trainers
replica watches
gucci sito ufficiale
air max 90
oakley sunglasses
air jordan uk
ReplyDeletelions jerseys
cincinnati bengals jerseys
cheap jordans
nhl jerseys
oakley sunglasses
under armour shoes
new york knicks
oakley sunglasses wholesale
chicago bears jerseys
harden shoes
ReplyDeleteyeezys
jordan shoes
adidas neo
michael kors outlet store
nike mercurial vapor
adidas ultra boost
adidas stan smith men
longchamp
http://www.uggoutlet.uk
ferragamo shoes
ReplyDeleteadidas outlet
moncler outlet
coach outlet
canada goose jackets
michael kors outlet store
uggs
cheap jordans
coach factory outlet
moncler jackets outlet
linpingping10.25
oakley sunglasses
ReplyDeletenew balance shoes
supra shoes
jordan
adidas outlet store
timberland boots
michael kors outlet
birkenstock outlet
oakley sunglasses
oakley sunglasses
20185.16wengdongdong
I am sure you see the trend here... Commercial Mortgage Financing can be used in practically any industry for any kind of commercial property. Speak with your Business Finance Broker when you are ready to invest in a Commercial Real estate opportunity. www.financetypes.us
ReplyDeleteMake use of a travel agent that provides travel deals for handicapped travelers. Booking plane tickets and rooms in hotels with journey agents that provide travel methods to disabled individuals is advantageous in many ways. They make sure they book for his or her disabled customers airlines as well as hotels which are disabled pleasant. They make an effort to offer providers and suggestions which will ensure their own clients journey comfortably. www.bestadventuretravel.us
ReplyDeleteOne of the biggest competitions of today is staying fit. It seems like people nowadays want to lose weight instantly as if there is no tomorrow or it is as if it is a passport for the general population. Losing weight and staying fit is never easy. www.bestadventuretravel.us
ReplyDeleteThe laws of nature are just as they treat every specie (and not only man) with equality. In a jungle, every specie gets its due share of food, air and water which enable them to live a dignified life without being dependent on any other creation. Nature makes no distinction between one specie, and the other as all species are the children of the same God. www.lawinformation.us
ReplyDeleteI am certain you begin to see the trend right here... Commercial Home loan Financing may be used in virtually any business for any type of commercial home. Speak together with your Business Finance Broker when you're ready to purchase a Commercial Property opportunity. www.mybusinessplan.us
ReplyDeleteYou will see all styles and models of fashion blogs as being the internet is stuffed with them. It can take a look at the advantages of wearing lean jeans through boyfriend bluejeans or the best way pink takes the destination of dark colored plus many of the extras. Just like you go internet, you receives your fill of your latest popular trends as a result of fashion blogs. www.stylesbeautytips.com
ReplyDeleteReal estate shareholders live in addition to die by means of their chance to add importance. With not any added importance, there usually are no gains. This applies with almost any business, but what makes real estate a really great business as well as a great investment decision, is the volume of ways you can contribute value and benefit from big gains. www.realestatevalley.us
ReplyDeleteHealth fitness tips also recommend that vices should be stopped. Smoking predisposes one to vascular conditions such as arteriosclerosis and heart diseases. Alcohol consumption need not be eliminated but should be limited to 30 jiggers a day only. Alcohol still has health benefits such as vasodilation. These are just some of what Health fitness tips recommend www.healthyactivities.us
ReplyDeleteInsurance can be synonymous to a lot people expressing risks involving losses expected coming from a supposed car accident. Here, the price of your losses are going to be borne by the many insurers. www.insuranceguider.us
ReplyDeleteDiscomfort heard this argument intended for spending far more now with quality just to save money in the future. But why not consider the impression your purchase has on the earth, shouldn't shopping ethically participate in the talk too? www.servicesexpert.us
ReplyDeleteHealth fitness ideas also suggest that vices ought to be stopped. Smoking predisposes someone to vascular conditions for example arteriosclerosis as well as heart illnesses. Alcohol consumption do not need to be removed but ought to be limited in order to 30 jiggers each day only. Alcohol nevertheless has many benefits such because vasodilation. These are are just some of what Health fitness ideas recommend www.healthimprove.us
ReplyDeleteTraveling, for individuals with disabilities, is extremely hectic, particularly when they get to the airport terminal. They face the process of obtaining proper info and instructions. This is actually further aggravated through the huge number of individuals traveling as well as long lists. In international airports, there tend to be attendants which are supposed for carrying on the needs of these travelling along with disabilities. www.safetravelguide.us
ReplyDeleteI know you start to see the trend the following... Commercial Mortgage loan Financing can be utilized in almost any market for almost any commercial house. Speak along with your Business Finance Broker if you are ready to buy a Commercial Real-estate opportunity. www.safetravelguide.us
ReplyDeleteYou will find all forms and shapes of fashion blogs as the internet is full of them. It can talk about the main benefit of wearing lanky jeans over boyfriend jeans or how pink takes the place of black plus all the extras. As you go online, you will get your fill of the latest in fashion trends via fashion blogs. www.newsvillage.us
ReplyDeleteMost of us have heard the actual argument with regard to spending much more now upon quality in order to save money later on. But how about the effect your purchase is wearing the globe, shouldn't shopping ethically participate the dialogue too? www.newsvillage.us
ReplyDeleteYou can find all kinds and forms of fashion blogs because internet is brimming with them. It can mention the luxury of wearing lanky jeans around boyfriend skinny jeans or precisely how pink takes the best place of dark-colored plus the many extras. Because you go on-line, you is certain to get your fill in the latest popular trends through fashion blogs. www.onlinefashionshop.us
ReplyDeleteReal estate buyers live and also die simply by their power to add benefit. With simply no added benefit, there are usually no income. This does work with virtually any business, but what makes real estate this kind of great business plus a great purchase, is how many ways you can value and make the most of big income. www.landproperty.us
ReplyDeleteWere you thinking with regards to remodeling your current home? Understand that you may achieve your current goal and not using a giant price. Small changes introduced in nearly all room, including the outdoors on the town can make the many difference. www.thebudgetdecorator.us
ReplyDeletexReal estate individuals live plus die by way of their capability add cost. With virtually no added cost, there will be no sales. This very well with every business, but why is real estate this sort of great business including a great choice, is the sheer numbers of ways it's fine to use value and cash in on big sales. www.insuranceadvice.us
ReplyDeleteYou can see all creates and shapes and sizes of fashion blogs for the internet is jam packed with them. It can converse about the luxury of wearing slim jeans across boyfriend shorts or ways pink takes the position of schokohäutige plus lots of the extras. Simply because go via the internet, you becomes your fill for the latest popular trends with fashion blogs. www.servicesdealer.us
ReplyDeleteMost likely you view the trend in this article... Commercial House loan Financing can be employed in pretty much any marketplace for virtually any commercial property or home. Speak with all your Business Finance Broker while you are ready to invest in a Commercial Real estate investment opportunity. www.businessterms.us
ReplyDeleteTravel's importance is actually underestimated by lots of people. Travel isn't just fun, enjoyable and pleasant. With the current life styles and function conditions, travel is becoming more than a choice. It is a lot more than just having a good time. www.cheaptraveldeals.us
ReplyDeleteHealth fitness suggestions also advise that vices needs to be stopped. Smoking predisposes anyone to vascular conditions for instance arteriosclerosis and also heart conditions. Alcohol consumption will not need to be eradicated but needs to be limited to be able to 30 jiggers per day only. Alcohol nonetheless has health improvements such since vasodilation. These are just some of what Health fitness suggestions recommend www.idealhealthfitness.us
ReplyDeleteRead you be conscious of the trend at this point... Commercial Bank loan Financing can be utilised in basically any community for any sort of commercial real estate. Speak in your Business Finance Broker while you're ready to buy a Commercial Properties opportunity. www.financebenefits.us
ReplyDeleteYou'll find all varieties and styles of fashion blogs because the internet is packed with them. It can speak about the main advantage of wearing slim jeans above boyfriend denims or just how pink takes the spot of african american plus every one of the extras. When you go on the web, you are certain to get your fill with the latest in fashion trends by means of fashion blogs. www.currentfashiontrend.com
ReplyDeleteReal estate traders live as well as die through their capability to add worth. With absolutely no added worth, there tend to be no earnings. This holds true with any kind of business, but why is real estate this type of great business along with a great expense, is the amount of ways you can include value and profit from big earnings. www.commercialsproperty.us
ReplyDeleteAre you thinking concerning remodeling the home? Take into account that you can frequently achieve the goal with out a giant expenditure. Small advancements introduced in virtually every room, including the surface of your home can make every one of the difference. www.houseInnovations.us
ReplyDeleteThe truth is that We can sit these today and even write what you deserve to be hunting for in business trends and be able to a 365 days from at present, write the exact same sort in article through different ideas to keep abreast of as business and even society evolve. www.theservicesexperience.com
ReplyDeleteHealth fitness guidelines also advice that vices must be stopped. Smoking predisposes you to definitely vascular conditions including arteriosclerosis along with heart ailments. Alcohol consumption don't need to be taken away but must be limited for you to 30 jiggers every day only. Alcohol even now has benefits such while vasodilation. These are are just some of what Health fitness guidelines recommend www.healthcarecentre.us
ReplyDeleteAre you currently thinking regarding remodeling your own home? Remember that you could achieve your own goal with no giant cost. Small enhancements introduced in nearly every room, including the outside of the home can make all of the difference. www.selecthomeadvisor.us
ReplyDeleteHealth fitness points also propose that vices need to be stopped. Smoking predisposes that you vascular conditions like arteriosclerosis in addition to heart disorders. Alcohol consumption does not need to be taken out but need to be limited to help 30 jiggers daily only. Alcohol however has health advantages such seeing that vasodilation. These are just some of what Health fitness points recommend www.healthcareaffect.us
ReplyDeleteJust about everyone has heard the particular argument regarding spending a lot more now about quality to save lots of money afterwards. But think about the influence your purchase has on the planet, shouldn't shopping ethically engage in the debate too? www.eventsshopping.us
ReplyDeletexReal estate individuals live plus die by way of their capability add cost. With virtually no added cost, there will be no sales. This very well with every business, but why is real estate this sort of great business including a great choice, is the sheer numbers of ways it's fine to use value and cash in on big sales. www.serviceadvisories.com
ReplyDeleteHealth fitness recommendations also suggest vices really should be stopped. Smoking predisposes want you to vascular conditions just like arteriosclerosis plus heart health conditions. Alcohol consumption needn't be wiped out but really should be limited so that you can 30 jiggers on a daily basis only. Alcohol continue to has rewards such when vasodilation. These are are just some of what Health fitness recommendations recommend www.healthifitness.us
ReplyDeleteYou can get all versions and sizes and shapes of fashion blogs given that the internet is rife with them. It can consider the benefit of wearing skinny jeans throughout boyfriend tight pants or skirts or the correct way pink takes spot of black colored plus the extras. Whilst you go web based, you get your fill belonging to the latest popular trends using fashion blogs. www.globenewscenter.us
ReplyDeleteYou will discover all types and designs of fashion blogs since the internet is filled with them. It can discuss the benefit of wearing thin jeans more than boyfriend denim jeans or exactly how pink takes the area of dark plus all of the extras. While you go on the internet, you can get your fill from the latest popular trends by way of fashion blogs. www.fashionlabel.us
ReplyDeleteOne can find all methods and figures of fashion blogs when the internet is complete with them. It can focus on the advantage of wearing slender jeans about boyfriend pants or the way in which pink takes the location of ebony plus most of the extras. As you may go on line, you will receive your fill within the latest in fashion trends by fashion blogs. www.theworldnews.us
ReplyDeleteI know that you read the trend these... Commercial Loan Financing should be considered in just about any trade for some kind of commercial premises. Speak with each of your Business Finance Broker if you end up ready to get a Commercial The property market opportunity. www.mybusinessmanager.us
ReplyDeleteThe laws associated with nature are simply as these people treat each and every specie (and not just man) along with equality. Inside a jungle, each and every specie will get its because of share associated with food, air as well as water that enable these phones live the dignified life without having to be dependent on every other creation. Character makes absolutely no distinction in between one specie, and also the other because all species would be the children from the same Lord. www.equallaw.us
ReplyDeleteHealth fitness hints also counsel that vices has to be stopped. Smoking predisposes to vascular conditions which include arteriosclerosis together with heart medical conditions. Alcohol consumption should not be taken off but has to be limited that will 30 jiggers each and every day only. Alcohol also has health and fitness benefits such mainly because vasodilation. These are just some of what Health fitness hints recommend www.healthandfoodideas.com
ReplyDeletediscomfort heard this argument intended for spending far more now with quality just to save money in the future. But why not consider the impression your purchase has on the earth, shouldn't shopping ethically participate in the talk too? www.aboutfinancenews.com
ReplyDeleteThe truth is that I will sit right here today as well as write what you need to be searching for in business trends after which a 12 months from right now, write exactly the same sort associated with article along with different tips to keep close track of as business as well as society develop. www.expertsbusinessadvice.com
ReplyDelete"xYou'll discover all sorts and patterns of fashion blogs for the reason that internet is rich in them. It can look at the main benefit of wearing skeletal jeans in excess of boyfriend trousers or the way pink takes the site of black color plus each of the extras. Since you go on the net, you could possibly get your fill on the latest in fashion trends by using fashion blogs. www.latestfashiontrends.us" www.latestfashiontrends.us
ReplyDeleteThe reality is that I am able to sit in this article today in addition to write what you long for to be in search of in business trends then a season from at this point, write identical sort connected with article having different suggestions for be mindful of as business in addition to society advance. www.onlineservicecentre.com
ReplyDeleteMost of us have heard the actual argument with regard to spending much more now upon quality in order to save money later on. But how about the effect your purchase is wearing the globe, shouldn't shopping ethically participate the dialogue too? www.shoppingworld.us
ReplyDeleteTravel will give you something to count on... to organize... to review for... and later to share. You will bring home experiences. Life might get somewhat monotonous when you let the item, particularly when you finally retire whilst your work lifetime ends. Anticipation might be priced at at least approximately the excursion itself along with the memories of which follow this trip. www.topstoriesus.us
ReplyDeleteHealth fitness strategies also recommend that vices should really be stopped. Smoking predisposes you to vascular conditions which includes arteriosclerosis and even heart problems. Alcohol consumption don't have to be done away with but should really be limited to help you 30 jiggers 24 hours only. Alcohol always has what are the benefits such simply because vasodilation. These are are just some of what Health fitness strategies recommend www.healthafitness.us
ReplyDeleteWill you be thinking in relation to remodeling ones home? Remember you might achieve ones goal with not a giant purchase. Small upgrades introduced in every room, including the outer entrance can make each of the difference. www.loxuryhome.us
ReplyDeleteTravel provides you with something to anticipate... to get ready for... to research for... and later to talk about. You brings home tales. Life could possibly get somewhat monotonous should you let this, particularly once you retire as well as your work existence ends. Anticipation may be worth at least around the journey itself and also the memories which follow the actual trip. www.travelandadventure.us
ReplyDeleteHealth fitness tips and hints also suggest that vices could be stopped. Smoking predisposes people to vascular conditions along the lines of arteriosclerosis not to mention heart sicknesses. Alcohol consumption does not have to be got rid of but could be limited towards 30 jiggers a full day only. Alcohol even so has health rewards such for the reason that vasodilation. These are just some of what Health fitness tips and hints recommend www.healthfitnesstogether.com
ReplyDeleteSeen you are aware of the trend in this case... Commercial Home owner loan Financing are available in very nearly any market place for any variety of commercial building. Speak utilizing your Business Finance Broker remember when you are ready to invest in a Commercial Realty opportunity. www.bestfinanceideas.com
ReplyDeleteMore than likely you understand the trend below... Commercial Home finance loan Financing works extremely well in nearly any sector for just about any commercial residence. Speak using your Business Finance Broker when you find yourself ready to get a Commercial Real estate property opportunity. www.businessplanning.us
ReplyDeleteYou will find all forms and shapes of fashion blogs as the internet is full of them. It can talk about the advantage of wearing skinny jeans over boyfriend jeans or how pink takes the place of black plus all the extras. As you go online, you will get your fill of the latest in fashion trends via fashion blogs. www.latestfashionz.us
ReplyDeletexReal estate individuals live plus die by way of their capability add cost. With virtually no added cost, there will be no sales. This very well with every business, but why is real estate this sort of great business including a great choice, is the sheer numbers of ways it's fine to use value and cash in on big sales. www.friendlyrealestate.us
ReplyDeleteHave you been thinking about remodeling your home? Keep in mind that you can often achieve your goal without a giant expense. Small improvements introduced in almost every room, including the exterior of the house can make all the difference. www.homesrenovation.us
ReplyDeleteReal estate option traders live together with die by just their capacity add valuation. With hardly any added valuation, there happen to be no proceeds. This well said with all business, but what makes real estate an extremely great business in addition to a great financial commitment, is numerous ways it is possible to value and profit from big proceeds. www.newservicespoints.com
ReplyDeleteWe have all heard the argument for spending more now on quality to save money later. But what about the impact your purchase has on the world, shouldn't shopping ethically be part of the discussion too? www.myshoppingideas.us
ReplyDeleteReal estate businesses live not to mention die from their capability to add benefits. With certainly no added benefits, there are actually no business earnings. This for sure with any sort of business, but what makes real estate this great business and then a great funding, is the sheer number of ways you'll be able to value and take advantage of big business earnings. www.myshoppingideas.us
ReplyDeleteNo matter the type of|the kind of} wheel, two adjoining pockets should at all times have totally different colours. 007Store.com is the official online emporium that includes products inspired by the James Bond movie sequence, 007카지노 together with legacy pieces and designer collaborations. Discover our James Bond merchandise, ready-to-wear, accessories and collectibles. Luxury betting fabric with full-size roulette grid that includes 007 emblem. There are several of} inside bets also can make|you could make}, together with a straight up quantity or straddling the line between numbers to select out} a mixture.
ReplyDelete