Skip to content

Commit

Permalink
release 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AE9RB committed Oct 24, 2011
1 parent a581ef1 commit 8d56a0a
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -7,17 +7,17 @@ GEM
kramdown (0.13.3)
maruku (0.6.0)
syntax (>= 1.0.0)
minitest (2.6.0)
minitest (2.6.2)
rack (1.3.2)
rake (0.9.2)
rake (0.9.2.2)
rubyzip (0.9.4)
syntax (1.0.0)
warbler (1.3.2)
jruby-jars (>= 1.4.0)
jruby-rack (>= 1.0.0)
rake (>= 0.8.7)
rubyzip (>= 0.9.4)
yard (0.7.2)
yard (0.7.3)

PLATFORMS
ruby
Expand Down
149 changes: 127 additions & 22 deletions README.md
@@ -1,42 +1,147 @@
#Google Closure Compiler, Library, Script, and Templates.
# Closure Script

A development environment for Google Closure Tools.

Licensed under the Apache License, Version 2.0 (the "License");
<http://www.apache.org/licenses/LICENSE-2.0>

## Java

### Step 1: Download to a new folder

<https://github.com/dturnbull/closure-script/downloads>
# Installing

### Step 2: Run from the new folder with Java
Everything you need for advanced Google Closure development is available in a
single .jar for the Java Virtual Machine. You may also run the tools on any
Ruby platform (>=1.8.6) including JRuby (JVM), Rubinius (LLVM), and Ruby 1.9 (YARV).

``` java -jar closure.jar ```
It is generally easier to get started with the .jar distribution, especially
under Windows. Mac OSX and most Linux will have a compatible Ruby by default.

### Step 3: Open a web browser
## Java (.jar)

<http://localhost:8080/>
### Step 1: Download to a new folder

cd ~/empty-dir
curl -LO https://github.com/downloads/dturnbull/closure-script/closure-1.4.0.jar

## Ruby
### Step 2: Start server from the new folder

### Step 1: Obtain a project
If you need a new project, it is recommended to start with the Java version.
You can switch to the Ruby Gem at any time.
java -jar closure-1.4.0.jar

### Step 2: Install the gem
### Step 3: Open a web browser

``` gem install closure ```
http://localhost:8080/

### Step 3: Start any web server that reads config.ru

``` rackup ```
## Ruby (.gem)

### Step 4: Open a web browser
### Step 1: Install the gem

<http://localhost:8080/>
gem install closure

### Step 2: Start server from a new folder

## More Information
cd ~/empty-dir
closure-script

### Step 3: Open a web browser

<https://github.com/dturnbull/closure-script/blob/master/docs/SCRIPT.md>
http://localhost:8080/


# The Closure Script Method

When you start the server for the first time in an empty folder, the home page
will prompt you to install scaffolding. This includes three example projects to
demonstrate soy, modules, and unobtrusive markup. Dissecting and working with
these examples is the fast track to understanding The Closure Script Method.

## The Server

Closure Script is a high-performance, multi-threaded web application engineered
exclusively for the needs of Google Closure Javascript development.

You will be freed from the command line. All error output from the compiler
will show on the Javascript console. This avoids lost time from not being
in the correct log and missing an important error. Javascript compilation
is done just-in-time and only when source files have changed.
No need for a separate build step; just refresh the browser. Not working?
Check your Javascript console. Then back to your editor.

## Easy Configuration

You'll need to supply the directories where you have source Javascript and static files.
Ruby developers will recognize that Closure Script is Rack middleware. This makes it trivial
to include the Closure Script build tool in a Rails application. If you're not developing a
Ruby application, your ```config.ru``` will probably never be more complex than the following:

require 'closure'
Closure.add_source '.', '/'
use Closure::Middleware, 'index'
run Rack::File.new '.'

The add_source command may be duplicated for each source Javascript folder you want to
serve. The first argument is the local filesystem path, the second is the mount point
for the http server. Make sure not to accidentally serve more than one copy of
Closure Library per Closure Script server or you'll get an error.

## Cut-and-Paste Ruby

In practice, all you do with Ruby is adjust the arguments to compiler.jar by
analyzing options on the URL query string. If you can handle conditionally appending
strings to an array in Ruby, then you're fully qualified to use Closure Script!
There's enough example code in the scaffolding to cut-and-paste your way to victory.

### Demo Scripts

The Closure Script Method is to create various demo pages to drive development. You may
also choose to use your main application instead of Closure Script for your demo pages.

Files ending with .erb are Closure Scripts and will have their embedded Ruby evaluated
as they are served. Scripts may also render other Scripts and pass variables if you
need that complexity. Scripts default to a MIME type of text/html so ```demo.erb``` is
the same as ```demo.html.erb```.

<html>
<head>
<script src='compiler.js?<%= query_string %>'></script>
</head>

### Compiler Scripts

Compilation is performed by requesting a file that generates Javascript instead of HTML.
The goog.compile() function of Closure Script handles everything for you.

