Dave on Facebook

Dave's profile on LinkedIn
DavesWeb visitors really liked:
Country Place Cookbook
Tomato Sauce Recipe
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
My Status
Fabulous Snow!
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
My Status
Thankful for Signs of Spring!
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
Country Place Cookbook
Grandmother Snare's Iced Tea
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
Gallery
Can Am Eyes
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
Top Viewed items on DavesWeb:
My Status
Balsamic Vinaigarette Watermelon - 38,091 views
My Status
Cool car - 26,530 views
Gallery
Can Am Eyes - 25,967 views

No Live Blogging, Sorry - 16,716 views
My Status
Ads Sneaked Onto DavesWeb Part 2 of 2 - 16,252 views
Recently Viewed Items on DavesWeb:
TechQuest
Taking Embedded Javascript (EJS) For A Test Drive
Main
Gramma's Welcoming Quilt
Main
Another Bad Person Looking for Trouble?
Main
WFH
Main
Best of Critter Cam!
TechQuest: Welcome to TechQuest.
Taking Embedded Javascript (EJS) For A Test Drive

In an earlier post, I was showing a new way to use JavaScript to navigate an Xml document and I noticed some string-concatenating code that was a bit verbose (and was making me not miss the old JavaScript world at all).
Uploaded Image

Then I was perusing an Embedded JavaScript (EJS) Tutorial and saw some "ugly" code that resembed mine. EJS promises to clean up similar code, so I thought I'd give it a try. EJS is commonly used for building html strings from JSON data. My example used Xml data islands, so hopefully that won't be too much of a stretch.

You don't have to download it to use it (you can simply include a link to the source), but EJS is here. (http://embeddedjavascript.googlecode.com/files/ejs_0.9_alpha_1_production.js)

Add a reference to EJS in the head of your html document:
Uploaded Image

EJS uses a template file to store presentation/markup. It looks a lot like ASP and Ruby on Rails, and it, indeed, helped clean up the string concatenation in my earlier example:
Uploaded Image

Back in my main Html page, I set up some data in an array. Getting it to display couldn't have been simpler:
Uploaded Image

EJS was able to access my data and display it. However, it rendered my Html tags as text. It seems like I did it exactly the way their demo did it, but how to make the Html tags work? I didn't find anything in EJS's very sparse documentation that explained why this was happening.
Uploaded Image


I also had difficulty getting EJS to read in a JSON file and render it the same way it would for JSON data that lives in the same Html file.

I took a look at EJS's source. Why do even open source projects feel the need to obfuscate their code? Does it really optimize performance significantly to put everything on one line of code? Also I was a little surprised to see dependencies on ActiveX objects. Does this mean EJS will only work on a Windows computer?

Check EJS out for yourself:

My demo is here.

2,010 views.
No users have rated this item yet.