Permalink
Browse files

import closure processor

  • Loading branch information...
0 parents commit 0aa4cf6535ad69d69963778d8c5148211df182c8 @igrigorik committed Aug 4, 2011
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in closure-sprockets.gemspec
+gemspec
@@ -0,0 +1,32 @@
+# Closure Sprockets
+
+Sprockets processor for Google's [Closure tools](http://code.google.com/closure/).
+
+## Integrating with Rails 3
+
+If you want to use closure as your JS library in Rails 3, add the gem to your Gemfile:
+
+```ruby
+gem 'closure-sprockets'
+gem 'closure-compiler' # optional, see below
+````
+
+If you also want to use the closure compressor to minify your Javascript, then change your environment config to:
+
+```ruby
+config.assets.js_compressor = Closure::Compiler.new
+```
+
+Finally, [download the latest version](http://code.google.com/closure/library/docs/gettingstarted.html) of closure library from Google and put it in `vendor/assets`.
+
+## Optional configuration
+
+If you decided to put your `closure-library` directory somewhere other than `vendor/assets`, then you'll have to update your environment config with the right path:
+
+```ruby
+config.closure.lib = 'vendor/assets/path/to/closure-library
+```
+
+### License
+
+(MIT License) - Copyright (c) 2011 Ilya Grigorik
@@ -0,0 +1 @@
+require 'bundler/gem_tasks'
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "closure-sprockets/version"
+
+Gem::Specification.new do |s|
+ s.name = "closure-sprockets"
+ s.version = Closure::Sprockets::VERSION
+ s.authors = ["Ilya Grigorik"]
+ s.email = ["ilya@igvita.com"]
+ s.homepage = "https://github.com/igrigorik/closure-sprockets"
+ s.summary = "Sprockets processor for Google's Closure tools"
+ s.description = s.summary
+
+ s.rubyforge_project = "closure-sprockets"
+ s.add_dependency "tilt"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end
@@ -0,0 +1,5 @@
+require "tilt"
+
+require "closure-sprockets/version"
+require "closure-sprockets/processor"
+require "closure-sprockets/railtie" if defined?(Rails)
@@ -0,0 +1,21 @@
+class ClosureDependenciesProcessor < Tilt::Template
+ def prepare; end
+
+ def evaluate(context, locals, &block)
+ context.require_asset 'goog/base'
+
+ data.lines.each do |line|
+
+ if line =~ /goog\.require\s*\(\s*[\'\"]([^\)]+)[\'\"]\s*\)/
+ goog, mod, sub = $1.split(".")
+ next if mod =~ /^Test/
+ sub = mod if sub.nil?
+
+ dep = [goog, mod, sub].compact.join("/").downcase
+ context.require_asset(dep)
+ end
+ end
+
+ data
+ end
+end
@@ -0,0 +1,12 @@
+module KlosureProcessor
+ class Railtie < Rails::Railtie
+ config.closure = ActiveSupport::OrderedOptions.new
+ config.closure.lib = 'vendor/assets/closure-library/closure'
+
+ config.after_initialize do |app|
+ app.assets.append_path config.closure.lib
+ app.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor
+ end
+
+ end
+end
@@ -0,0 +1,5 @@
+module Closure
+ module Sprockets
+ VERSION = "0.1.0"
+ end
+end

0 comments on commit 0aa4cf6

Please sign in to comment.