packr 1.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +16 -0
- data/Manifest.txt +19 -0
- data/README.txt +112 -0
- data/Rakefile +12 -0
- data/bin/packr +91 -0
- data/lib/packr.rb +68 -240
- data/lib/packr/base62.rb +150 -0
- data/lib/packr/collection.rb +147 -0
- data/lib/packr/constants.rb +8 -0
- data/lib/packr/encoder.rb +35 -0
- data/lib/packr/map.rb +66 -0
- data/lib/packr/minifier.rb +80 -0
- data/lib/packr/parser.rb +21 -0
- data/lib/packr/privates.rb +19 -0
- data/lib/packr/regexp_group.rb +122 -122
- data/lib/packr/shrinker.rb +123 -0
- data/lib/packr/words.rb +39 -84
- data/lib/string.rb +6 -5
- data/test/test_packr.rb +140 -0
- metadata +79 -51
- data/README +0 -118
- data/test/assets/packed/controls.js +0 -1
- data/test/assets/packed/dragdrop.js +0 -1
- data/test/assets/packed/effects.js +0 -1
- data/test/assets/packed/prototype.js +0 -1
- data/test/assets/packed/prototype_shrunk.js +0 -1
- data/test/assets/src/controls.js +0 -833
- data/test/assets/src/dragdrop.js +0 -942
- data/test/assets/src/effects.js +0 -1088
- data/test/assets/src/prototype.js +0 -2515
- data/test/packr_test.rb +0 -68
data/test/packr_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'packr'
|
3
|
-
|
4
|
-
class PackrTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def setup
|
7
|
-
dir = File.dirname(__FILE__) + '/assets'
|
8
|
-
@data = {
|
9
|
-
:default => [{
|
10
|
-
:source => File.read("#{dir}/src/controls.js"),
|
11
|
-
:packed => File.read("#{dir}/packed/controls.js")
|
12
|
-
}],
|
13
|
-
:shrink_vars => [{
|
14
|
-
:source => File.read("#{dir}/src/dragdrop.js"),
|
15
|
-
:packed => File.read("#{dir}/packed/dragdrop.js")
|
16
|
-
},
|
17
|
-
{ :source => File.read("#{dir}/src/prototype.js"),
|
18
|
-
:packed => File.read("#{dir}/packed/prototype_shrunk.js")
|
19
|
-
}],
|
20
|
-
:base62 => [{
|
21
|
-
:source => File.read("#{dir}/src/effects.js"),
|
22
|
-
:packed => File.read("#{dir}/packed/effects.js")
|
23
|
-
}],
|
24
|
-
:base62_shrink_vars => [{
|
25
|
-
:source => File.read("#{dir}/src/prototype.js"),
|
26
|
-
:packed => File.read("#{dir}/packed/prototype.js")
|
27
|
-
}]
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_basic_packing
|
32
|
-
assert_equal @data[:default][0][:packed], Packr.pack(@data[:default][0][:source])
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_shrink_vars_packing
|
36
|
-
assert_equal @data[:shrink_vars][0][:packed], Packr.pack(@data[:shrink_vars][0][:source], :shrink_vars => true)
|
37
|
-
assert_equal @data[:shrink_vars][1][:packed], Packr.pack(@data[:shrink_vars][1][:source], :shrink_vars => true)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_base62_packing
|
41
|
-
expected = @data[:base62][0][:packed]
|
42
|
-
actual = Packr.pack(@data[:base62][0][:source], :base62 => true)
|
43
|
-
assert_equal expected.size, actual.size
|
44
|
-
expected_words = expected.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
|
45
|
-
actual_words = actual.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
|
46
|
-
assert expected_words.eql?(actual_words)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_base62_and_shrink_vars_packing
|
50
|
-
expected = @data[:base62_shrink_vars][0][:packed]
|
51
|
-
actual = Packr.pack(@data[:base62_shrink_vars][0][:source], :base62 => true, :shrink_vars => true)
|
52
|
-
assert_equal expected.size, actual.size
|
53
|
-
expected_words = expected.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
|
54
|
-
actual_words = actual.scan(/'[\w\|]+'/)[-2].gsub(/^'(.*?)'$/, '\1').split("|").sort
|
55
|
-
assert expected_words.eql?(actual_words)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_protected_names
|
59
|
-
expected = 'var func=function(a,b,$super,c){return $super(a+c)}'
|
60
|
-
actual = Packr.pack('var func = function(foo, bar, $super, baz) { return $super( foo + baz ); }', :shrink_vars => true)
|
61
|
-
assert_equal expected, actual
|
62
|
-
packr = Packr.new
|
63
|
-
packr.protect_vars *(%w(other) + [:method, :names] + ['some random stuff', 24])
|
64
|
-
expected = 'var func=function(a,other,$super,b,names){return $super()(other.apply(names,a))}'
|
65
|
-
actual = packr.pack('var func = function(foo, other, $super, bar, names) { return $super()(other.apply(names, foo)); }', :shrink_vars => true)
|
66
|
-
assert_equal expected, actual
|
67
|
-
end
|
68
|
-
end
|