Compiling dust.js template to html server side? - javascript

Is it possible to compile dust.js template to plain html?
I tried dusty and dustc serverside compilers but they generates a javascript file which will write the content of the template on the page.

Dust only compiles to JavaScript, but you can use a compiled template to render plain HTML. This works the same on the server and on the client. On the server you need to use Node.js or Rhino (or some other engine that interprets JavaScript).

It is possible to render a dust template directly to HTML, but it is not recommended. Anyway, this can be done with pyv8 a Python bindings for V8 JS engine.
In this article Andrew Wilkinson show how he made it for mustache.js.

Related

Javascript frameworks just "markup" for javascript?

I am a little curious about how javascript frameworks work. Web development isn't really my area of expertise (I'm more of a c/c++ guy), but do javascript frameworks get translated into vanilla javascript?
Upon inspection of website source, it seems like it is mostly just standard javascript. Do these javascript engines just translate code into javascript on the server side?
Yes, most of JavaScript Frameworks translates the code you write to vanilla JavaScript, however, this does not happen on the Server Side, that would be really slow (Server side code is used to check databases, serve files, authenticate, etc.). This process of translation is done in compilation time (Although it is translation). (Just like when you compile c++ code into binary).
When it's source code to source code like JavaScript and React (JSX) to Vanilla JavaScript (JS), it's translation. When it's source code to binary like C++ source code to an executable (.exe) is compilation.
After you're done writting your JavaScript code with frameworks, you most translate it to Vanilla JavaScript (if you also used other uncommon languages to write styles, you must translate them too, like SASS instead of CSS). It is also common to minify it, so it can load faster.
All this is mainly done by tools like webpack.
When your site is up and running, we can say that is run time.
Looking at the fact that they were written in js they would be resolved to js before running and as Robin said they are executed on client side except Node which is a runtime environment and not a framework

Does Webassembly end up as rendered HTML in the browser?

Webassembly can compile say C# to bytecode, executable by the browser.What is its rendered form in the browser? HTML with JavaScript? Or something like Silverlight or a Java applet that runs inside the browser such as a business app with rich GUIs?
Your application code written in C# is compiled into asp.net assembly, and is managed by the mono run time, which was compiled to WebAssembly. What is rendered in the browser is html through manipulation of the DOM using JavaScript interop; that is, your C# code communicate with JavaScript code to manipulate the DOM, and rerender the diffs.
In simple terms WebAssembly is a lightweight virtual machine that can executed numeric instructions. It cannot render HTML, or use any WebAPIs directly.
You cannot however import / export WebAssembly functions to allow it to communicate with JavaScript. Therefore WebAssembly apps tend to use DOM or canvas via Javascript bindings.

Which editor to use for coding dynamic web pages

I am new to web development and I see it is very common to print HTML syntax from some server side script which is typically written in python, php, perl etc.
Now, normally all editors have some features which can help with syntax checking of the HTML as the programmer is writing them.
However, if the HTML code is emitted from a print statement, how can HTML syntax checking be done.
For example
the server side python script generating an HTML form can be like
print("<td><input type="file" name="upload_file" />")
Here the ending tag
</td> is missing. Is there an editor which can warn about this. Otherwise, how do the programmers deal with it.
You can't display this code using python. If you want to create a server, you will need to look for the development of the server side (these are the three most used):
Flask
Django
Tornado
Also, you can check more web frameworks here: https://wiki.python.org/moin/WebFrameworks
use sublime, its light weight and have lots of features.
For any non-trivial work it's best not to embed HTML (or any other language) in your Python code. Use a templating engine such as jinja2 or one of the others available. Most Python web frameworks support integration with at least one templating engine.
Separating your code and markup by using a templating engine makes your code easier to maintain. In particular, files for templating engine code are essentially HTML with some additional markup to allow for variable substitution, looping etc and so your editor's HTML syntax highlighting will work on them.

How to integrate curl.js with server-side jinja2 templating

I have a Python-based Flask web application that uses Jinja2 to perform templating on the server-side.
I would like to improve my Javascript and CSS loading by using curl.js to load JS and CSS asynchronously.
Is there a specific, well-defined method for doing this?

how write text/template in a file and include it to project

I use script type="text/template" for my project and I use a lot of templates, I want write my template in foreign file and include it to my html
If its possible , what type of file must i use and how must write it ?
In a pure JavaScript/HTML environment, you can't easily.
Your choices are:
Use some kind of JavaScript template library
I'm only familiar with Durandal that uses the Knockout engine.
AngularJS seems to be another popular choice.
Most of these packages include far more than just templates and may be overkill.
Use a server-side template package
PHP is a popular server-side tool.
Some HTTP Servers support Server Side Includes, but these are so limited I couldn't actually recommend them.

Categories