Giter Site home page Giter Site logo

tiankui / closure-compiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from documentcloud/closure-compiler

1.0 1.0 0.0 30.95 MB

A Ruby Wrapper for the Google Closure Compiler

Home Page: http://github.com/documentcloud/closure-compiler

License: Other

closure-compiler's Introduction

The Closure Compiler (as a Ruby Gem)

The closure-compiler gem is a svelte wrapper around the Google Closure Compiler for JavaScript compression.

Latest Version: 1.1.6

The Closure Compiler’s 2012-03-05 JAR-file is included with the gem.

Installation

sudo gem install closure-compiler

Usage

The Closure::Compiler has a single method, compile, which can be passed a string or an open IO object, and returns the compiled JavaScript. The result is returned as a string, or, if a block is passed, yields as an IO object for streaming writes.

require 'rubygems'
require 'closure-compiler'
Closure::Compiler.new.compile(File.open('underscore.js', 'r'))

=> "(function(){var j=this,m=j._;function i(a){......

When creating a Closure::Compiler, you can pass any options that the command-line compiler accepts to the initializer and they’ll be forwarded. For example, to raise the compilation level up a notch:

closure = Closure::Compiler.new(:compilation_level => 'ADVANCED_OPTIMIZATIONS')
closure.compile(File.open('underscore.js', 'r'))
  
=> "(function(){var j=this,m=j.h;function i(a){......

The default values of all the compiler flags are identical to the command-line version. The default compilation_level is “SIMPLE_OPTIMIZATIONS”.

A Closure::Error exception will be raised, explaining the JavaScript syntax error, if compilation fails for any reason.

YUI Compressor Compatibility

Effort has been made to make the “closure-compiler” gem a drop-in alternative to the “ruby-yui-compressor”. To that end, Closure::Compiler#compile has been aliased as compress, and can take the same string or IO argument that a YUI::JavaScriptCompressor#compress can. In addition, the Closure::Compiler initializer can take java and jar_file options, overriding the location of the Java command and the Closure Compiler JAR file, respectively.

compiler = Closure::Compiler.new(
  :java     => '/usr/local/bin/java16',
  :jar_file => '/usr/src/closure/build/latest.jar'
)

closure-compiler's People

Contributors

ghazel avatar jashkenas avatar josh avatar kares avatar lapluviosilla avatar xiazek avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.