Skip to content

Commit

Permalink
Switch from Hoe to Bundler for managing dependencies, and tidy up a l…
Browse files Browse the repository at this point in the history
…ittle.
  • Loading branch information
jcoglan committed Jul 19, 2011
1 parent 5896f94 commit 14c3904
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
Gemfile.lock
*.gem
.redcar
2 changes: 2 additions & 0 deletions Gemfile
@@ -0,0 +1,2 @@
source "http://rubygems.org"
gemspec
4 changes: 4 additions & 0 deletions History.txt
@@ -1,3 +1,7 @@
=== 3.1.1 / 2011-07-19

* Remove dependency on Hoe

=== 3.1.0 / 2009-02-22

* Project is now a gem, not a Rails plugin
Expand Down
19 changes: 0 additions & 19 deletions Manifest.txt

This file was deleted.

84 changes: 40 additions & 44 deletions README.txt → README.rdoc
Expand Up @@ -4,22 +4,24 @@
* http://dean.edwards.name/packer/
* http://base2.googlecode.com


== Description

PackR is a Ruby version of Dean Edwards' JavaScript compressor.


== Features

* Whitespace and comment removal
* Compression of local variable names
* Compression and obfuscation of 'private' (_underscored) identifiers
* Base-62 encoding


== Synopsis

To call from within a Ruby program:

require 'rubygems'
require 'packr'

code = File.read('my_script.js')
Expand All @@ -41,72 +43,66 @@ The full list of available options is:
compressed = Packr.pack(code, :shrink_vars => true,
:protect => %w[$super self])

To call from the command line (use <tt>packr --help</tt> to see available options):
To call from the command line (use <tt>packr --help</tt> to see available
options):

packr my_script.js > my_script.min.js



== Notes

This program is not a JavaScript parser, and rewrites your files using regular
expressions. Be sure to include semicolons and braces everywhere they are required
so that your program will work correctly when packed down to a single line.
expressions. Be sure to include semicolons and braces everywhere they are
required so that your program will work correctly when packed down to a single
line.

By far the most efficient way to serve JavaScript over the web is to use PackR
with the --shrink-vars flag, combined with gzip compression. If you don't have access
to your server config to set up mod_deflate, you can generate gzip files using
(on Unix-like systems):
with the --shrink-vars flag, combined with gzip compression. If you don't have
access to your server config to set up mod_deflate, you can generate gzip files
using (on Unix-like systems):

packr -s my-file.js | gzip > my-file.js.gz

You can then get Apache to serve the files by putting this in your .htaccess file:
You can then get Apache to serve the files by putting this in your .htaccess
file:

AddEncoding gzip .gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [QSA,L]

If you really cannot serve gzip files, use the --base62 option to further compress
your code. This mode is at its best when compressing large files with many repeated
tokens.
If you really cannot serve gzip files, use the --base62 option to further
compress your code. This mode is at its best when compressing large files with
many repeated tokens.

The --private option can be used to stop other programs calling private methods
in your code by renaming anything beginning with a single underscore. Beware that
you should not use this if the generated file contains 'private' methods that need
to be accessible by other files. Also know that all the files that access any
particular private method must be compressed together so they all get the same
rewritten name for the private method.
in your code by renaming anything beginning with a single underscore. Beware
that you should not use this if the generated file contains 'private' methods
that need to be accessible by other files. Also know that all the files that
access any particular private method must be compressed together so they all get
the same rewritten name for the private method.

== Requirements

* Rubygems
* Oyster (installed automatically)
== License

== Installation
(The MIT License)

sudo gem install packr -y
Copyright (c) 2004-2011 Dean Edwards, James Coglan

== License
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the 'Software'), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

(The MIT License)
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

Copyright (c) 2004-2009 Dean Edwards, James Coglan

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 changes: 0 additions & 12 deletions Rakefile

This file was deleted.

82 changes: 44 additions & 38 deletions bin/packr
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'oyster'
require 'packr'
require File.expand_path('../../lib/packr', __FILE__)

spec = Oyster.spec do
name "packr -- JavaScript code compressor based on Dean Edwards' Packer"
Expand All @@ -11,13 +13,14 @@ spec = Oyster.spec do
EOS

description <<-EOS
PackR is a program for compressing JavaScript programs. It can remove whitespace
and comments, compress local variable names, compress/obfuscate private identifiers,
and encode the program in base-62.
PackR is a program for compressing JavaScript programs. It can remove
whitespace and comments, compress local variable names, compress/obfuscate
private identifiers, and encode the program in base-62.
When invoked from the command line, it concatenates all the code in INPUT_FILES (or
from standard input) and compresses the code using the given options, printing the
result to standard output. You can pipe this output into another file to save it.
When invoked from the command line, it concatenates all the code in
INPUT_FILES (or from standard input) and compresses the code using the given
options, printing the result to standard output. You can pipe this output into
another file to save it.
EOS

