diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e569dd1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+Gemfile.lock
+*.gem
+.redcar
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..1aa98e4
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,2 @@
+source "http://rubygems.org"
+gemspec
diff --git a/History.txt b/History.txt
index 078b92f..8f28414 100644
--- a/History.txt
+++ b/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
diff --git a/Manifest.txt b/Manifest.txt
deleted file mode 100644
index 4cf17ab..0000000
--- a/Manifest.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-History.txt
-Manifest.txt
-README.txt
-Rakefile
-bin/packr
-lib/packr.rb
-lib/string.rb
-lib/packr/map.rb
-lib/packr/collection.rb
-lib/packr/regexp_group.rb
-lib/packr/constants.rb
-lib/packr/encoder.rb
-lib/packr/minifier.rb
-lib/packr/parser.rb
-lib/packr/privates.rb
-lib/packr/shrinker.rb
-lib/packr/words.rb
-lib/packr/base62.rb
-test/test_packr.rb
diff --git a/README.txt b/README.rdoc
similarity index 55%
rename from README.txt
rename to README.rdoc
index 8ba54e5..d6cf7dc 100644
--- a/README.txt
+++ b/README.rdoc
@@ -4,10 +4,12 @@
* 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
@@ -15,11 +17,11 @@ PackR is a Ruby version of Dean Edwards' JavaScript compressor.
* 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')
@@ -41,24 +43,28 @@ 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 packr --help to see available options):
+To call from the command line (use packr --help 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
@@ -66,47 +72,37 @@ You can then get Apache to serve the files by putting this in your .htaccess fil
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.
diff --git a/Rakefile b/Rakefile
deleted file mode 100644
index 8ca00b2..0000000
--- a/Rakefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- ruby -*-
-
-require 'rubygems'
-require 'hoe'
-require './lib/packr.rb'
-
-Hoe.new('packr', Packr::VERSION) do |p|
- p.developer('James Coglan', 'jcoglan@googlemail.com')
- p.extra_deps = %w(oyster)
-end
-
-# vim: syntax=Ruby
diff --git a/bin/packr b/bin/packr
index 04f3cd9..021afd8 100644
--- a/bin/packr
+++ b/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"
@@ -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,
@@ -34,17 +37,19 @@ 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
@@ -52,16 +57,16 @@ spec = Oyster.spec do
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
@@ -69,23 +74,24 @@ spec = Oyster.spec do
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])
-
diff --git a/lib/packr.rb b/lib/packr.rb
index ec550cd..bab95ca 100644
--- a/lib/packr.rb
+++ b/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',
@@ -20,8 +16,6 @@
class Packr
- VERSION = '3.1.0'
-
DATA = Parser.new.
put("STRING1", IGNORE).
put('STRING2', IGNORE).
diff --git a/packr.gemspec b/packr.gemspec
new file mode 100644
index 0000000..6d4154b
--- /dev/null
+++ b/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
diff --git a/test/test_packr.rb b/test/test_packr.rb
index 91fae5c..05ee731 100644
--- a/test/test_packr.rb
+++ b/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