Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install closurebuilder

How to install ClosureBuilder

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install closurebuilder
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.3.7 Available View build log
0.3.6 Available View build log
0.3.5 Available View build log
0.3.4 Available View build log
0.3.3 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.3 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
0.1a Available View build log
Windows (64-bit)
0.3.7 Available View build log
0.3.6 Available View build log
0.3.5 Available View build log
0.3.4 Available View build log
0.3.3 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.3 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
0.1a Available View build log
Mac OS X (10.5+)
0.3.7 Available View build log
0.3.6 Available View build log
0.3.5 Available View build log
0.3.4 Available View build log
0.3.3 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.3 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
0.1a Available View build log
Linux (32-bit)
0.3.7 Available View build log
0.3.6 Available View build log
0.3.5 Available View build log
0.3.4 Available View build log
0.3.3 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.3 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
0.1a Available View build log
Linux (64-bit)
0.3.7 Available View build log
0.3.6 Available View build log
0.3.5 Available View build log
0.3.4 Available View build log
0.3.3 Available View build log
0.3.2 Available View build log
0.3.1 Available View build log
0.3 Available View build log
0.2.2 Available View build log
0.2 Available View build log
0.1 Available View build log
0.1a Available View build log
 
Author
License
Apache License v2
Imports
Lastest release
version 0.3.7 on Jan 5th, 2011

Installation Instructions

pip install closurebuilder

Configuring project to use with PasteScript

Create new python package

$ paster create MyPackage

Modify MyPackage/setup.py

from setuptools import setup, find_packages
import sys, os

version = '0.1'

setup(name='MyProject',
      .....
      paster_plugins=['ClosureBuilder'],
      .....
)

Go to the MyPackage folder and execute

$ python setup.py egg_info

Now, the ClosureBuilder commands are available.

Run the following command to create the ClosureBuilder folder structure

$ paster init

This command will create the following files in mypackage folder

closure\
    sources.txt
    compiler-settings.txt
    closure-top.txt

Download latest Closure Library source files and move them into MyPackage/mypackage/closure/closure-library folder. Open sources.txt file and uncomment include directive

#
# Directories where source files can be found
#

include closure-library

include directive tells the ClosureBuilder to search source files in specified folder (in our case in closure-library folder). You can specify more than one include directive, e.g.

#
# Directories where source files can be found
#

include closure-library
include /home/andrey/some_other_library
include /home/andrey/my_library_1 strictly
include "/home/andrey/my library 2" strictly

Now we are ready to create and compile javascript application.

Creating application

Just execute the following command to create application

$ paster create-app helloworld

This command will create the following files in closure folder

helloworld\
    helloworld.js
    helloworld.css
    manifest.txt

Modify helloworld.js

.....

/**
 * helloworld.Helloworld bootstrap point
 * @final
 */
helloworld.Helloworld.prototype.entrypoint = function()
{
  alert('Hello World!!!');
}

.....

Compiling application

Execute the following command to compile your application

$ paster compile helloworld

After successful command execution the compiled files will be placed in closure/compiled/helloworld/ folder.

The ClosureBuilder standalone

If you do not want to use paster, you can use closure-builder command-line script. closure-builder has absolutely the same commands.

To initialize ClosureBuilder folder structure execute the following commands

$ mkdir MyProject
$ cd MyProject
$ closure-builder init

Now you can use closure-builder in the same manner as described above.

File closure-top.txt

NOTE: This file is used only if you use closure-builder command-line script instead of paster

The ClosureBuilder reads this file to obtain meta information of the project. At this moment only 3 fields are used: Author, Author-mail and License.

File compiler-settings.txt

This file declares common compiler settings for all applications in project.

compiler-settings directive closure-compiler option
compiler PATH_TO_JAR java -jar PATH_TO_JAR
charset CHARSET --charset CHARSET
enable error WARNING_CLASS --jscomp_error WARNING_CLASS
enable warning WARNING_CLASS --jscomp_warning WARNING_CLASS
disable warning WARNING_CLASS --jscomp_off WARNING_CLASS
summary detail level LEVEL --summary_detail_level LEVEL
warning level LEVEL --warning_level LEVEL

