closure-compilr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
Binary file
@@ -5,15 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{closure-compilr}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tal Atlas"]
12
- s.date = %q{2010-01-04}
13
- s.default_executable = %q{closure-compiler.jar}
12
+ s.date = %q{2010-01-13}
14
13
  s.description = %q{A gem for combining and minimizing your javascript files using google's closure compiler.}
15
14
  s.email = %q{me@talatlas.com}
16
- s.executables = ["closure-compiler.jar"]
15
+ s.executables = ["closure-compiler-20091217.jar", "closure-compiler.jar"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE",
19
18
  "README.rdoc"
@@ -25,6 +24,7 @@ Gem::Specification.new do |s|
25
24
  "README.rdoc",
26
25
  "Rakefile",
27
26
  "VERSION",
27
+ "bin/closure-compiler-20091217.jar",
28
28
  "bin/closure-compiler.jar",
29
29
  "closure-compilr.gemspec",
30
30
  "lib/closure-compilr.rb",
@@ -1,12 +1,14 @@
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
-
1
+ require 'open-uri'
2
+ require 'tempfile'
3
+
4
+ module ClosureCompilr # :nodoc:
7
5
 
8
6
  # JSCompilation.new('myjsfile.js').compile #=> /user/me/projects/myproject/public/javascripts/myjsfile.min.js
9
7
  class JSCompilation
8
+
9
+ COMPILER_FILE_LOCATION = File.join File.dirname(__FILE__),'..','bin',"closure-compiler.jar"
10
+ COMPILER_VERSION = 20091217
11
+
10
12
  class << self
11
13
  def root# :nodoc:
12
14
  @@root;
@@ -38,7 +40,7 @@ module ClosureCompilr
38
40
  @@root,@@js_path = RAILS_ROOT, File.join('public','javascripts')
39
41
  @@write_path = File.join(@@root,@@js_path)
40
42
  end
41
- attr_accessor :file,:filename,:other_files,:write_path
43
+ attr_accessor :file,:filename,:other_files,:write_path, :compiler_version
42
44
 
43
45
 
44
46
  # ==== Params
@@ -46,8 +48,9 @@ module ClosureCompilr
46
48
  # - opts: Options to pass
47
49
  def initialize(fname,opts={})
48
50
  @root = opts.fetch(:root,@@root)
49
-
51
+ @tempfiles = Array.new
50
52
  @filename = fname
53
+ @compiler_version = opts.fetch(:compiler_version,COMPILER_VERSION)
51
54
  if m = @filename.match(/(.+[\\|\/])(.+)/)
52
55
  @filename = m[2]
53
56
  @js_path = File.join( m[1].split(/[\\|\/]+/) )
@@ -57,8 +60,20 @@ module ClosureCompilr
57
60
  @write_path = opts.fetch(:write_path,@@write_path)
58
61
  end
59
62
  # @file = File.new(filename)
60
-
63
+
64
+ process_opts
65
+ end
66
+
67
+ def process_opts # :nodoc:
68
+ start_reading = nil
61
69
  @other_files = File.open(file_path).inject([]) do |result,line|
70
+
71
+ unless start_reading
72
+ start_reading = line =~ /==ClosureCompiler==/
73
+ next result
74
+ end
75
+ break result if line =~ /==\/ClosureCompiler==/
76
+
62
77
  if m=line.match(/@code_path (.+)/i)
63
78
  path = File.join @@root,@@js_path,File.join( m[1].split(/[\\|\/]+/) )
64
79
  begin
@@ -67,10 +82,27 @@ module ClosureCompilr
67
82
  raise JSCompInvalidFile, "File cannot be found: #{path}"
68
83
  end
69
84
  result << path
85
+ elsif m=line.match(/@code_url (.+)/i)
86
+ url = m[1]
87
+ filename = url.match(/.+\/(.+)/)
88
+ if filename
89
+ filename = filename[1]
90
+ else
91
+ next result
92
+ end
93
+ temp = Tempfile.new(filename)
94
+ temp.write open(url).read
95
+ temp.flush
96
+ @tempfiles << temp
97
+ result << temp.path
98
+ elsif m=line.match(/@compilation_level (.+)/i)
99
+ @compilation_level = m[1]
100
+ elsif m=line.match(/@formatting (.+)/i)
101
+ @formatting = m[1]
70
102
  end
103
+
71
104
  result
72
105
  end
73
-
74
106
  end
75
107
 
76
108
  # Full path of the source file
@@ -93,12 +125,30 @@ module ClosureCompilr
93
125
  File.join @write_path, output_filename
94
126
  end
95
127
 
128
+ def compiler_file_location # :nodoc:
129
+ @compiler_version ? File.join(File.dirname(__FILE__),'..','bin',"closure-compiler-#{@compiler_version}.jar") : COMPILER_FILE_LOCATION
130
+ end
131
+
96
132
  # Compile's the javascript file and all dependencies
97
133
  def compile
98
- output = `java -jar #{COMPILER_FILE_LOCATION} -js #{all_files.join(' ')} --js_output_file #{output_path}`
134
+ cmd = "java -jar #{compiler_file_location}"
135
+ cmd << " --compilation_level #{@compilation_level}" if @compilation_level
136
+ cmd << " --formatting #{@formatting}" if @formatting
137
+ all_files.each do |file|
138
+ cmd << " --js #{file}"
139
+ end
140
+ cmd << " --js_output_file #{output_path}"
141
+
142
+ output = `#{cmd}`
143
+
99
144
  output_path
100
145
  end
101
146
  alias compress compile
147
+
148
+ # Closes out the tempfiles generated by downloading external javascripts
149
+ def close_tempfiles
150
+ @tempfiles.each {|f| f.close}
151
+ end
102
152
  end
103
153
 
104
154
  # Error type returned if there was an error compiling
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: closure-compilr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tal Atlas
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-04 00:00:00 -05:00
13
- default_executable: closure-compiler.jar
12
+ date: 2010-01-13 00:00:00 -05:00
13
+ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -25,6 +25,7 @@ dependencies:
25
25
  description: A gem for combining and minimizing your javascript files using google's closure compiler.
26
26
  email: me@talatlas.com
27
27
  executables:
28
+ - closure-compiler-20091217.jar
28
29
  - closure-compiler.jar
29
30
  extensions: []
30
31
 
@@ -38,6 +39,7 @@ files:
38
39
  - README.rdoc
39
40
  - Rakefile
40
41
  - VERSION
42
+ - bin/closure-compiler-20091217.jar
41
43
  - bin/closure-compiler.jar
42
44
  - closure-compilr.gemspec
43
45
  - lib/closure-compilr.rb