Note that goog.compile() does not simply call the compiler. It will monitor your source
files and skip calling the compiler if everything is up to date. The Java process will
remain running on a REPL so subsequent compilations don't pay the Java startup cost.
The dependency tree for all your sources is known so you can build from namespaces
(--ns) as well as files (--js). Modules have been automated to find common dependencies,
like plovr, and work from namespaces so you don't need to use filenames and counts.
The luxurious goog.compile() can serve up a loader for the raw, uncompiled files,
even when working with modules.

A very simple compiler.js.erb is as follows. Check the scaffold for practical examples
that use the query string.

<%
args = %w{
--compilation_level ADVANCED_OPTIMIZATIONS
--js_output_file compiler_build.js
--ns myapp.helloWorld
}
@response = goog.compile(args).to_response
%>

### Testing

Closure Script helps with testing because it can see your data in ways that
browsers are not allowed to. The ```alltests.js``` file in Closure Library is
generated by a program that scans the filesystem. Here's a replacement in
Closure Script so that a manual build step never has to be executed again:

<% all_test_files = Dir.glob expand_path '**/*_test.html'
json_strings = all_test_files.map { |x| relative_src(x).dump }
-%>var _allTests = [<%= json_strings.join(',') %>];

Since all of Ruby is at your disposal, you could even pull fixture data from SQL
or a web service. Perhaps a fixture refresh happens when the developer pushes a
form button. The svn.erb tool is a complex example that uses threads and a
background process. You're only limited by your imagination.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -28,7 +28,7 @@ DOCS = %w{closure erb rack haml kramdown}
desc 'Start the Closure Script server'
task 'server' do
require 'rack'
Rack::Server.start :config => "config.ru"
::Rack::Server.start :config => "config.ru"
end

desc 'Start the Closure Script welcome server'
Expand Down
19 changes: 19 additions & 0 deletions bin/closure-script
@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
begin
require 'rubygems'
rescue LoadError
end
require 'rack'
closure_lib_path = File.expand_path('../lib', File.dirname(__FILE__))
if File.exist? File.join closure_lib_path, 'closure.rb'
$LOAD_PATH.unshift(closure_lib_path) if !$LOAD_PATH.include?(closure_lib_path)
end
if File.exist? 'config.ru'
Rack::Server.start
else
require 'closure'
ENV["CLOSURE_SCRIPT_WELCOME"] = 'true'
Rack::Server.start :config => File.join(Closure.base_path, 'scripts/config.ru')
end


3 changes: 2 additions & 1 deletion closure.gemspec
Expand Up @@ -16,10 +16,11 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"
s.add_dependency 'rack', '>= 1.0.0'

dirs = %w{beanshell closure-compiler closure-templates lib docs/closure}
dirs = %w{beanshell bin closure-compiler closure-templates lib docs/closure}
dirs += Dir.glob('scripts/*') - %w{scripts/closure-library scripts/fixtures}
s.require_path = 'lib'
s.files = Dir.glob("{#{dirs.join ','}}/**/*")
s.files += %w(LICENSE README.md docs/index.erb docs/SCRIPT.md)
s.files += Dir.glob('scripts/*')
s.executables = ['closure-script']
end
16 changes: 2 additions & 14 deletions lib/closure.rb
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'rack'
require 'ostruct'
require 'tempfile'

Expand All @@ -28,19 +29,6 @@

class Closure

autoload(:VERSION, 'closure/version')
autoload(:BeanShell, 'closure/beanshell')
autoload(:Script, 'closure/script')
autoload(:Sources, 'closure/sources')
autoload(:FileResponse, 'closure/file_response')
autoload(:Middleware, 'closure/middleware')
autoload(:Compiler, 'closure/compiler')
autoload(:Server, 'closure/server')
autoload(:Goog, 'closure/goog')
autoload(:Templates, 'closure/templates')
autoload(:ShowExceptions, 'closure/show_exceptions')


# Filesystem location of the Closure Script install.
# Typically, where the gem was installed. This is mainly used
# internally but may be useful for experimental configurations.
Expand Down Expand Up @@ -134,7 +122,6 @@ def self.config
end
@@config
end
require 'closure/engines'

# Run the welcome server. Handy for gem users.
# @example
Expand All @@ -154,3 +141,4 @@ def self.welcome

end

Dir.glob(File.expand_path('**/*.rb', File.dirname(__FILE__))).each {|f| require f}
2 changes: 1 addition & 1 deletion lib/closure/version.rb
Expand Up @@ -14,5 +14,5 @@


class Closure
VERSION = "1.4.0.pre"
VERSION = "1.5.0.pre"
end
Binary file removed vendor/cache/minitest-2.6.0.gem
Binary file not shown.
Binary file added vendor/cache/minitest-2.6.2.gem
Binary file not shown.
Binary file added vendor/cache/rake-0.9.2.2.gem
Binary file not shown.
Binary file removed vendor/cache/rake-0.9.2.gem
Binary file not shown.
Binary file removed vendor/cache/yard-0.7.2.gem
Binary file not shown.
Binary file added vendor/cache/yard-0.7.3.gem
Binary file not shown.

0 comments on commit 8d56a0a

Please sign in to comment.