Class zebkit.Package <zebkit>

Package is a special class to declare zebkit packages. Global variable "zebkit" is root package for all other packages. To declare a new package use "zebkit" global variable:

// declare new "mypkg" package
zebkit.package("mypkg", function(pkg, Class) {
    // put the package entities in
    pkg.packageVariable = 10;
    ...
});
...

// now we can access package and its entities directly
zebkit.mypkg.packageVariable

// or it is preferable to wrap a package access with "require"
// method
zebkit.require("mypkg", function(mypkg) {
    mypkg.packageVariable
});
Constructor:
zebkit.Package ( )


private void $detectLocation ( )

Detect the package location and store the location into "$url" package field

public <zebkit.Package> byName (name)

Get a package by the specified name.


Parameters:
  • name <String>

    a package name


Returns: <zebkit.Package>

a package

public <String> cd (path)

Find a package with the given file like path relatively to the given package.


Parameters:
  • path <String>

    a file like path


Returns: <String>

path a path


Example:
 // declare "zebkit.test" package
 zebkit.package("test", function(pkg, Class) {
     ...
 });
 ...

 zebkit.require("test", function(test) {
     var parent = test.cd(".."); // parent points to zebkit package
     ...
 });
public void config ([name], [value], [overwrite])

Get or set configuration parameter.


Parameters:
  • [name] <String>

    a parameter name.

  • [value] <Object>

    a parameter value.

  • [overwrite] <Boolean>

    boolean flag that indicates if the parameters value have to be overwritten if it exists

public void configWith (path, [cb])

Configure the given package with the JSON.


Parameters:
public void configWithRs (path, [cb])

Configure the given package with the JSON.


Parameters:
public <String> fullname ( )

Get full name of the package. Full name includes not the only the given package name, but also all parent packages separated with "." character.


Returns: <String>

a full package name

public <zebkit.Package> getRootPackage ( )

Detect root package.


Returns: <zebkit.Package>

a root package

public <String> import ([pkgname])

Build import JS code string that can be evaluated in a local space to make visible the given package or packages classes, variables and methods.


Parameters:
  • [pkgname] <String> (*..n)

    names of packages to be imported


Returns: <String>

an import string to be evaluated in a local JS space


Example:
(function() {
    // make visible variables, classes and methods declared in "zebkit.ui"
    // package in the method local space
    eval(zebkit.import("ui"));

    // use imported from "zebkit.ui.Button" class without necessity to specify
    // full path to it
    var bt = new Button("Ok");
})();
public void ls (cb, [all])

List classes, variables and interfaces defined in the given package. If second parameter "all" passed to the method is false, the method will skip package entities whose name starts from "$" or "_" character. These entities are considered as private ones. Pay attention sub-packages are not listed.


Parameters:
  • cb <Function>

    a callback method that get the package entity key and the entity value as arguments.

  • [all] <Boolean>

    flag that specifies if private entities are should be listed.

public <zebkit.Package> package (name, [callback], [config])

Method that has to be used to declare packages.


Parameters:
  • name <String>

    a name of the package

  • [callback] <Function>

    a call back method that is called in package context. The method has to be used to populate the given package classes, interfaces and variables.

  • [config] <String | Boolean>

    a path to configuration JSON file or boolean flag that says to perform configuration using package as configuration name


Returns: <zebkit.Package>

a package


Example:
// declare package "zebkit.log"
zebkit.package("log", function(pkg) {
    // declare the package class Log
    pkg.Log = zebkit.Class([
         function error() { ... },
         function warn()  { ... },
         function info()  { ... }
    ]);
});

// later on you can use the declared package stuff as follow
zebkit.require("log", function(log) {
    var myLog = new log.Log();
    ...
    myLog.warn("Warning");
});
public void packages (callback, [recursively])

List the package sub-packages.


Parameters:
  • callback <Function>

    callback function that gets a sub-package name and the sub-package itself as its arguments

  • [recursively] <Boolean>

    indicates if sub-packages have to be traversed recursively

public void require ([packages], [callback])

This method has to be used to start building a zebkit application. It expects a callback function where an application code has to be placed and number of required for the application packages names. The call back gets the packages instances as its arguments. The method guarantees the callback is called at the time zebkit and requested packages are loaded, initialized and ready to be used.


Parameters:
  • [packages] <String> (*..n)

    name or names of packages to make visible in callback method

  • [callback] <Function>

    a method to be called. The method is called in context of the given package and gets requested packages passed as the method arguments in order they have been requested.


Example:
zebkit.require("ui", function(ui) {
    var b = new ui.Button("Ok");
    ...
});
public void resources (paths, cb)

This method loads resources (images, textual files, etc) and call callback method with completely loaded resources as input arguments.


Parameters:
  • paths <String> (*..n)

    paths to resources to be loaded

  • cb <Function>

    callback method that is executed when all listed resources are loaded and ready to be used.


Example:
zebkit.resources(
    "http://test.com/image1.jpg",
    "http://test.com/text.txt",
    function(image, text) {
        // handle resources here
        ...
    }
);
private chainable then (f)

This method helps to sync accessing to package entities with the package internal state. For instance package declaration can initiate loading resources that happens asynchronously. In this case to make sure the package completed loading its configuration we should use package "then" method.


Parameters:
  • f <Function>

    a callback method where we can safely access the package entities


Example:
zebkit.then(function() {
    // here we can make sure all package declarations
    // are completed and we can start using it
});

private <Object> $config

Package configuration parameters.

public <String> $name

Name of the package

private <zebkit.Package> $parent

Reference to a parent package

public <String> $url

URL the package has been loaded