defacer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Guardfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/defacer.gemspec +27 -0
- data/lib/defacer/version.rb +3 -0
- data/lib/defacer.rb +25 -0
- data/spec/fixtures/google_maps_example.js +97 -0
- data/spec/fixtures/jquery-2.1.1.js +9190 -0
- data/spec/lib/defacer_spec.rb +28 -0
- data/spec/spec_helper.rb +8 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c028358c98698cc06fd73e5c0ef431e9c4bd676
|
4
|
+
data.tar.gz: 489a5c35581b16f888695f989441d01a4e75b9aa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e724488b72f1c3f5600c0693a7390f6bf95220c88b65e41284983eb473dd0336c2e623a22bfcd37cd3f1cdc5e7fc3338512bcd043354b3068972843ecc7f43b3
|
7
|
+
data.tar.gz: 4153c51cb7fb6e4616f275519d017600d59b2f45a7d907ae1730dea6ab369ec60cebe686bad59b561d2e4ae34666b2a3960d8ce8339add47335d6af4e4c5d930
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Bradley Buda
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Defacer
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'defacer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install defacer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/defacer/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/defacer.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'defacer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "defacer"
|
8
|
+
spec.version = Defacer::VERSION
|
9
|
+
spec.authors = ["Bradley Buda"]
|
10
|
+
spec.email = ["bradleybuda@gmail.com"]
|
11
|
+
spec.summary = %q{Pure-ruby JavaScript minifier}
|
12
|
+
spec.description = %q{Favors speed over size of minified JS, works on any ruby platform, works well with the Rails asset pipeline and Sprockets}
|
13
|
+
spec.homepage = "https://github.com/meldium/defacer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'rkelly-remix', '0.0.6'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.2'
|
27
|
+
end
|
data/lib/defacer.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "defacer/version"
|
2
|
+
|
3
|
+
require 'rkelly'
|
4
|
+
|
5
|
+
module Defacer
|
6
|
+
class WhitespaceRemovingVisitor < RKelly::Visitors::ECMAVisitor
|
7
|
+
def visit_SourceElementsNode(o)
|
8
|
+
o.value.map { |x| "#{indent}#{x.accept(self)}" }.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def visit_FunctionBodyNode(o)
|
12
|
+
"{#{o.value.accept(self)}}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.compress(source)
|
17
|
+
parser = RKelly::Parser.new
|
18
|
+
ast = parser.parse(source)
|
19
|
+
if ast # TODO test this case
|
20
|
+
WhitespaceRemovingVisitor.new.accept(ast)
|
21
|
+
else
|
22
|
+
''
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
var map;
|
2
|
+
var TILE_SIZE = 256;
|
3
|
+
var chicago = new google.maps.LatLng(41.850033,-87.6500523);
|
4
|
+
|
5
|
+
function bound(value, opt_min, opt_max) {
|
6
|
+
if (opt_min != null) value = Math.max(value, opt_min);
|
7
|
+
if (opt_max != null) value = Math.min(value, opt_max);
|
8
|
+
return value;
|
9
|
+
}
|
10
|
+
|
11
|
+
function degreesToRadians(deg) {
|
12
|
+
return deg * (Math.PI / 180);
|
13
|
+
}
|
14
|
+
|
15
|
+
function radiansToDegrees(rad) {
|
16
|
+
return rad / (Math.PI / 180);
|
17
|
+
}
|
18
|
+
|
19
|
+
/** @constructor */
|
20
|
+
function MercatorProjection() {
|
21
|
+
this.pixelOrigin_ = new google.maps.Point(TILE_SIZE / 2,
|
22
|
+
TILE_SIZE / 2);
|
23
|
+
this.pixelsPerLonDegree_ = TILE_SIZE / 360;
|
24
|
+
this.pixelsPerLonRadian_ = TILE_SIZE / (2 * Math.PI);
|
25
|
+
}
|
26
|
+
|
27
|
+
MercatorProjection.prototype.fromLatLngToPoint = function(latLng,
|
28
|
+
opt_point) {
|
29
|
+
var me = this;
|
30
|
+
var point = opt_point || new google.maps.Point(0, 0);
|
31
|
+
var origin = me.pixelOrigin_;
|
32
|
+
|
33
|
+
point.x = origin.x + latLng.lng() * me.pixelsPerLonDegree_;
|
34
|
+
|
35
|
+
// Truncating to 0.9999 effectively limits latitude to 89.189. This is
|
36
|
+
// about a third of a tile past the edge of the world tile.
|
37
|
+
var siny = bound(Math.sin(degreesToRadians(latLng.lat())), -0.9999,
|
38
|
+
0.9999);
|
39
|
+
point.y = origin.y + 0.5 * Math.log((1 + siny) / (1 - siny)) *
|
40
|
+
-me.pixelsPerLonRadian_;
|
41
|
+
return point;
|
42
|
+
};
|
43
|
+
|
44
|
+
MercatorProjection.prototype.fromPointToLatLng = function(point) {
|
45
|
+
var me = this;
|
46
|
+
var origin = me.pixelOrigin_;
|
47
|
+
var lng = (point.x - origin.x) / me.pixelsPerLonDegree_;
|
48
|
+
var latRadians = (point.y - origin.y) / -me.pixelsPerLonRadian_;
|
49
|
+
var lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) -
|
50
|
+
Math.PI / 2);
|
51
|
+
return new google.maps.LatLng(lat, lng);
|
52
|
+
};
|
53
|
+
|
54
|
+
function createInfoWindowContent() {
|
55
|
+
var numTiles = 1 << map.getZoom();
|
56
|
+
var projection = new MercatorProjection();
|
57
|
+
var worldCoordinate = projection.fromLatLngToPoint(chicago);
|
58
|
+
var pixelCoordinate = new google.maps.Point(
|
59
|
+
worldCoordinate.x * numTiles,
|
60
|
+
worldCoordinate.y * numTiles);
|
61
|
+
var tileCoordinate = new google.maps.Point(
|
62
|
+
Math.floor(pixelCoordinate.x / TILE_SIZE),
|
63
|
+
Math.floor(pixelCoordinate.y / TILE_SIZE));
|
64
|
+
|
65
|
+
return [
|
66
|
+
'Chicago, IL',
|
67
|
+
'LatLng: ' + chicago.lat() + ' , ' + chicago.lng(),
|
68
|
+
'World Coordinate: ' + worldCoordinate.x + ' , ' +
|
69
|
+
worldCoordinate.y,
|
70
|
+
'Pixel Coordinate: ' + Math.floor(pixelCoordinate.x) + ' , ' +
|
71
|
+
Math.floor(pixelCoordinate.y),
|
72
|
+
'Tile Coordinate: ' + tileCoordinate.x + ' , ' +
|
73
|
+
tileCoordinate.y + ' at Zoom Level: ' + map.getZoom()
|
74
|
+
].join('<br>');
|
75
|
+
}
|
76
|
+
|
77
|
+
function initialize() {
|
78
|
+
var mapOptions = {
|
79
|
+
zoom: 3,
|
80
|
+
center: chicago
|
81
|
+
};
|
82
|
+
|
83
|
+
map = new google.maps.Map(document.getElementById('map-canvas'),
|
84
|
+
mapOptions);
|
85
|
+
|
86
|
+
var coordInfoWindow = new google.maps.InfoWindow();
|
87
|
+
coordInfoWindow.setContent(createInfoWindowContent());
|
88
|
+
coordInfoWindow.setPosition(chicago);
|
89
|
+
coordInfoWindow.open(map);
|
90
|
+
|
91
|
+
google.maps.event.addListener(map, 'zoom_changed', function() {
|
92
|
+
coordInfoWindow.setContent(createInfoWindowContent());
|
93
|
+
coordInfoWindow.open(map);
|
94
|
+
});
|
95
|
+
}
|
96
|
+
|
97
|
+
google.maps.event.addDomListener(window, 'load', initialize);
|