File sources.txt

This file declares where to search sources files.

To include/exclude all sources in specified folder (recursively):
  • include PATH
  • include PATH loosely (same as include PATH)
  • include PATH strictly
  • exclude PATH
To include/exclude specified source:
  • include source SOURCE
  • include source SOURCE loosely (same as include source SOURCE)
  • include source SOURCE strictly
  • exclude source SOURCE

Distinction between strict and loose inclusion is that strict inclusion causes an error if source provides more than one namespace.

For example, we have A, B, C and D folders. B is A's subfolder. C is B's subfolder. D is C's subfolder.

To include all sources in these folders:

include A

To include all sources in A and B folders only:

include A
exclude C

To include all sources in A and D folders only:

include A
exclude B
include D

File manifest.txt

Appliction directives Description
compile application NAMESPACE Tells the ClosureBuilder to compile application with the given namespace
compile module NAMESPACE:
module directives
Tells the ClosureBuilder to compile the given namespace as the module
scan PATH deprecated, use include strictly instead
scan loose PATH deprecated, use include instead
include PATH see above
include PATH strictly see above
exclude PATH see above
include source SOURCE see above
include source SOURCE strictly see above
exclude source SOURCE see above
set target PATH Defines the root folder where compiled files will be placed
write to FILENAME Defines the filename for application compiled code(relative to the target folder)
write css to FILENAME If specified all css files will be written as single one.
define see closure compiler --define option
enable debug see closure compiler --debug option
add extern see closure compiler --externs option
Module directives Description
set uri REFERENCE Module URL
set metadata:
module metadata
Specifies module metadata. Use goog.module.ModuleInfo.getMeta() to obtain metadata dictionary.
depends on NAMESPACE Tells the ClosureBuilder that this module depends on another module and must be loaded after it
write to FILENAME Defines the filename for module compiled code(relative to the target folder)
Module metadata Description
set KEY VALUE Stores the given value in module metadata dictionary

Example

#
# Application manifest
#

compile application myapp
set target ../public

define goog.DEBUG=false

compile module myapp.Module1:
    set uri "/public/js/module1.js"
    set metadata:
        set somemeta1 "meta1"
        set somemeta2 "meta2"
    write to js/module1.js

compile module myapp.Module2:
    set uri "/public/js/module2.js"
    write to js/module2.js

compile module myapp.Module3:
    set uri "/public/js/module3.js"
    depends on myapp.Module1
    depends on myapp.Module2
    write to js/module3.js

write to js/main.js
write css to css/main.css

CSS compilation

The ClosureBuilder can obfuscate CSS-files and generate CSS renaming map for using with goog.getCssName() function. The given feature turns on automaticly, if you use function goog.resource() in your source files. For more information see goog.getCssName().

Example

goog.provide('myapp')

goog.resource('myapp.css')
...
// now you can use goog.getCssName() to get obfuscated css class name

Module compilation

Add compile module directive to the application manifest file to tell the ClosureBuilder to compile application with specified module. The ClosureBuilder automatically adds the module info and the module url in ModuleManager. Thus, you should not do it manually.

To load the module from your application you can use the following code

goog.module.ModuleManager.getInstance().execOnLoad('myapp.Module1',
  function() {
    alert('myapp.Module1 is loaded');
  }
);

Note: Do not forget to call goog.module.ModuleManager.setLoaded() to tell the ModuleManager that module was loaded completely

Feedback

Issue tracker

Mail

Changes

0.3.7:
  • Bug fix: Module information should be added immediately after goog.module.ModuleLoader
0.3.6:
  • Bug fix: Modules with the same dependency does not compile
0.3.5
  • Bug fix: Using directives "include"/"exclude" in the manifest.txt causes an error.
0.3.4
  • New directives are available: "include source" and "exclude source"
0.3.3
  • Directive "scan" was deprecated
  • New directives are available instead of "scan" directive: "include" and "exclude"
0.3.2
  • New compiler-settings directive "compiler"
0.3.1
  • Bug fix: directive "add extern" supports now relative and absolute paths

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:4

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.