closure-sprockets 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in closure-sprockets.gemspec
4
+ gemspec
@@ -0,0 +1,52 @@
1
+ # Closure Sprockets
2
+
3
+ Sprockets preprocessor for Google's [Closure tools](http://code.google.com/closure/).
4
+
5
+ ## Integrating with Rails 3
6
+
7
+ If you want to use closure as your Javascript library in Rails 3, add this gem to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'closure-sprockets'
11
+ ````
12
+ The gem ships with a Railtie which will automatically register a Closure preprocessor. From here, two more steps:
13
+
14
+ - [Download the latest version](http://code.google.com/closure/library/docs/gettingstarted.html) of closure library from Google and put it in `vendor/assets`
15
+ - Write some closure code!
16
+
17
+ ```js
18
+ // in one of your javascript files
19
+ goog.require('goog.dom');
20
+
21
+ newHeader = goog.dom.createDom('h1', {}, 'Hello world!');
22
+ goog.dom.appendChild(document.body, newHeader);
23
+ }
24
+ ```
25
+
26
+ That's it! Point your browser at your page and you should have a hello world greeting from Google Closure, preprocessed by the Rails 3 Asset Pipeline and without any external Python dependencies or dynamic Javascript loading.
27
+
28
+ ## Optional configuration
29
+
30
+ 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:
31
+
32
+ ```ruby
33
+ config.closure.lib = 'vendor/assets/path/to/closure-library'
34
+ ```
35
+
36
+ ## Using Closure Compressor for Minification
37
+
38
+ Closure also provides its own Javascript compressor. If you wish to use it, pull in the [closure-compiler](https://github.com/documentcloud/closure-compiler) gem:
39
+
40
+ ```ruby
41
+ # in your Gemfile
42
+ gem 'closure-compiler'
43
+ ````
44
+
45
+ ```ruby
46
+ # in your environment configuration
47
+ config.assets.js_compressor = Closure::Compiler.new
48
+ ```
49
+
50
+ ### License
51
+
52
+ (MIT License) - Copyright (c) 2011 Ilya Grigorik
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "closure-sprockets/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "closure-sprockets"
7
+ s.version = Closure::Sprockets::VERSION
8
+ s.authors = ["Ilya Grigorik"]
9
+ s.email = ["ilya@igvita.com"]
10
+ s.homepage = "https://github.com/igrigorik/closure-sprockets"
11
+ s.summary = "Sprockets processor for Google's Closure tools"
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "closure-sprockets"
15
+ s.add_dependency "tilt"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,5 @@
1
+ require "tilt"
2
+
3
+ require "closure-sprockets/version"
4
+ require "closure-sprockets/processor"
5
+ require "closure-sprockets/railtie" if defined?(Rails)
@@ -0,0 +1,21 @@
1
+ class ClosureDependenciesProcessor < Tilt::Template
2
+ def prepare; end
3
+
4
+ def evaluate(context, locals, &block)
5
+ context.require_asset 'goog/base'
6
+
7
+ data.lines.each do |line|
8
+
9
+ if line =~ /goog\.require\s*\(\s*[\'\"]([^\)]+)[\'\"]\s*\)/
10
+ goog, mod, sub = $1.split(".")
11
+ next if mod =~ /^Test/
12
+ sub = mod if sub.nil?
13
+
14
+ dep = [goog, mod, sub].compact.join("/").downcase
15
+ context.require_asset(dep)
16
+ end
17
+ end
18
+
19
+ data
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module ClosureProcessor
2
+ class Railtie < Rails::Railtie
3
+ config.closure = ActiveSupport::OrderedOptions.new
4
+ config.closure.lib = 'vendor/assets/closure-library/closure'
5
+
6
+ initializer :setup_closure do |app|
7
+ app.assets.append_path config.closure.lib
8
+ app.assets.register_preprocessor 'application/javascript', ClosureDependenciesProcessor
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Closure
2
+ module Sprockets
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: closure-sprockets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ilya Grigorik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tilt
16
+ requirement: &2156864060 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156864060
25
+ description: Sprockets processor for Google's Closure tools
26
+ email:
27
+ - ilya@igvita.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - closure-sprockets.gemspec
37
+ - lib/closure-sprockets.rb
38
+ - lib/closure-sprockets/processor.rb
39
+ - lib/closure-sprockets/railtie.rb
40
+ - lib/closure-sprockets/version.rb
41
+ homepage: https://github.com/igrigorik/closure-sprockets
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: closure-sprockets
61
+ rubygems_version: 1.8.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Sprockets processor for Google's Closure tools
65
+ test_files: []