closure-compilr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/closure-compiler.jar +0 -0
- data/closure-compilr.gemspec +58 -0
- data/lib/closure-compilr.rb +110 -0
- data/spec/closure-compilr_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +77 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tal Atlas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= closure-compilr
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Tal Atlas. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "closure-compilr"
|
8
|
+
gem.summary = %Q{Gem for using google's closure compiler on your own javascript files}
|
9
|
+
gem.description = %Q{A gem for combining and minimizing your javascript files using google's closure compiler.}
|
10
|
+
gem.email = "me@talatlas.com"
|
11
|
+
gem.homepage = "http://github.com/Talby/closure-compilr"
|
12
|
+
gem.authors = ["Tal Atlas"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "closure-compilr #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
Binary file
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{closure-compilr}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tal Atlas"]
|
12
|
+
s.date = %q{2010-01-04}
|
13
|
+
s.default_executable = %q{closure-compiler.jar}
|
14
|
+
s.description = %q{A gem for combining and minimizing your javascript files using google's closure compiler.}
|
15
|
+
s.email = %q{me@talatlas.com}
|
16
|
+
s.executables = ["closure-compiler.jar"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/closure-compiler.jar",
|
29
|
+
"closure-compilr.gemspec",
|
30
|
+
"lib/closure-compilr.rb",
|
31
|
+
"spec/closure-compilr_spec.rb",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/Talby/closure-compilr}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Gem for using google's closure compiler on your own javascript files}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/closure-compilr_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module ClosureCompilr
|
2
|
+
VERSION = "0.0.1"
|
3
|
+
VERSION_HASH = {:major => 0, :minor => 0, :patch => 1}
|
4
|
+
COMPILER_FILE_LOCATION = File.join File.dirname(__FILE__),'..','bin',"closure-compiler.jar"
|
5
|
+
COMPILER_VERSION = 20091217
|
6
|
+
|
7
|
+
|
8
|
+
# JSCompilation.new('myjsfile.js').compile #=> /user/me/projects/myproject/public/javascripts/myjsfile.min.js
|
9
|
+
class JSCompilation
|
10
|
+
class << self
|
11
|
+
def root# :nodoc:
|
12
|
+
@@root;
|
13
|
+
end
|
14
|
+
|
15
|
+
# Manually set the root path of the application you're using
|
16
|
+
# JSCompilation.root = '/user/me/projects/myproject'
|
17
|
+
def root=(r);@@root=r;end
|
18
|
+
|
19
|
+
def js_path# :nodoc:
|
20
|
+
@@js_path
|
21
|
+
end
|
22
|
+
|
23
|
+
# Manually set the storage location for javascript files relative to the root path
|
24
|
+
# JSCompilation.js_path = 'public/javascripts'
|
25
|
+
def js_path=(j);@@js_path=j;end
|
26
|
+
|
27
|
+
def write_path# :nodoc:
|
28
|
+
@@write_path
|
29
|
+
end
|
30
|
+
# The directory to output the completed file. Defaults to root path combined with js_path
|
31
|
+
# JSCompilation.write_path = '/user/me/projects/myproject/public/javascripts'
|
32
|
+
def write_path=(w);@@write_path=w;end
|
33
|
+
end
|
34
|
+
if defined? Merb
|
35
|
+
@@root,@@js_path = Merb.root_path, File.join('public','javascripts')
|
36
|
+
@@write_path = File.join(@@root,@@js_path)
|
37
|
+
elsif defined? RAILS_ROOT
|
38
|
+
@@root,@@js_path = RAILS_ROOT, File.join('public','javascripts')
|
39
|
+
@@write_path = File.join(@@root,@@js_path)
|
40
|
+
end
|
41
|
+
attr_accessor :file,:filename,:other_files,:write_path
|
42
|
+
|
43
|
+
|
44
|
+
# ==== Params
|
45
|
+
# - fname: Filename of javascript file to compile
|
46
|
+
# - opts: Options to pass
|
47
|
+
def initialize(fname,opts={})
|
48
|
+
@root = opts.fetch(:root,@@root)
|
49
|
+
|
50
|
+
@filename = fname
|
51
|
+
if m = @filename.match(/(.+[\\|\/])(.+)/)
|
52
|
+
@filename = m[2]
|
53
|
+
@js_path = File.join( m[1].split(/[\\|\/]+/) )
|
54
|
+
@write_path = opts.fetch(:write_path,File.join(@root,@js_path) )
|
55
|
+
else
|
56
|
+
@js_path = opts.fetch(:root,@@js_path)
|
57
|
+
@write_path = opts.fetch(:write_path,@@write_path)
|
58
|
+
end
|
59
|
+
# @file = File.new(filename)
|
60
|
+
|
61
|
+
@other_files = File.open(file_path).inject([]) do |result,line|
|
62
|
+
if m=line.match(/@code_path (.+)/i)
|
63
|
+
path = File.join @@root,@@js_path,File.join( m[1].split(/[\\|\/]+/) )
|
64
|
+
begin
|
65
|
+
File.open(path)
|
66
|
+
rescue Errno::ENOENT
|
67
|
+
raise JSCompInvalidFile, "File cannot be found: #{path}"
|
68
|
+
end
|
69
|
+
result << path
|
70
|
+
end
|
71
|
+
result
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
# Full path of the source file
|
77
|
+
def file_path
|
78
|
+
File.join(@@root,@@js_path,filename)
|
79
|
+
end
|
80
|
+
|
81
|
+
# All the files to be processed together
|
82
|
+
def all_files
|
83
|
+
other_files + file_path.to_a
|
84
|
+
end
|
85
|
+
|
86
|
+
# Filename of the file to be output
|
87
|
+
def output_filename
|
88
|
+
filename.gsub(/\.js$/i,'.min.js')
|
89
|
+
end
|
90
|
+
|
91
|
+
# Full path of the file to be output
|
92
|
+
def output_path
|
93
|
+
File.join @write_path, output_filename
|
94
|
+
end
|
95
|
+
|
96
|
+
# Compile's the javascript file and all dependencies
|
97
|
+
def compile
|
98
|
+
output = `java -jar #{COMPILER_FILE_LOCATION} -js #{all_files.join(' ')} --js_output_file #{output_path}`
|
99
|
+
output_path
|
100
|
+
end
|
101
|
+
alias compress compile
|
102
|
+
end
|
103
|
+
|
104
|
+
# Error type returned if there was an error compiling
|
105
|
+
class JSCompilationFailed < StandardError; end
|
106
|
+
# Error type returned if one of hte dependencies listed wasn't found
|
107
|
+
class JSCompInvalidFile < JSCompilationFailed; end
|
108
|
+
end
|
109
|
+
|
110
|
+
include ClosureCompilr
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: closure-compilr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tal Atlas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-04 00:00:00 -05:00
|
13
|
+
default_executable: closure-compiler.jar
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: A gem for combining and minimizing your javascript files using google's closure compiler.
|
26
|
+
email: me@talatlas.com
|
27
|
+
executables:
|
28
|
+
- closure-compiler.jar
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- bin/closure-compiler.jar
|
42
|
+
- closure-compilr.gemspec
|
43
|
+
- lib/closure-compilr.rb
|
44
|
+
- spec/closure-compilr_spec.rb
|
45
|
+
- spec/spec.opts
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/Talby/closure-compilr
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Gem for using google's closure compiler on your own javascript files
|
75
|
+
test_files:
|
76
|
+
- spec/closure-compilr_spec.rb
|
77
|
+
- spec/spec_helper.rb
|