jim 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ /*
2
+ * jQuery Color Animations
3
+ * Copyright 2007 John Resig
4
+ * Released under the MIT and GPL licenses.
5
+ */
6
+
7
+ (function(jQuery){
8
+
9
+ // We override the animation for all of these color styles
10
+ jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
11
+ jQuery.fx.step[attr] = function(fx){
12
+ if ( fx.state == 0 ) {
13
+ fx.start = getColor( fx.elem, attr );
14
+ fx.end = getRGB( fx.end );
15
+ }
16
+
17
+ fx.elem.style[attr] = "rgb(" + [
18
+ Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
19
+ Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
20
+ Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
21
+ ].join(",") + ")";
22
+ }
23
+ });
24
+
25
+ // Color Conversion functions from highlightFade
26
+ // By Blair Mitchelmore
27
+ // http://jquery.offput.ca/highlightFade/
28
+
29
+ // Parse strings looking for color tuples [255,255,255]
30
+ function getRGB(color) {
31
+ var result;
32
+
33
+ // Check if we're already dealing with an array of colors
34
+ if ( color && color.constructor == Array && color.length == 3 )
35
+ return color;
36
+
37
+ // Look for rgb(num,num,num)
38
+ if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
39
+ return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
40
+
41
+ // Look for rgb(num%,num%,num%)
42
+ if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
43
+ return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
44
+
45
+ // Look for #a0b1c2
46
+ if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
47
+ return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
48
+
49
+ // Look for #fff
50
+ if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
51
+ return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
52
+
53
+ // Look for rgba(0, 0, 0, 0) == transparent in Safari 3
54
+ if (result = /rgba\(0, 0, 0, 0\)/.exec(color))
55
+ return colors['transparent'];
56
+
57
+ // Otherwise, we're most likely dealing with a named color
58
+ return colors[jQuery.trim(color).toLowerCase()];
59
+ }
60
+
61
+ function getColor(elem, attr) {
62
+ var color;
63
+
64
+ do {
65
+ color = jQuery.curCSS(elem, attr);
66
+
67
+ // Keep going until we find an element that has color, or we hit the body
68
+ if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
69
+ break;
70
+
71
+ attr = "backgroundColor";
72
+ } while ( elem = elem.parentNode );
73
+
74
+ return getRGB(color);
75
+ };
76
+
77
+ // Some named colors to work with
78
+ // From Interface by Stefan Petre
79
+ // http://interface.eyecon.ro/
80
+
81
+ var colors = {
82
+ aqua:[0,255,255],
83
+ azure:[240,255,255],
84
+ beige:[245,245,220],
85
+ black:[0,0,0],
86
+ blue:[0,0,255],
87
+ brown:[165,42,42],
88
+ cyan:[0,255,255],
89
+ darkblue:[0,0,139],
90
+ darkcyan:[0,139,139],
91
+ darkgrey:[169,169,169],
92
+ darkgreen:[0,100,0],
93
+ darkkhaki:[189,183,107],
94
+ darkmagenta:[139,0,139],
95
+ darkolivegreen:[85,107,47],
96
+ darkorange:[255,140,0],
97
+ darkorchid:[153,50,204],
98
+ darkred:[139,0,0],
99
+ darksalmon:[233,150,122],
100
+ darkviolet:[148,0,211],
101
+ fuchsia:[255,0,255],
102
+ gold:[255,215,0],
103
+ green:[0,128,0],
104
+ indigo:[75,0,130],
105
+ khaki:[240,230,140],
106
+ lightblue:[173,216,230],
107
+ lightcyan:[224,255,255],
108
+ lightgreen:[144,238,144],
109
+ lightgrey:[211,211,211],
110
+ lightpink:[255,182,193],
111
+ lightyellow:[255,255,224],
112
+ lime:[0,255,0],
113
+ magenta:[255,0,255],
114
+ maroon:[128,0,0],
115
+ navy:[0,0,128],
116
+ olive:[128,128,0],
117
+ orange:[255,165,0],
118
+ pink:[255,192,203],
119
+ purple:[128,0,128],
120
+ violet:[128,0,128],
121
+ red:[255,0,0],
122
+ silver:[192,192,192],
123
+ white:[255,255,255],
124
+ yellow:[255,255,0],
125
+ transparent: [255,255,255]
126
+ };
127
+
128
+ })(jQuery);
@@ -0,0 +1 @@
1
+ // mustache.js
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "mustache",
3
+ "author": "Jan Lehnardt",
4
+ "description": "{{mustaches}} in JavaScript — shameless port from @defunkt",
5
+ "version": "0.2.2",
6
+ "keywords": ["template"]
7
+ }
@@ -0,0 +1 @@
1
+ function() {};
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+ require 'mocha'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require 'jim'
10
+
11
+ Jim.logger = Logger.new('/dev/null')
12
+ Jim::Installer.tmp_root = File.join(File.dirname(__FILE__), 'tmp', 'jimtmproot')
13
+
14
+ class Test::Unit::TestCase
15
+
16
+ def fixture_path(path)
17
+ full_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', path))
18
+ end
19
+
20
+ def fixture(path)
21
+ File.read(fixture_path(path))
22
+ end
23
+
24
+ def tmp_path
25
+ File.join(File.dirname(__FILE__), 'tmp')
26
+ end
27
+
28
+ def assert_readable(*args)
29
+ full_path = File.join(*args)
30
+ assert File.readable?(full_path), "Expected #{full_path} to be a readable file"
31
+ end
32
+
33
+ def assert_dir(*args)
34
+ full_path = File.join(*args)
35
+ assert File.directory?(full_path), "Expected #{full_path} to be a directory"
36
+ end
37
+
38
+ end
@@ -0,0 +1,151 @@
1
+ require 'helper'
2
+
3
+ class TestJimBundler < Test::Unit::TestCase
4
+
5
+ context "Jim::Bundler" do
6
+ setup do
7
+ # clear the tmp dir
8
+ FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
9
+ root = File.dirname(__FILE__)
10
+ @directories = [File.join(root, 'fixtures'), File.join(root, 'tmp', 'lib')]
11
+ Jim::Installer.new(fixture_path('infoincomments.js'), tmp_path).install
12
+ @bundler = Jim::Bundler.new(fixture('jimfile'), Jim::Index.new(@directories))
13
+ end
14
+
15
+ context "initialize" do
16
+
17
+ should "load jimfile data if jimfile is a Pathname" do
18
+ @bundler = Jim::Bundler.new(Pathname.new(fixture_path('jimfile')), Jim::Index.new(@directories))
19
+ assert @bundler
20
+ assert_equal fixture('jimfile'), @bundler.jimfile
21
+ end
22
+
23
+ should "load jimfile data as a string" do
24
+ assert @bundler
25
+ assert_equal fixture('jimfile'), @bundler.jimfile
26
+ end
27
+
28
+ should "parse options out of jimfile" do
29
+ assert_equal 'tmp/public/javascripts/bundled.js', @bundler.options[:bundled_path]
30
+ assert_equal 'tmp/public/javascripts/vendor', @bundler.options[:vendor_dir]
31
+ end
32
+
33
+ should "set index" do
34
+ assert @bundler.index.is_a?(Jim::Index)
35
+ assert_equal @directories, @bundler.index.directories
36
+ end
37
+ end
38
+
39
+ context "resolve!" do
40
+
41
+ should "find projects listed in the jimfile and set paths" do
42
+ assert @bundler.paths.empty?
43
+ @bundler.resolve!
44
+ assert @bundler.paths
45
+ assert_equal 2, @bundler.paths.length
46
+ @bundler.paths.each do |path|
47
+ assert path.is_a?(Pathname)
48
+ end
49
+ end
50
+
51
+ should "set paths in same order as in jimfile" do
52
+ @bundler.resolve!
53
+ assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), @bundler.paths.first
54
+ end
55
+
56
+ should "raise error if file can not be found" do
57
+ FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
58
+ assert_raise(Jim::Bundler::MissingFile) {
59
+ @bundler.resolve!
60
+ }
61
+ end
62
+
63
+ end
64
+
65
+ context "vendor!" do
66
+
67
+ should "copy files in jemfile to path specified" do
68
+ vendor_dir = Pathname.new(tmp_path) + 'vendor'
69
+ @bundler.vendor!(vendor_dir)
70
+ assert_readable vendor_dir + 'jquery.js'
71
+ assert_readable vendor_dir + 'myproject.js'
72
+ end
73
+
74
+ end
75
+
76
+ context "bundle!" do
77
+
78
+ should "concatenate file into a string" do
79
+ @bundler.options = {}
80
+ bundle = @bundler.bundle!
81
+ assert bundle.is_a?(String)
82
+ assert_match(/jQuery/, bundle)
83
+ end
84
+
85
+ should "raise error if file cant be found" do
86
+ FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
87
+ assert_raise(Jim::Bundler::MissingFile) {
88
+ @bundler.bundle!
89
+ }
90
+ end
91
+
92
+ should "write to file specified in options" do
93
+ bundle_path = @bundler.options[:bundled_path]
94
+ assert @bundler.bundle!
95
+ assert bundle = File.read(bundle_path)
96
+ assert_match(/jQuery/, bundle)
97
+ end
98
+
99
+ should "write to file if path is given" do
100
+ bundle_path = File.join(tmp_path, 'app.js')
101
+ assert @bundler.bundle!(bundle_path)
102
+ assert bundle = File.read(bundle_path)
103
+ assert_match(/jQuery/, bundle)
104
+ end
105
+
106
+ should "write to IO if IO is given" do
107
+ bundle_path = File.join(tmp_path, 'app.js')
108
+ assert @bundler.bundle!(File.open(bundle_path, 'w'))
109
+ assert bundle = File.read(bundle_path)
110
+ assert_match(/jQuery/, bundle)
111
+ end
112
+
113
+ end
114
+
115
+ context "compress!" do
116
+ setup do
117
+ @bundler.expects(:js_compress).returns(@bundler.bundle!(false))
118
+ end
119
+
120
+ should "run through google compressor" do
121
+ @bundler.options = {}
122
+ bundle = @bundler.compress!
123
+ assert bundle.is_a?(String)
124
+ assert_match(/jQuery/, bundle)
125
+ end
126
+
127
+ should "write to file specified in options" do
128
+ bundle_path = @bundler.options[:compressed_path]
129
+ assert @bundler.compress!
130
+ assert bundle = File.read(bundle_path)
131
+ assert_match(/jQuery/, bundle)
132
+ end
133
+
134
+ should "write to file if path is given" do
135
+ bundle_path = File.join(tmp_path, 'app.js')
136
+ assert @bundler.compress!(bundle_path)
137
+ assert bundle = File.read(bundle_path)
138
+ assert_match(/jQuery/, bundle)
139
+ end
140
+
141
+ should "write to IO if IO is given" do
142
+ bundle_path = File.join(tmp_path, 'app.js')
143
+ assert @bundler.compress!(File.open(bundle_path, 'w'))
144
+ assert bundle = File.read(bundle_path)
145
+ assert_match(/jQuery/, bundle)
146
+ end
147
+
148
+ end
149
+ end
150
+
151
+ end
@@ -0,0 +1,71 @@
1
+ require 'helper'
2
+
3
+ class TestJimCLI < Test::Unit::TestCase
4
+
5
+ context "Jim::CLI" do
6
+ setup do
7
+ FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
8
+ other_tmp_path = File.join(File.dirname(__FILE__), '..', 'tmp')
9
+ FileUtils.rm_rf(other_tmp_path) if File.directory?(other_tmp_path)
10
+ Jim::Installer.new(fixture_path('infoincomments.js'), tmp_path).install
11
+ Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path).install
12
+ end
13
+
14
+ context "init" do
15
+ should "write Jimfile to path" do
16
+ run_cli("init", tmp_path)
17
+ assert_readable tmp_path, "Jimfile"
18
+ end
19
+ end
20
+
21
+ context "bundle" do
22
+ should "write bundled Jimfile to path" do
23
+ run_cli("bundle", tmp_path + '/bundle.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
24
+ assert_readable tmp_path + '/bundle.js'
25
+ end
26
+
27
+ should "write to bundled_path if no path provided" do
28
+ run_cli("bundle", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
29
+ assert_readable tmp_path, '..', '..', 'tmp', 'public', 'javascripts', 'bundled.js'
30
+ end
31
+ end
32
+
33
+ context "compress" do
34
+ should "compress Jimfile to path" do
35
+ run_cli("compress", tmp_path + '/compressed.js', "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
36
+ assert_readable tmp_path + '/compressed.js'
37
+ end
38
+
39
+ should "compress to compressed_path if no path provided" do
40
+ run_cli("compress", "-j", fixture_path('Jimfile'), "--jimhome", tmp_path)
41
+ assert_readable tmp_path, '..', '..', 'tmp', 'public', 'javascripts', 'compressed.js'
42
+ end
43
+ end
44
+
45
+ context "vendor" do
46
+ should "vendor Jimfile to dir" do
47
+
48
+ end
49
+
50
+ should "vendor Jimfile to vendor dir" do
51
+
52
+ end
53
+ end
54
+
55
+ context "install" do
56
+ should "install url to jim home" do
57
+ run_cli("install", fixture_path('jquery-1.4.1.js'), "--jimhome", tmp_path)
58
+ install_path = File.join(tmp_path, 'lib', 'jquery-1.4.1')
59
+ assert_dir install_path
60
+ assert_readable install_path, 'jquery.js'
61
+ assert_equal fixture('jquery-1.4.1.js'), File.read(File.join(install_path, 'jquery.js'))
62
+ end
63
+ end
64
+
65
+ end
66
+
67
+ def run_cli(*args)
68
+ Jim::CLI.new(args.collect {|a| a.to_s }).run
69
+ end
70
+
71
+ end
@@ -0,0 +1,97 @@
1
+ require 'helper'
2
+
3
+ class TestJimIndex < Test::Unit::TestCase
4
+
5
+ context "Jim::Index" do
6
+ setup do
7
+ # clear the tmp dir
8
+ FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path)
9
+ root = File.dirname(__FILE__)
10
+ @directories = [File.join(root, 'fixtures'), File.join(root, 'tmp', 'lib')]
11
+ @index = Jim::Index.new(*@directories)
12
+ end
13
+
14
+ context "initializing" do
15
+
16
+ should "set an array of directories" do
17
+ assert_equal @directories, @index.directories
18
+ end
19
+ end
20
+
21
+ context "list" do
22
+ setup do
23
+ Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path, :version => '1.5pre').install
24
+ @list = @index.list
25
+ end
26
+
27
+ should "return list of files and directories" do
28
+ names = @list.collect {|l| l[0] }
29
+ assert names.include?('jquery'), "should include jquery"
30
+ assert names.include?('infoincomments')
31
+ end
32
+
33
+ should "only return one of each name" do
34
+ jquery = @list.find {|l| l[0] == 'jquery' }
35
+ assert jquery, "should include jquery"
36
+ assert jquery[1].is_a?(Array), "should have array of versions"
37
+ assert_equal jquery[1].length, jquery[1].uniq.length
38
+ assert jquery[1].include?('1.5pre')
39
+ end
40
+
41
+ end
42
+
43
+ context "find" do
44
+
45
+ should "find by name and version in local files" do
46
+ path = @index.find('jquery', '1.4.1')
47
+ assert path
48
+ assert path.is_a?(Pathname)
49
+ assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), path
50
+ end
51
+
52
+ should "find by name alone in local files" do
53
+ path = @index.find('jquery')
54
+ assert path
55
+ assert path.is_a?(Pathname)
56
+ assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), path
57
+ end
58
+
59
+ should "find by path and version in local files" do
60
+ path = @index.find('fixtures/jquery')
61
+ assert path
62
+ assert path.is_a?(Pathname)
63
+ assert_equal Pathname.new(fixture_path('jquery-1.4.1.js')), path
64
+ end
65
+
66
+ should "find by name and version in jim dirs" do
67
+ installer = Jim::Installer.new(fixture_path('jquery-1.4.1.js'), tmp_path, :version => '1.5pre')
68
+ jim_path = installer.install
69
+ assert jim_path.is_a?(Pathname)
70
+ path = @index.find('jquery', '1.5pre')
71
+ assert_equal jim_path.expand_path, path.expand_path
72
+ end
73
+
74
+ should "find by name with dot and version 0 in jim dirs" do
75
+ installer = Jim::Installer.new(fixture_path('jquery.color.js'), tmp_path)
76
+ jim_path = installer.install
77
+ assert jim_path.is_a?(Pathname)
78
+ path = @index.find('jquery.color', '0')
79
+ assert_equal jim_path.expand_path, path.expand_path
80
+ end
81
+
82
+ should "find by name in jim dirs" do
83
+ installer = Jim::Installer.new(fixture_path('infoincomments.js'), tmp_path)
84
+ jim_path = installer.install
85
+ assert jim_path.is_a?(Pathname)
86
+ path = @index.find('myproject')
87
+ assert_equal jim_path.expand_path, path.expand_path
88
+ end
89
+
90
+ should "return false if file can not be found" do
91
+ assert !@index.find('jquery', '1.8')
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+ end