I'm currently exploring how to use HandlebarsJS via a server-side parser.
Unfortunately we are limited to using RhinoJS server.
I've searched high and low to find out how to use HandlebarsJS via the server side. I can see how to register a helper and various other things, but I'm curious to know if it's possible to parse a JS or HTML file and have the various portions of the file replaced with the server generated content?
I'm hoping this is possible without using something like node and optimistic that it's possible to parse the file just like you would do using PHP or CFML but using JS under RhinoJS instead.
Any suggestions greatly appreciated.
Related
I have a JSON file in the same folder as my Javascript file. I have been looking for a way to simply access the JSON file and parse through it using Javascript. I thought it would be as simple as just referencing it and parsing it, however the only solutions i have found seem to be either parsing JSON that is natively stored within a Javascript file, or having to fetch a JSON file off of a server using AJAX. Surely there has to be an easy way to just reference it and open it using Javascript, right?
Thanks
JavaScript cannot access the files that are stored on server. If it could, it would cause massive security issues.
Solution 1:
That's what you do with the server-side language(e.g PHP) and then parse it to JS (for
example using json.encode() in PHP)
Solution 2:
Using AJAX call
Solution 3:
Try using it directly in same JS file or another JS and then import it
For CouchDB, I know that show function can generate HTMLs / Images / XML feed on the fly.
While in that case they have to be in the script itself and encoded (e.g. base 64 for image), as in here
What is the best way to load static resources which are attachments of design documents
e.g. As simple as JSON, or Images and process with server-side javascript?
The script file itself is an attachment in the design doc. The variable doc is not available.
Are there any way similar to node.js for it? or we use trick in context like _show or _list to show the document with id: _design/ddoc ?
doing REST request inside that environment I believe is also not possible as XMLHttpRequest is also not available. Establishing DB connection is also not possible?
This supposed to be a simple question, I wonder I am missing something in couchDB?
In order to serve a website directly, you need to use url rewrites. You'd rewrite / to got to one of your show functions. to bootstrap your site with basic HTML and JS (embedded probably).
A lot of this work has been done already by CouchApps (basic tutorial here). This is by far the easiest way to get started. This seems to be the way http://npmjs.org is served.
This isn't the place for a walkthrough, so hopefully this gives you enough information to get started.
If your site needs server-side logic (websockets for example), this solution won't work for you. All you get with a couch app is a database, HTML, CSS and Javascript.
I made a program in Java which takes an XML document, which user chooses, and present its content on screen (on JLabel using Gui). That works fine. Now, I need to create it as a web based. I want to parse a JSON file, instead of xml file, into JavaScipt. I tried to use JSP and JavaScipt in combination with HTML5 but I didn't really find the correct way to do it.
So I am wondering if there is a possible way to do it this way or if it is better to use servlets (send the data in server side).
Also, I am wondering if it is better to use the existing Java code I have, using Javabeans, instead of JavaScipt. And then combine servlets with JSP in order to print the result on screen. I know JavaScipt is quicker than Java in web applications but I think I can't see a way to make a connection between JavaScript and HTML5 to accomplish this parsing.
I would like to use GWT to read and parse local csv file.
EDIT: Local file here means client file.
I know I can use HTML5 with javascript to achieve that, but I would like to use GWT to do it.
One way of doing it is by using JavaScript Native Interface (JSNI), however I think it beats the purpose of using GWT.
Another way of doing this would be upload the file to server, and send it back as a json. But I feel it's not the best way of doing it.
Please advise. Thanks.
EDIT: I intend to design a desktop app, so I try to avoid using any web-server scripting.
Using jsni doesn't beat the purpose of gwt, sometimes you need to use it as a wrapper to functionality not yet available in gwt or an external javascript library. Instead of writting jsni access to the file api you can use one of several third party libraries available that implement html5 file access, like http://code.google.com/p/lib-gwt-file
A quick search returned this SO question: Read text file in google GWT?
Although GWT doesn't support java.io.InputStream, it looks like you could make a request to your CSV File and then parse it.
Remember that if you will host on AppEngine, you won't have a filesystem available so you'll have to have the files hosted elsewhere.
I have some XML files which are currently used to load data into Adobe Flex applications. I am trying to make an HTML5 version of the application, and I need to load this same data into the html "app" so I can use and manipulate like I would in Flex. I have searched and can't find any information or examples on how to do this, or even if it can be done.
For example, if my application is a quiz, I have the questions, choices, and correct answers in an XML file. I would like the HTML file to load this data so it can display my quiz and I can use JS and jQuery to show one question at a time. I just don't know how to "get" the xml file. I suppose I could also convert the xml to json if need be, but it would be easier to use the xml as is.
You can do that by using Ajax and a Javascript XML parser. The best way to do that is with a JS library, like jQuery.
Check out jQuery ajax to grab your XML: http://api.jquery.com/jQuery.ajax/
jParse is a pretty decent xml parser: http://jparse.kylerush.net/
Ajax is for accessing pages in the same domain. If you need to grab a file on a different domain you'll have to find a different solution.