jzip 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG +74 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.textile +159 -0
  5. data/Rakefile +42 -0
  6. data/VERSION +1 -0
  7. data/init.rb +1 -0
  8. data/install.rb +3 -0
  9. data/jzip.gemspec +143 -0
  10. data/lib/jzip.rb +7 -0
  11. data/lib/jzip/actionpack.rb +2 -0
  12. data/lib/jzip/actionpack/action_controller/base.rb +18 -0
  13. data/lib/jzip/assets.rb +28 -0
  14. data/lib/jzip/core.rb +4 -0
  15. data/lib/jzip/core/string.rb +6 -0
  16. data/lib/jzip/core/string/analyzation.rb +22 -0
  17. data/lib/jzip/engine.rb +82 -0
  18. data/lib/jzip/engine/requirement.rb +46 -0
  19. data/lib/jzip/engine/support/jsmin.rb +205 -0
  20. data/lib/jzip/engine/support/minifier.rb +31 -0
  21. data/lib/jzip/engine/support/notifier.rb +21 -0
  22. data/lib/jzip/engine/template.rb +141 -0
  23. data/lib/jzip/plugin.rb +12 -0
  24. data/rails/init.rb +1 -0
  25. data/tasks/jzip.rake +11 -0
  26. data/test/actionpack/action_controller/base_test.rb +74 -0
  27. data/test/core/string/analyzation_test.rb +31 -0
  28. data/test/engine_test.rb +17 -0
  29. data/test/javascripts/after/compressed/public/javascripts/backend.js +34 -0
  30. data/test/javascripts/after/compressed/public/javascripts/defaults.js +461 -0
  31. data/test/javascripts/after/compressed/public/javascripts/frontend.js +34 -0
  32. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/code_heroes/backend.js +2 -0
  33. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/code_heroes/frontend.js +2 -0
  34. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/code_heroes.js +3 -0
  35. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/code_heroes/ajaxify.js +2 -0
  36. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/jquery/ajax_setup.js +4 -0
  37. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/jquery/class.js +5 -0
  38. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/jquery/components/core.js +6 -0
  39. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/jquery/extensions/core.js +5 -0
  40. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/jquery/extensions/deparam.js +4 -0
  41. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/jquery/seat_holder.js +12 -0
  42. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/native/extensions/array.js +4 -0
  43. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/native/extensions/string.js +2 -0
  44. data/test/javascripts/after/compressed/tmp/jzip/_minified_/assets/jzip/shared/native/log.js +2 -0
  45. data/test/javascripts/after/compressed/tmp/jzip/_minified_/public/javascripts/application.js +0 -0
  46. data/test/javascripts/after/compressed/tmp/jzip/_minified_/public/javascripts/controls.js +66 -0
  47. data/test/javascripts/after/compressed/tmp/jzip/_minified_/public/javascripts/dragdrop.js +68 -0
  48. data/test/javascripts/after/compressed/tmp/jzip/_minified_/public/javascripts/effects.js +49 -0
  49. data/test/javascripts/after/compressed/tmp/jzip/_minified_/public/javascripts/prototype.js +278 -0
  50. data/test/javascripts/after/compressed/tmp/jzip/_minified_/tmp/jzip/public/javascripts/shared/_shared.js +32 -0
  51. data/test/javascripts/after/compressed/tmp/jzip/_minified_/tmp/jzip/public/javascripts/shared/jquery/_core.js +6 -0
  52. data/test/javascripts/after/compressed/tmp/jzip/public/javascripts/shared/_shared.js +49 -0
  53. data/test/javascripts/after/compressed/tmp/jzip/public/javascripts/shared/jquery/_core.js +6 -0
  54. data/test/javascripts/after/uncompressed/public/javascripts/backend.js +826 -0
  55. data/test/javascripts/after/uncompressed/public/javascripts/defaults.js +7389 -0
  56. data/test/javascripts/after/uncompressed/public/javascripts/frontend.js +826 -0
  57. data/test/javascripts/after/uncompressed/tmp/jzip/public/javascripts/shared/_shared.js +811 -0
  58. data/test/javascripts/after/uncompressed/tmp/jzip/public/javascripts/shared/jquery/_core.js +158 -0
  59. data/test/javascripts/assets/jzip/backend.jz +3 -0
  60. data/test/javascripts/assets/jzip/code_heroes/backend.js +15 -0
  61. data/test/javascripts/assets/jzip/code_heroes/frontend.js +15 -0
  62. data/test/javascripts/assets/jzip/defaults.jz +2 -0
  63. data/test/javascripts/assets/jzip/frontend.jz +3 -0
  64. data/test/javascripts/assets/jzip/shared/_shared.jz +15 -0
  65. data/test/javascripts/assets/jzip/shared/code_heroes.js +25 -0
  66. data/test/javascripts/assets/jzip/shared/code_heroes/ajaxify.js +15 -0
  67. data/test/javascripts/assets/jzip/shared/jquery/_all.jz +4 -0
  68. data/test/javascripts/assets/jzip/shared/jquery/_core.fxc-clip.jz +3 -0
  69. data/test/javascripts/assets/jzip/shared/jquery/_core.jz +2 -0
  70. data/test/javascripts/assets/jzip/shared/jquery/_core.uic-resizable.jz +3 -0
  71. data/test/javascripts/assets/jzip/shared/jquery/_fxc-clip.jz +2 -0
  72. data/test/javascripts/assets/jzip/shared/jquery/_fxc-clip.uic-resizable.jz +3 -0
  73. data/test/javascripts/assets/jzip/shared/jquery/_uic-resizable.jz +2 -0
  74. data/test/javascripts/assets/jzip/shared/jquery/ajax_setup.js +23 -0
  75. data/test/javascripts/assets/jzip/shared/jquery/class.js +213 -0
  76. data/test/javascripts/assets/jzip/shared/jquery/components/core.js +157 -0
  77. data/test/javascripts/assets/jzip/shared/jquery/components/fxc-clip.js +16 -0
  78. data/test/javascripts/assets/jzip/shared/jquery/components/uic-resizable.js +16 -0
  79. data/test/javascripts/assets/jzip/shared/jquery/extensions/core.js +36 -0
  80. data/test/javascripts/assets/jzip/shared/jquery/extensions/deparam.js +113 -0
  81. data/test/javascripts/assets/jzip/shared/jquery/seat_holder.js +184 -0
  82. data/test/javascripts/assets/jzip/shared/native/extensions/array.js +28 -0
  83. data/test/javascripts/assets/jzip/shared/native/extensions/string.js +4 -0
  84. data/test/javascripts/assets/jzip/shared/native/log.js +8 -0
  85. data/test/javascripts/before/application.js +2 -0
  86. data/test/javascripts/before/controls.js +963 -0
  87. data/test/javascripts/before/dragdrop.js +973 -0
  88. data/test/javascripts/before/effects.js +1128 -0
  89. data/test/javascripts/before/prototype.js +4320 -0
  90. data/test/rails_root/compressed/assets/jzip/foo.js +0 -0
  91. data/test/rails_root/compressed/public/javascripts/foo.js +0 -0
  92. data/test/rails_root/uncompressed/assets/jzip/foo.js +0 -0
  93. data/test/rails_root/uncompressed/public/javascripts/foo.js +0 -0
  94. data/test/setup.rb +12 -0
  95. data/test/test_helper.rb +5 -0
  96. data/uninstall.rb +1 -0
  97. metadata +177 -0
