jim 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,8 +15,10 @@ begin
15
15
  gem.email = "aaron@quirkey.com"
16
16
  gem.homepage = "http://github.com/quirkey/jim"
17
17
  gem.authors = ["Aaron Quint"]
18
- gem.add_dependency "downlow", ">= 0.1.1"
18
+
19
+ gem.add_dependency "downlow", ">= 0.1.2"
19
20
  gem.add_dependency "yajl-ruby"
21
+
20
22
  gem.add_development_dependency "shoulda", ">= 0"
21
23
  gem.add_development_dependency "fakeweb", ">= 1.2.8"
22
24
  gem.add_development_dependency "mocha"
data/jim.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jim}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = %q{2010-02-20}
12
+ s.date = %q{2010-02-21}
13
13
  s.default_executable = %q{jim}
14
14
  s.description = %q{jim is your friendly javascript library manager. He downloads, stores, bundles, vendors and compresses.}
15
15
  s.email = %q{aaron@quirkey.com}
@@ -69,20 +69,20 @@ Gem::Specification.new do |s|
69
69
  s.specification_version = 3
70
70
 
71
71
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
72
- s.add_runtime_dependency(%q<downlow>, [">= 0.1.1"])
72
+ s.add_runtime_dependency(%q<downlow>, [">= 0.1.2"])
73
73
  s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
74
74
  s.add_development_dependency(%q<shoulda>, [">= 0"])
75
75
  s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
76
76
  s.add_development_dependency(%q<mocha>, [">= 0"])
77
77
  else
78
- s.add_dependency(%q<downlow>, [">= 0.1.1"])
78
+ s.add_dependency(%q<downlow>, [">= 0.1.2"])
79
79
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
80
80
  s.add_dependency(%q<shoulda>, [">= 0"])
81
81
  s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
82
82
  s.add_dependency(%q<mocha>, [">= 0"])
83
83
  end
84
84
  else
85
- s.add_dependency(%q<downlow>, [">= 0.1.1"])
85
+ s.add_dependency(%q<downlow>, [">= 0.1.2"])
86
86
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
87
87
  s.add_dependency(%q<shoulda>, [">= 0"])
88
88
  s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
data/lib/jim/bundler.rb CHANGED
@@ -68,7 +68,7 @@ module Jim
68
68
  to = options[:compressed_path] if to.nil? && options[:compressed_path]
69
69
  io = io_for_path(to)
70
70
  logger.info "compressing to #{to}"
71
- io << js_compress(bundle!(false))
71
+ io << compress_js(bundle!(false))
72
72
  io
73
73
  end
74
74
 
@@ -84,6 +84,27 @@ module Jim
84
84
  end
85
85
  end
86
86
 
87
+ # Run the uncompressed test through a JS compressor (closure-compiler) by
88
+ # default. Setting options[:compressor] == 'yui' will force the YUI JS Compressor
89
+ def compress_js(uncompressed)
90
+ if options[:compressor] == 'yui'
91
+ begin
92
+ require "yui/compressor"
93
+ rescue LoadError
94
+ raise "You must install the yui compressor gem to use the compressor\ngem install yui-compressor"
95
+ end
96
+ compressor = ::YUI::JavaScriptCompressor.new
97
+ else
98
+ begin
99
+ require 'closure-compiler'
100
+ rescue LoadError
101
+ raise "You must install the closure compiler gem to use the compressor\ngem install closure-compiler"
102
+ end
103
+ compressor = ::Closure::Compiler.new
104
+ end
105
+ compressor.compress(uncompressed)
106
+ end
107
+
87
108
  private
88
109
  def io_for_path(to)
89
110
  case to
@@ -109,26 +130,7 @@ module Jim
109
130
  end
110
131
  end
111
132
  end
112
-
113
- def js_compress(uncompressed)
114
- if options[:compressor] == 'yui'
115
- begin
116
- require "yui/compressor"
117
- rescue LoadError
118
- raise "You must install the yui compressor gem to use the compressor\ngem install yui-compressor"
119
- end
120
- compressor = ::YUI::JavaScriptCompressor.new
121
- else
122
- begin
123
- require 'closure-compiler'
124
- rescue LoadError
125
- raise "You must install the closure compiler gem to use the compressor\ngem install closure-compiler"
126
- end
127
- compressor = ::Closure::Compiler.new
128
- end
129
- compressor.compress(uncompressed)
130
- end
131
-
133
+
132
134
  def logger
