JSON-LD to HTML template engine - javascript

Is there any template engine which I could use to convert a JSON-LD response into HTML using javascript in the browser (or with nodejs)?
I know of SPARQL Web Pages and SPARQL Template Transformation Language. They appear to be monumental standards, which will never be implemented on any language. (At least I did not find any implementation of them.)
The closest I have found is Jassa, which is surely not production ready, or even close to it (33% coverage).
Anything else worth mentioning?

Using the Ruby JSON-LD and rdf-rdfa gems you can turn JSON-LD into RDF and serials to HTML, which uses a customizable Haml template. This is used in rdf.greggkellogg.net and linter.structured-data.org.
The other strategy is to just use it as JSON and use a regular templating engine. The earl gem does this, for example.

Related

Can we use JSTL in ReactJS?

Is it possible to use JSTL (JavaServer Pages Standard Tag Library) along with ReactJS and JSP?
ReactJS uses JSX (JSX is a syntactic extension to Javascript). Same way can it use and implement JSTL also. Though ReactJS is front end library and JSP is server side scripting, can it be achieved to a minimal extend?
It is not possible, any extension in javascript is for the browser, so it's running at clien't side. While JSTL is a server side library.
The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications. JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.
You can use it on the backend in the modern browser. You can also use it on the frontend for the client that has no javascript enabled. But it's rarely used today.

Using Handlebars for templating other than HTML?

I like how simple Handlebars is and how its design encourages the user to not put logic into the view. I have used it to template things other than HTML, but I am noticing the Handlebars.js website only discusses HTML examples. Is Handlebars only for templating HTML?
My IDE IntelliJ also only syntax checks/highlights my Handlebars files as HTML. I was hoping renaming my handlebars files with the intended extension as secondary (like Question.xml.hbs) would clue IntelliJ into my intentions, but it continued processing like I was editing HTML. There do not appear to be any pragmas in Handlebars for me to indicate what my target format or MIME type should be.
Architecturally, is it bad form to use Handlebars for purposes other than HTML templating? What if I restrict myself to HTML-like languages, like XML?
Handlebars is used mostly with HTML. But you can change template language for a specified file in the IDEA settings. See:
Update:
In the settings you can specify a template language to whole project.

Tools to retrieve static content from JSP and JS files - ANTLR?

I am trying to find out if there are any tools that exist that will get all the static content (for localization) from JSP and JS files. We want to automate the process of finding the static content from JSP and create resource bundles with them.
After some analysis it seems like some form of this can be achieved using ANTLR and XML grammar for ANTLR - http://www.antlr.org/wiki/display/ANTLR3/1.+Lexer
That is use ANTLR with XML grammar to parse JSP and use StringTemplate to output in to property bundle.
Kindly let me know if somebody has attempted same succesfully.Any help or pointer is greatly appreciated. Thanks
What you always end up discovering is that a half-baked solution is half-baked. Trying to parse JSP or JS (for the latter you really mean HTML with embedded JS?) you need parsers that will handle JSP and HTML. XML looking like HTML won't cut it; you'll just end up with parsing errors.
So, you can try to bend ANTLR's XML parser and with sufficient effort you might succeed. But then this project turns in to one of bending parsers, rather than doing localization.
Our DMS Software Reengineering Toolkit has full parsers for JSP and for JavaScript embedded in HTML, and for HTML. These parsers build full ASTs automatically and make their content available for custom output purposes.

Javascript Templating with Django

I'd really like to use a Javascript templating system together with Django. The syntax and style of Mustache.js (and it's derivatives) really sits well with me. The problem is the delimiter tag used by Mustache doesn't play nicely with the syntax of Django's templating system.
Is there any good way to use them together?
I have tried using this verbatim snippet to render the JS templates properly. The problem with that solution is I still sometimes need Django variables or URLs inside the JS.
I have also tried changing the delimiter for Mustache using
{{=[[ ]]=}}
However, that doesn't allow for using section tags, like {{#}}. The author has said he intends on removing that capability in future releases altogether.
Are there any template libraries for Javascript that follow closely to Mustache.js, but use different delimiters? Or is there another solution for changing the delimiters Mustache.js uses?
I've used jquery's templating with django. Ultimately I decided the best way is:
put all the javascript into static javascript files and serve them up without any serverside processing
in the django templates deliver all the html hooks (id's or classes) but no js.
in the js use 'document.ready' plus jquery selectors to insert tags into the page and attach events
if the js needs data then make an ajax call.
I softened on the last one and might embed data as a block of json into the django template, and perhaps also have a short js at the bottom of a template which do no more than set variables/parameters to instruct the js how to render the page - little clues from the server side telling it what to do.
Thus:
contention between the escape characters becomes a non-issue
you don't have to keep asking yourself "is this code running on the server or on the client" because you're not trying to write both at once into the one file
your javascript code is necessarily better structured and re-usable
It looks like it would be extremely easy to change Mustache's delimiters, although configurable delimiters should be supported in my opinion.
If this is not acceptable to you, there are many other templating libraries out there such as jquery-tmpl and underscore.template.
EJS is a pretty nice templating system. It uses <% %> tags.
Edit: More templating libs

Multilanguage support in my Javascript code

I'm using Django and I need to support multilanguage in my Javascript code. But my Javascript files are into site_media so they are not rendering by the template engine. I would like to learn what is the most common solution for this situation, how do you handle it generally?
Thanks
You may want to look into the l10n.js library I've written. The benefits are that you can separate language data files and code in a way that only optionally requires l10n.js.

Categories

Resources