Javascript Code Generator - Zontroy

Javascript Code Generator

Generate Javascript Code in Minutes

A Javascript Code Generator is a tool make coding faster. As a result it produces code files like written by a developer. A javascript developer can generate tones of code using Zontroy Code Generator. Let’s start then:

Create a Project

Create a Zontroy project to begin generating as clicking File -> New Project menu.

In New Project window select Empty Zontroy Project and click Create button.

Select Data Source as what your data sourse is such as PostgreSQL, MSSQL, MySQL, Oracle or Entity Classes.

After selection enter Database credintials and select programming Language as Javascript. Give a project name and select the location of Zontroy project that will be created in your computer.

Create a Template File and Implement It

Create a Zontroy Repeating File as template file and inside it write the generation code below. To add a template file right click on the main folder and click Add File.

In the New File window select Zontroy Repeating File (.zref) and give a name like below.

In Zontroy you can write code in file name. The file name means that create a file for each entity in data source and name it same as entity name.

After entering the name Click Add File button.

function readFormData() {
    var formData = {};
    zg-for(((zg-item:::[[[zg-entity...zg-fields]]]))){{{
    formData["[[[zg-item...zg-name]]]"] = document.getElementById("[[[zg-item...zg-name]]]").value;}}}
    return formData;
}

In this Zontroy code file, we are implementing readFormDate function. For each form data item we are iterating fields in our entity and name it as zg-item.

[[[zg-entity…zg-fields]]] is a predefined collection of fields of an entity.

In for loop, right now we can access to field property zg-name as writing [[[zg-item…zg-name]]].

In the background Zontroy is getting the name of each field and writing it to each entity code file. Like this, we can also access other properties of a field such as data type, target type (the type in js), label etc.

Generate Your Code

Right click on the template file and click Generate This File(s).

You will see generated files.

Open the files as double clicking and see the generated files and code lines.

actor.js

function readFormData() {
    var formData = {};
    
    formData["actor_id"] = document.getElementById("actor_id").value;
    formData["first_name"] = document.getElementById("first_name").value;
    formData["last_name"] = document.getElementById("last_name").value;
    formData["last_update"] = document.getElementById("last_update").value;
    return formData;
}

address.js

function readFormData() {
    var formData = {};
    
    formData["address_id"] = document.getElementById("address_id").value;
    formData["address"] = document.getElementById("address").value;
    formData["address2"] = document.getElementById("address2").value;
    formData["district"] = document.getElementById("district").value;
    formData["city_id"] = document.getElementById("city_id").value;
    formData["postal_code"] = document.getElementById("postal_code").value;
    formData["phone"] = document.getElementById("phone").value;
    formData["last_update"] = document.getElementById("last_update").value;
    return formData;
}

We completed our code generation. Just in a few minutes we create 15 files and implemented them. This is just a simple example and you can create javascript files fully.

You can find more detailed info about javascript in official website and you can fine more about Zontroy in Docs.

Comments

  • Priya Antony

    23 April 2022

    It is very helpful

    reply
    • Zontroy

      25 April 2022

      Hi, thank you for using Zontroy to generate Javascript!

      Best regards.

      reply

Post a Comment