Module: Packr

Defined in:
lib/packr.rb,
lib/packr/map.rb,
lib/packr/words.rb,
lib/packr/base62.rb,
lib/packr/engine.rb,
lib/packr/parser.rb,
lib/packr/encoder.rb,
lib/packr/minifier.rb,
lib/packr/privates.rb,
lib/packr/shrinker.rb,
lib/packr/collection.rb,
lib/packr/regexp_group.rb

Defined Under Namespace

Classes: Base62, Collection, Encoder, Engine, Map, Minifier, Parser, Privates, RegexpGroup, Shrinker, Words

Constant Summary collapse

IGNORE =
RegexpGroup::IGNORE
REMOVE =
""
SPACE =
" "
DATA =
Parser.new.
put("STRING1", IGNORE).
put('STRING2', IGNORE).
put("CONDITIONAL", IGNORE). # conditional comments
put("(OPERATOR)\\s*(REGEXP)", "\\1\\2")
CONCAT =
Parser.new.
put("(STRING1)\\+(STRING1)", lambda { |*args| args[1][0...-1] + args[3][1..-1] }).
put("(STRING2)\\+(STRING2)", lambda { |*args| args[1][0...-1] + args[3][1..-1] })

Class Method Summary collapse

Class Method Details

.encode52(c) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/packr.rb', line 30

def self.encode52(c)
  # Base52 encoding (a-Z)
  encode = lambda do |d|
    (d < 52 ? '' : encode.call((d / 52.0).to_i)) +
        ((d = d % 52) > 25 ? (d + 39).chr : (d + 97).chr)
  end
  encoded = encode.call(c.to_i)
  encoded = encoded[1..-1] + '0' if encoded =~ /^(do|if|in)$/
  encoded
end

.encode62(c) ⇒ Object



25
26
27
28
# File 'lib/packr.rb', line 25

def self.encode62(c)
  (c < 62 ? '' : encode62((c / 62.0).to_i)) +
      ((c = c % 62) > 35 ? (c+29).chr : c.to_s(36))
end

.newObject



50
51
52
# File 'lib/packr.rb', line 50

def self.new
  Packr::Engine.new
end

.pack(script, options = {}) ⇒ Object



45
46
47
48
# File 'lib/packr.rb', line 45

def self.pack(script, options = {})
  @packr ||= Packr::Engine.new
  @packr.pack(script, options)
end

.rescape(string) ⇒ Object



41
42
43
# File 'lib/packr.rb', line 41

def self.rescape(string)
  string.gsub(/([\/()\[\]{}|*+-.,^$?\\])/) { |m| "\\#{$1}" }
end