@@ -0,0 +1,7 @@
1
+
2
+ module Jzip
3
+ extend self
4
+ end
5
+
6
+ require "jzip/core"
7
+ require "jzip/actionpack"
@@ -0,0 +1,2 @@
1
+
2
+ require File.join(File.dirname(__FILE__), "actionpack", "action_controller", "base.rb")
@@ -0,0 +1,18 @@
1
+
2
+ unless defined?(Jzip::CONTROLLER_HOOKED)
3
+
4
+ module ActionController
5
+
6
+ class Base
7
+ alias_method :original_process, :process
8
+ def process(*args)
9
+ Jzip::Engine.compile_javascript_files
10
+ original_process(*args)
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ Jzip::CONTROLLER_HOOKED = true
17
+
18
+ end
@@ -0,0 +1,28 @@
1
+
2
+ module Jzip
3
+ module Assets
4
+ extend self
5
+
6
+ def install_defaults
7
+ puts "Installing defaults..."
8
+
9
+ create_default_template_location
10
+ File.open(File.join(default_template_location, "defaults.jz"), "w") do |f|
11
+ f.write("\n//= require /defaults\n")
12
+ end
13
+
14
+ puts "Done"
15
+ end
16
+
17
+ private
18
+
19
+ def create_default_template_location
20
+ FileUtils.mkdir_p default_template_location
21
+ end
22
+
23
+ def default_template_location
24
+ File.join Jzip::Engine.root_dir, "assets", "jzip"
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+
2
+ Dir[File.join(File.dirname(__FILE__), "core", "*.rb")].each do |file|
3
+ require file
4
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require "jzip/core/string/analyzation"
3
+
4
+ class String
5
+ include Jzip::Core::String::Analyzation
6
+ end
@@ -0,0 +1,22 @@
1
+
2
+ module Jzip
3
+ module Core
4
+ module String
5
+ module Analyzation
6
+
7
+ def jzip_require_statement?
8
+ !!self.strip.match(Jzip::Engine::REG_EXPS[:require_statement])
9
+ end
10
+
11
+ def required_jzip_source(exclude_exclamation_mark = true)
12
+ self.strip.gsub(Regexp.new([Jzip::Engine::REG_EXPS[:require_statement].source, ("\!?" if exclude_exclamation_mark)].compact.join), "").strip if self.jzip_require_statement?
13
+ end
14
+
15
+ def overrule_jzip_minification?
16
+ !!required_jzip_source(false).match(/^!/) if self.jzip_require_statement?
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+
2
+ module Jzip
3
+ module Engine
4
+ include Support::Notifier
5
+
6
+ extend self
7
+
8
+ PREDEFINED_SETS = {"defaults" => %w(prototype effects dragdrop controls application)}
9
+ REG_EXPS = {:require_statement => /^\/\/\=\s*require\s*/, :partial => /^_/, :default_javascripts => /^\//}
10
+
11
+ @options = {
12
+ :minify => RAILS_ENV == "production",
13
+ :always_update => RAILS_ENV != "production"
14
+ }
15
+ attr_reader :root_dir, :options
16
+
17
+ def root_dir=(value)
18
+ @template_locations.clear
19
+ @initial_compile = true
20
+ @root_dir = value
21
+ end
22
+
23
+ def options=(value)
24
+ @options.merge! value
25
+ end
26
+
27
+ def add_template_location(location)
28
+ @template_locations << location
29
+ end
30
+
31
+ def compile_javascript_files
32
+ return unless @options[:always_update] or @initial_compile
33
+
34
+ init if @initial_compile
35
+ parse_templates
36
+ @initial_compile = false
37
+ end
38
+
39
+ def init
40
+ @template_locations.unshift File.join(root_dir, "assets", "jzip")
41
+ FileUtils.mkdir_p tmp_dir
42
+ end
43
+
44
+ def root_dir
45
+ @root_dir || RAILS_ROOT
46
+ end
47
+
48
+ def tmp_dir
49
+ File.join(root_dir, "tmp", "jzip")
50
+ end
51
+
52
+ private
53
+
54
+ @template_locations = []
55
+ @initial_compile = true
56
+
57
+ def template_refs
58
+ Hash[
59
+ *@template_locations.collect do |location|
60
+ (location.is_a?(Hash) ? location.to_a : [location].flatten).collect do |x|
61
+ ref = [x].flatten
62
+ [ref.shift, ref.shift || File.join(root_dir, "public", "javascripts")]
63
+ end
64
+ end.flatten
65
+ ]
66
+ end
67
+
68
+ def parse_templates
69
+ notify "Compiling templates..."
70
+
71
+ Template.clear_instances
72
+ template_refs.each do |source, target|
73
+ Dir.glob(File.join(source, "**", "[^_]*.jz")).each do |template|
74
+ Template.build(template, source, target).parse
75
+ end
76
+ end
77
+
78
+ notify "Done"
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,46 @@
1
+
2
+ module Jzip
3
+ module Engine
4
+
5
+ Requirement = Struct.new(:file, :source, :target, :overrule_minification) do
6
+
7
+ include Support::Notifier
8
+
9
+ def newer?(mtime)
10
+ notify "Newer '#{target_file}'" if result = mtime < File.mtime(target_file)
11
+ result
12
+ end
13
+
14
+ def parse
15
+ @code ||= begin
16
+ source_file = plain_javascript? ? self.file : (template.parse; template.target_file)
17
+ File.read(minify? ? Support::Minifier.parse(source_file) : source_file)
18
+ end
19
+ end
20
+
21
+ def code
22
+ parse
23
+ end
24
+
25
+ private
26
+
27
+ def plain_javascript?
28
+ File.extname(self.file) == ".js"
29
+ end
30
+
31
+ def minify?
32
+ Jzip::Engine::options[:minify] && !@overrule_minification
33
+ end
34
+
35
+ def template
36
+ @template ||= Template.build(self.file, self.source, self.target) unless plain_javascript?
37
+ end
38
+
39
+ def target_file
40
+ plain_javascript? ? self.file : template.target_file
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/ruby
2
+ # jsmin.rb 2007-07-20
3
+ # Author: Uladzislau Latynski
4
+ # This work is a translation from C to Ruby of jsmin.c published by
5
+ # Douglas Crockford. Permission is hereby granted to use the Ruby
6
+ # version under the same conditions as the jsmin.c on which it is
7
+ # based.
8
+ #
9
+ # /* jsmin.c
10
+ # 2003-04-21
11
+ #
12
+ # Copyright (c) 2002 Douglas Crockford (www.crockford.com)
13
+ #
14
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
15
+ # this software and associated documentation files (the "Software"), to deal in
16
+ # the Software without restriction, including without limitation the rights to
17
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
+ # of the Software, and to permit persons to whom the Software is furnished to do
19
+ # so, subject to the following conditions:
20
+ #
21
+ # The above copyright notice and this permission notice shall be included in all
22
+ # copies or substantial portions of the Software.
23
+ #
24
+ # The Software shall be used for Good, not Evil.
25
+ #
26
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ # SOFTWARE.
33
+
34
+ EOF = -1
35
+ $theA = ""
36
+ $theB = ""
37
+
38
+ # isAlphanum -- return true if the character is a letter, digit, underscore,
39
+ # dollar sign, or non-ASCII character
40
+ def isAlphanum(c)
41
+ return false if !c || c == EOF
42
+ return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
43
+ (c >= 'A' && c <= 'Z') || c == '_' || c == '$' ||
44
+ c == '\\' || c[0] > 126)
45
+ end
46
+
47
+ # get -- return the next character from stdin. Watch out for lookahead. If
48
+ # the character is a control character, translate it to a space or linefeed.
49
+ def get()
50
+ c = $stdin.getc
51
+ return EOF if(!c)
52
+ c = c.chr
53
+ return c if (c >= " " || c == "\n" || c.unpack("c") == EOF)
54
+ return "\n" if (c == "\r")
55
+ return " "
56
+ end
57
+
58
+ # Get the next character without getting it.
59
+ def peek()
60
+ lookaheadChar = $stdin.getc
61
+ $stdin.ungetc(lookaheadChar)
62
+ return lookaheadChar.chr
63
+ end
64
+
65
+ # mynext -- get the next character, excluding comments.
66
+ # peek() is used to see if a '/' is followed by a '/' or '*'.
67
+ def mynext()
68
+ c = get
69
+ if (c == "/")
70
+ if(peek == "/")
71
+ while(true)
72
+ c = get
73
+ if (c <= "\n")
74
+ return c
75
+ end
76
+ end
77
+ end
78
+ if(peek == "*")
79
+ get
80
+ while(true)
81
+ case get
82
+ when "*"
83
+ if (peek == "/")
84
+ get
85
+ return " "
86
+ end
87
+ when EOF
88
+ raise "Unterminated comment"
89
+ end
90
+ end
91
+ end
92
+ end
93
+ return c
94
+ end
95
+
96
+
97
+ # action -- do something! What you do is determined by the argument: 1
98
+ # Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B.
99
+ # (Delete A). 3 Get the next B. (Delete B). action treats a string as a
100
+ # single character. Wow! action recognizes a regular expression if it is
101
+ # preceded by ( or , or =.
102
+ def action(a)
103
+ if(a==1)
104
+ $stdout.write $theA
105
+ end
106
+ if(a==1 || a==2)
107
+ $theA = $theB
108
+ if ($theA == "\'" || $theA == "\"")
109
+ while (true)
110
+ $stdout.write $theA
111
+ $theA = get
112
+ break if ($theA == $theB)
113
+ raise "Unterminated string literal" if ($theA <= "\n")
114
+ if ($theA == "\\")
115
+ $stdout.write $theA
116
+ $theA = get
117
+ end
118
+ end
119
+ end
120
+ end
121
+ if(a==1 || a==2 || a==3)
122
+ $theB = mynext
123
+ if ($theB == "/" && ($theA == "(" || $theA == "," || $theA == "=" ||
124
+ $theA == ":" || $theA == "[" || $theA == "!" ||
125
+ $theA == "&" || $theA == "|" || $theA == "?" ||
126
+ $theA == "{" || $theA == "}" || $theA == ";" ||
127
+ $theA == "\n"))
128
+ $stdout.write $theA
129
+ $stdout.write $theB
130
+ while (true)
131
+ $theA = get
132
+ if ($theA == "/")
133
+ break
134
+ elsif ($theA == "\\")
135
+ $stdout.write $theA
136
+ $theA = get
137
+ elsif ($theA <= "\n")
138
+ raise "Unterminated RegExp Literal"
139
+ end
140
+ $stdout.write $theA
141
+ end
142
+ $theB = mynext
143
+ end
144
+ end
145
+ end
146
+
147
+ # jsmin -- Copy the input to the output, deleting the characters which are
148
+ # insignificant to JavaScript. Comments will be removed. Tabs will be
149
+ # replaced with spaces. Carriage returns will be replaced with linefeeds.
150
+ # Most spaces and linefeeds will be removed.
151
+ def jsmin
152
+ $theA = "\n"
153
+ action(3)
154
+ while ($theA != EOF)
155
+ case $theA
156
+ when " "
157
+ if (isAlphanum($theB))
158
+ action(1)
159
+ else
160
+ action(2)
161
+ end
162
+ when "\n"
163
+ case ($theB)
164
+ when "{","[","(","+","-"
165
+ action(1)
166
+ when " "
167
+ action(3)
168
+ else
169
+ if (isAlphanum($theB))
170
+ action(1)
171
+ else
172
+ action(2)
173
+ end
174
+ end
175
+ else
176
+ case ($theB)
177
+ when " "
178
+ if (isAlphanum($theA))
179
+ action(1)
180
+ else
181
+ action(3)
182
+ end
183
+ when "\n"
184
+ case ($theA)
185
+ when "}","]",")","+","-","\"","\\", "'", '"'
186
+ action(1)
187
+ else
188
+ if (isAlphanum($theA))
189
+ action(1)
190
+ else
191
+ action(3)
192
+ end
193
+ end
194
+ else
195
+ action(1)
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ ARGV.each do |anArg|
202
+ $stdout.write "// #{anArg}\n"
203
+ end
204
+
205
+ jsmin
@@ -0,0 +1,31 @@
1
+
2
+ module Jzip
3
+ module Engine
4
+ module Support
5
+ module Minifier
6
+ include Notifier
7
+
8
+ extend self
9
+
10
+ def parse(source_file)
11
+ target_file = derive_target(source_file)
12
+
13
+ unless File.exists?(target_file)
14
+ notify "Minifying '#{source_file}'"
15
+ FileUtils.mkdir_p File.dirname(target_file)
16
+ `ruby #{File.join(File.dirname(__FILE__), "jsmin.rb")} <#{source_file} >#{target_file}`
17
+ end
18
+
19
+ target_file
20
+ end
21
+
22
+ private
23
+
24
+ def derive_target(source_file)
25
+ source_file.gsub source_file.match(REG_EXPS[:partial]) ? Engine.tmp_dir : Engine.root_dir, File.join(Engine.tmp_dir, "_minified_")
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end