Class: Configurator

Configurator


new Configurator(dir)

Object used to read and manipulate the config.xml file of an ADX

 const ADX = require('adxutil').ADX;

 const myAdx = new ADX('path/to/adx/');
 myAdx.load(function (err) {
     if (err) {
         throw err;
     }

     // Get the instance of the Configurator
     const conf = myAdx.configurator;

     console.log(conf.info.name());

 });
Parameters:
Name Type Description
dir String

Path of the ADX directory

Classes

Info
Outputs
Properties

Members


info :Configurator.Info

Info of the ADX

Type:

outputs :Configurator.Outputs

Outputs of the ADX

Type:

path :String

Path of the ADX directory

Type:
  • String

projectType :String|"adc"|"adp"

Type of the project (adc or adp)

Type:
  • String | "adc" | "adp"

projectVersion :String

Version of the ADX project

Type:
  • String

properties :Configurator.Properties

Properties of the ADX

Type:

Methods


fromXml()

Re-init the configurator using the xml string

  // Load the configuration using an xml string
  // xmlString contains information from config.xml
  configurator.fromXml(xmlString);

get()

Get the entire configuration as object

  // Get the info object
  configurator.get();
  // {
  //   info : { // .... },
  //   outputs : { // ... },
  //   properties : { // ...}
  // }
Returns:
Type
Object

load( [callback])

Read the config.xml file and initialize all properties of the current instance object

  // Load the config file
  configurator.load(function (err) {
     if (err) {
         throw err;
     }
     console.log(adxInfo.name());
  });
Parameters:
Name Type Argument Description
callback function <optional>

Callback function

Properties
Name Type Argument Description
err Error <optional>

Error


save( [callback])

Save the current configuration

Parameters:
Name Type Argument Description
callback function <optional>
Properties
Name Type Description
err Error

set(data)

Set th configuration using an object

  // Get the info object
  configurator.set(
     info {
         name : "My ADC"
         version : "2.2.0.beta1",
         date  : "2015-06-25",
         guid  : "the-guid",
         description : "Description of the ADC"
         author  : "The author name",
         company : "The company name",
         site    : "http://website.url.com",
         helpURL : "http://help.url.com",
         constraints : {
             questions : {
                single : true,
                multiple : true
             },
             controls : {
                 responseBlock : true
             },
             responses : {
                 max : 10
             }
         }
     },
     outputs : {
         defaultOutput : "main",
         outputs : [
            {
                id : "main",
                description : "Main output",
                 contents : [
                      {
                         fileName : 'main.css',
                         type : 'css',
                         mode : 'static',
                         position : 'head'
                     },
                     {
                         fileName : 'main.html',
                         type : 'html',
                         mode : 'dynamic',
                         position : 'placeholder'
                     },
                     {
                         fileName : 'main.js',
                         type : 'javascript',
                         mode : 'static',
                         position: 'foot'
                     }
                 ]
             },
             {
                 id : "second",
                 description : "Second output",
                 condition : "Browser.Support(\"javascript\")",
                 contents : [
                     {
                         fileName : 'second.css',
                         type : 'css',
                         mode : 'static',
                         position : 'head'
                     },
                     {
                         fileName : 'second.html',
                         type : 'html',
                         mode : 'dynamic',
                         position : 'placeholder'
                     },
                     {
                         fileName : 'second.js',
                         type : 'javascript',
                         mode : 'static',
                         position : 'foot'
                     }
                 ]
             },
             {
                 id : "third",
                 description : "Third output",
                 maxIterations : 12,
                 defaultGeneration : false,
                 contents : [
                     {
                         fileName : "third.css",
                         type  : "css",
                         mode : "static",
                         position : "head",
                         attributes : [
                             {
                                 name : "rel",
                                 value : "alternate"
                             },
                             {
                                 name : "media",
                                 value : "print"
                             }
                         ]
                     },
                     {
                         fileName : 'HTML5Shim.js',
                         type : 'javascript',
                         mode : 'static',
                         position : 'head',
                         yieldValue : '<!--[if lte IE 9]><script type="text/javascript"  src="{%= CurrentADC.URLTo("static/HTML5Shim.js") %}" ></script><![endif]-->'
                     }
                 ]
            }
         },
         properties : {
             categories : [
                {
                    id : "general",
                    description : "General",
                    properties  : [
                          {
                             id : "background",
                             name : "Background color",
                             type : "color",
                             description : "Color of the ADC background",
                             colorFormat : "rgb",
                             value  : "255,255,255"
                         }
                   ]
                }
             ]
         }
   });
Parameters:
Name Type Description
data Object

Data to set

Properties
Name Type Argument Description
info Object <optional>

Info data

outputs Object <optional>

Outputs data

properties Object <optional>

Properties data


toXml()

Return the configuration as xml

  // Serialize the config to XML
  configurator.toXml();
  // -> <?xml version="1.0" encoding="utf-8"?>
        <control  xmlns="http://www.askia.com/2.1.0/ADCSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.askia.com/2.1.0/ADCSchema https://raw.githubusercontent.com/AskiaADX/ADXSchema/2.1.0/ADCSchema.xsd"
        version="2.1.0"
        askiaCompat="5.4.2">
            <info>
                <name>My Name</name>
                <guid>the-guid</guid>
                ....
            </info>
            <outputs defaultOutput="default">
                ....
            </outputs>
            <properties>
                ....
            </properties>
          </control>
Returns:
Type
String