flag :'shrink-vars', :default => true,
Expand All @@ -34,58 +37,61 @@ spec = Oyster.spec do

notes <<-EOS
This program is not a JavaScript parser, and rewrites your files using regular
expressions. Be sure to include semicolons and braces everywhere they are required
so that your program will work correctly when packed down to a single line.
expressions. Be sure to include semicolons and braces everywhere they are
required so that your program will work correctly when packed down to a single
line.
By far the most efficient way to serve JavaScript over the web is to use PackR
with the --shrink-vars flag, combined with gzip compression. If you don't have access
to your server config to set up mod_deflate, you can generate gzip files using
(on Unix-like systems):
with the --shrink-vars flag, combined with gzip compression. If you don't have
access to your server config to set up mod_deflate, you can generate gzip
files using (on Unix-like systems):
packr -s my-file.js | gzip > my-file.js.gz
You can then get Apache to serve the files by putting this in your .htaccess file:
You can then get Apache to serve the files by putting this in your .htaccess
file:
AddEncoding gzip .gz
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [QSA,L]
If you really cannot serve gzip files, use the --base62 option to further compress
your code. This mode is at its best when compressing large files with many repeated
tokens.
If you really cannot serve gzip files, use the --base62 option to further
compress your code. This mode is at its best when compressing large files with
many repeated tokens.
The --private option can be used to stop other programs calling private methods
in your code by renaming anything beginning with a single underscore. Beware that
you should not use this if the generated file contains 'private' methods that need
to be accessible by other files. Also know that all the files that access any
particular private method must be compressed together so they all get the same
rewritten name for the private method.
The --private option can be used to stop other programs calling private
methods in your code by renaming anything beginning with a single underscore.
Beware that you should not use this if the generated file contains 'private'
methods that need to be accessible by other files. Also know that all the
files that access any particular private method must be compressed together so
they all get the same rewritten name for the private method.
EOS

author <<-EOS
Original JavaScript version by Dean Edwards, Ruby port by James Coglan <jcoglan@googlemail.com>
EOS

copyright <<-EOS
Copyright (c) 2004-2008 Dean Edwards, James Coglan. This program is free software,
distributed under the MIT license.
Copyright (c) 2004-2011 Dean Edwards, James Coglan. This program is free
software, distributed under the MIT license.
EOS
end

begin; opts = spec.parse
rescue Oyster::HelpRendered; exit
begin
opts = spec.parse

inputs = opts[:unclaimed]
code = inputs.empty? ?
$stdin.read :
inputs.map { |f| File.read(f) }.join("\n")

$stdout.puts Packr.pack(code,
:shrink_vars => !!opts[:'shrink-vars'],
:protect => opts[:protect],
:private => !!opts[:private],
:base62 => !!opts[:base62])

rescue Oyster::HelpRendered
end

inputs = opts[:unclaimed]
code = inputs.empty? ?
$stdin.read :
inputs.map { |f| File.read(f) }.join("\n")

$stdout.puts Packr.pack(code,
:shrink_vars => !!opts[:'shrink-vars'],
:protect => opts[:protect],
:private => !!opts[:private],
:base62 => !!opts[:base62])

6 changes: 0 additions & 6 deletions lib/packr.rb
@@ -1,7 +1,3 @@
# PackR -- a Ruby port of Packer by Dean Edwards
# Packer version 3.1 copyright 2004-2009, Dean Edwards
# http://www.opensource.org/licenses/mit-license

[ '/string',
'/packr/map',
'/packr/collection',
Expand All @@ -20,8 +16,6 @@

class Packr

VERSION = '3.1.0'

DATA = Parser.new.
put("STRING1", IGNORE).
put('STRING2', IGNORE).
Expand Down
20 changes: 20 additions & 0 deletions packr.gemspec
@@ -0,0 +1,20 @@
Gem::Specification.new do |s|
s.name = "packr"
s.version = "3.1.1"
s.summary = "Ruby version of Dean Edwards' JavaScript compressor"
s.author = "James Coglan"
s.email = "jcoglan@gmail.com"
s.homepage = "http://github.com/jcoglan/packr"

s.extra_rdoc_files = %w[README.rdoc]
s.rdoc_options = %w[--main README.rdoc]

s.files = %w[History.txt README.rdoc] + Dir.glob("{bin,lib,test}/**/*")

s.executables = Dir.glob("bin/**").map { |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "oyster", ">= 0.9.5"

s.add_development_dependency "test-unit"
end
5 changes: 4 additions & 1 deletion test/test_packr.rb
@@ -1,6 +1,9 @@
require 'rubygems'
require 'bundler/setup'
require 'test/unit'
require 'fileutils'
require 'packr'

require File.expand_path('../../lib/packr', __FILE__)

class PackrTest < Test::Unit::TestCase

Expand Down

0 comments on commit 14c3904

Please sign in to comment.