133
135
  Jim.logger
134
136
  end
data/lib/jim/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'optparse'
2
+ require 'readline'
2
3
 
3
4
  module Jim
4
5
 
@@ -93,6 +94,29 @@ module Jim
93
94
  logger.info "Installed:\n#{list.collect {|i| "#{i[0]} (#{i[1].join(', ')})"}.join("\n")}"
94
95
  end
95
96
 
97
+ # Iterates over matching files and prompts for removal
98
+ def remove(name, version = nil)
99
+ logger.info "Looking for files matching #{name} #{version}"
100
+ files = installed_index.find_all(name, version)
101
+ if files.length > 0
102
+ logger.info "Found #{files.length} matching files"
103
+ removed = 0
104
+ files.each do |filename|
105
+ response = Readline.readline("Remove #{filename}? (y/n)\n")
106
+ if response.strip =~ /y/i
107
+ logger.info "Removing #{filename}"
108
+ filename.delete
109
+ removed += 1
110
+ else
111
+ logger.info "Skipping #{filename}"
112
+ end
113
+ end
114
+ logger.info "Removed #{removed} files."
115
+ else
116
+ logger.info "No installed files matched."
117
+ end
118
+ end
119
+
96
120
  # list the files and their resolved paths specified in the Jimfile
97
121
  def resolve
98
122
  resolved = bundler.resolve!
@@ -141,13 +165,21 @@ module Jim
141
165
  end
142
166
 
143
167
  def index
144
- @index ||= Jim::Index.new(jimhome + 'lib', Dir.pwd)
168
+ @index ||= Jim::Index.new(install_dir, Dir.pwd)
169
+ end
170
+
171
+ def installed_index
172
+ @installed_index ||= Jim::Index.new(install_dir)
145
173
  end
146
174
 
147
175
  def bundler
148
176
  @bundler ||= Jim::Bundler.new(jimfile, index)
149
177
  end
150
178
 
179
+ def install_dir
180
+ jimhome + 'lib'
181
+ end
182
+
151
183
  def template(path)
152
184
  (Pathname.new(__FILE__).dirname + 'templates' + path).read
153
185
  end
data/lib/jim/index.rb CHANGED
@@ -14,18 +14,15 @@ module Jim
14
14
  def list
15
15
  list = {}
16
16
  each_file_in_index('.js') do |filename|
17
- if version = filename.version
18
- name = filename.stem.gsub(/(\-[^\-]+)$/, '')
19
- elsif /lib\/([^\/]+)-([\d\w\.\-]+)\/.+/.match filename
17
+ if /lib\/([^\/]+)-([\d\w\.\-]+)\/.+/.match filename
20
18
  name = $1
21
19
  version = $2
22
20
  else
23
- name = filename.stem
24
- version = '0'
21
+ name, version = Jim::VersionParser.parse_filename(filename)
25
22
  end
26
23
  if name && version
27
24
  list[name] ||= []
28
- list[name] << version unless list[name].include?(version)
25
+ list[name] << [version, filename]
29
26
  end
30
27
  end
31
28
  list.sort
@@ -51,14 +48,20 @@ module Jim
51
48
  possible_paths.each do |p|
52
49
  if File.file?(filename) && p.match(filename)
53
50
  final = Pathname.new(filename).expand_path
54
- break
51
+ block_given? ? yield(final) : break
55
52
  end
56
53
  end
57
- break if final
54
+ break if final && !block_given?
58
55
  end
59
56
  final
60
57
  end
61
58
 
59
+ def find_all(name, version = nil)
60
+ matched = []
61
+ find(name, version) {|p| matched << p }
62
+ matched
63
+ end
64
+
62
65
  def each_file_in_index(ext, &block)
63
66
  @directories.each do |dir|
64
67
  Dir.glob(Pathname.new(dir) + '**' + "*#{ext}") do |filename|
@@ -4,7 +4,7 @@ module Jim
4
4
  NOT_EXTENSIONS = %w{.min .pre .beta}
5
5
 
6
6
  def self.parse_filename(filename)
7
- f = filename.dup
7
+ f = Pathname.new(filename).basename.to_s
8
8
  extension = f.scan(/\.[^\.\d\s\-\_][^\.]*$/)[0]
9
9
  if NOT_EXTENSIONS.include?(extension)
10
10
  extension = nil
data/lib/jim.rb CHANGED
@@ -4,7 +4,7 @@ require 'yajl'
4
4
 
5
5
 
6
6
  module Jim
7
- VERSION = '0.1.1'
7
+ VERSION = '0.1.2'
8
8
 
9
9
  class Error < RuntimeError; end
10
10
  class FileExists < Error; end
data/test/helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'test/unit'
3
3
  require 'shoulda'
4
4
  require 'fakeweb'
5
5
  require 'mocha'
6
+ # require 'test_benchmark'
6
7
 
7
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
9
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -114,7 +114,7 @@ class TestJimBundler < Test::Unit::TestCase
114
114
 
115
115
  context "compress!" do
116
116
  setup do
117
- @bundler.expects(:js_compress).returns(@bundler.bundle!(false))
117
+ @bundler.stubs(:compress_js).returns(@bundler.bundle!(false))
118
118
  end
119
119
 
120
120
  should "run through google compressor" do
data/test/test_jim_cli.rb CHANGED
@@ -31,6 +31,10 @@ class TestJimCLI < Test::Unit::TestCase
31
31
  end
32
32
 
33
33
  context "compress" do
34
+ setup do
35
+ Jim::Bundler.any_instance.stubs(:compress_js).returns("compressed.js")
36
+ end
37
+
34
38
  should "compress Jimfile to path" do
35
39
  run_cli("compress", tmp_path + '/compressed.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
36
40
  assert_readable tmp_path + '/compressed.js'
@@ -24,8 +24,8 @@ class TestJimIndex < Test::Unit::TestCase
24
24
  @list = @index.list
25
25
  end
26
26
 
27
- should "return list of files and directories" do
28
- names = @list.collect {|l| l[0] }
27
+ should "return list of files" do
28
+ names = @list.collect {|l| l[0] }
29
29
  assert names.include?('jquery'), "should include jquery"
30
30
  assert names.include?('infoincomments')
31
31
  end
@@ -33,9 +33,11 @@ class TestJimIndex < Test::Unit::TestCase
33
33
  should "only return one of each name" do
34
34
  jquery = @list.find {|l| l[0] == 'jquery' }
35
35
  assert jquery, "should include jquery"
36
- assert jquery[1].is_a?(Array), "should have array of versions"
36
+ assert jquery[1].is_a?(Array), "should have array of versions and filenames"
37
37
  assert_equal jquery[1].length, jquery[1].uniq.length
38
- assert jquery[1].include?('1.5pre')
38
+ assert jquery[1][0].is_a?(Array)
39
+ assert jquery[1][0][0].is_a?(String), "should have version"
40
+ assert jquery[1][0][1].is_a?(Pathname), "should include pathname"
39
41
  end
40
42
 
41
43
  end
@@ -92,6 +94,23 @@ class TestJimIndex < Test::Unit::TestCase
92
94
  end
93
95
 
94
96
  end
97
+
98
+ context "find_all" do
99
+ setup do
100
+ Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path, :version => '1.5pre').install
101
+ @all = @index.find_all("jquery")
102
+ end
103
+
104
+ should "return array" do
105
+ assert @all.is_a?(Array)
106
+ end
107
+
108
+ should "find all files that match the search" do
109
+ assert @all[0].is_a?(Pathname)
110
+ assert @all.all? {|p| p.to_s.match /jquery/ }
111
+ end
112
+
113
+ end
95
114
 
96
115
  end
97
116
  end
@@ -9,6 +9,7 @@ class TestJimVersionParser < Test::Unit::TestCase
9
9
  [
10
10
  ["sammy-0.1.0", ["sammy", "0.1.0"]],
11
11
  ["sammy_0.1.0", ["sammy", "0.1.0"]],
12
+ ["/test/fixtures/sammy-0.1.0", ["sammy", "0.1.0"]],
12
13
  ["sammy-1", ["sammy", "1"]],
13
14
  ["sammy_1", ["sammy", "1"]],
14
15
  ["sammy.1.0", ["sammy", "1.0"]],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Quint
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-20 00:00:00 -05:00
12
+ date: 2010-02-21 00:00:00 -05:00
13
13
  default_executable: jim
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.1.1
23
+ version: 0.1.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yajl-ruby