jzip 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/CHANGELOG +7 -0
  2. data/README.textile +32 -8
  3. data/VERSION +1 -1
  4. data/jzip.gemspec +2 -2
  5. data/lib/jzip.rb +2 -0
  6. data/lib/jzip/actionpack/action_controller/base.rb +5 -5
  7. data/lib/jzip/assets.rb +6 -6
  8. data/lib/jzip/core/string/analyzation.rb +4 -4
  9. data/lib/jzip/engine.rb +24 -22
  10. data/lib/jzip/engine/requirement.rb +12 -12
  11. data/lib/jzip/engine/support/minifier.rb +7 -7
  12. data/lib/jzip/engine/support/notifier.rb +10 -5
  13. data/lib/jzip/engine/template.rb +28 -28
  14. data/lib/jzip/plugin.rb +2 -2
  15. data/tasks/jzip.rake +2 -2
  16. data/test/actionpack/action_controller/base_test.rb +11 -11
  17. data/test/core/string/analyzation_test.rb +5 -5
  18. data/test/javascripts/after/uncompressed/public/javascripts/backend.js +103 -103
  19. data/test/javascripts/after/uncompressed/public/javascripts/frontend.js +103 -103
  20. data/test/javascripts/after/uncompressed/tmp/jzip/public/javascripts/shared/_shared.js +102 -102
  21. data/test/javascripts/assets/jzip/code_heroes/backend.js +1 -1
  22. data/test/javascripts/assets/jzip/code_heroes/frontend.js +1 -1
  23. data/test/javascripts/assets/jzip/shared/code_heroes.js +2 -2
  24. data/test/javascripts/assets/jzip/shared/code_heroes/ajaxify.js +1 -1
  25. data/test/javascripts/assets/jzip/shared/jquery/ajax_setup.js +2 -2
  26. data/test/javascripts/assets/jzip/shared/jquery/class.js +51 -51
  27. data/test/javascripts/assets/jzip/shared/jquery/extensions/core.js +1 -1
  28. data/test/javascripts/assets/jzip/shared/jquery/extensions/deparam.js +23 -23
  29. data/test/javascripts/assets/jzip/shared/jquery/seat_holder.js +22 -22
  30. metadata +4 -4
data/CHANGELOG CHANGED
@@ -1,5 +1,12 @@
1
1
  = Jzip CHANGELOG
2
2
 
3
+ == Version 1.0.11 (November 2, 2010)
4
+
5
+ * Introduced Jzip::Engine.options[:log_level] which provides control over the Jzip logging (available options are :error, :info, :debug and :console)
6
+ * Explicitly requiring Jzip::Engine::Support::Minifier and Jzip::Plugin
7
+ * Using Rails environment flags
8
+ * Change RAILS to Rails.
9
+
3
10
  == Version 1.0.10 (September 3, 2010)
4
11
 
5
12
  * Updated source file requiring
@@ -9,26 +9,38 @@ Jzip was created due to the need of simply merging and minifying Javascript file
9
9
 
10
10
  h2. Installation
11
11
 
12
- h3. Using Jzip as gem
12
+ h3. Using Jzip as gem in Rails 3
13
13
 
14
- Install the Jzip gem:
14
+ Add Jzip in @Gemfile@ as a gem dependency:
15
15
 
16
16
  <pre>
17
- sudo gem install jzip
17
+ gem "jzip"
18
18
  </pre>
19
19
 
20
- Add Jzip in environment.rb as a gem dependency:
20
+ Run the following in your console to install with Bundler:
21
+
22
+ <pre>
23
+ bundle install
24
+ </pre>
25
+
26
+ h3. Using Jzip as gem in Rails 2
27
+
28
+ Add Jzip in @environment.rb@ as a gem dependency:
21
29
 
22
30
  <pre>
23
31
  config.gem "jzip"
24
32
  </pre>
25
33
 
26
- h3. Using Jzip as plugin
34
+ Run the following in your console:
35
+
36
+ <pre>
37
+ sudo rake gems:install
38
+ </pre>
27
39
 
28
- Install the Jzip plugin:
40
+ h3. Using Jzip as plugin in Rails 3
29
41
 
30
42
  <pre>
31
- ./script/plugin install git://github.com/archan937/jzip.git
43
+ rails plugin install git://github.com/archan937/jzip.git
32
44
  </pre>
33
45
 
34
46
  *Note*: the following will be created at installation of the plugin:
@@ -36,6 +48,12 @@ Install the Jzip plugin:
36
48
  * @assets/jzip@ - which is the default template location
37
49
  * @assets/jzip/defaults.jz@ - a Jzip template which requires the default Javascript files (Prototype, Scriptaculous and application.js)
38
50
 
51
+ h3. Using Jzip as plugin in Rails 2
52
+
53
+ <pre>
54
+ script/plugin install git://github.com/archan937/jzip.git
55
+ </pre>
56
+
39
57
  h2. Usage
40
58
 
41
59
  h3. Including generated Javascript files
@@ -73,7 +91,7 @@ Please see "http://github.com/archan937/jzip/tree/master/test/javascripts/assets
73
91
 
74
92
  h3. Registering template locations
75
93
 
76
- You probably already have guessed that the default location for Jzip templates is @RAILS_ROOT/assets/jzip@. I can imagine that you would have choosen another location. So fortunately, the Jzip engine offers you to that piece of freedom. All you have to do is put the following in your @environment.rb@ file:
94
+ You probably already have guessed that the default location for Jzip templates is @RAILS_ROOT/assets/jzip@. I can imagine that you would have choosen another location. So fortunately, the Jzip engine offers you to that piece of freedom. All you have to do is put the following in your @environment.rb@ file:
77
95
 
78
96
  <pre>
79
97
  Jzip::Engine.add_template_location < your_own_template_location(s) >
@@ -111,12 +129,14 @@ Finally, Jzip has some options that you can configure in the @environment.rb@ fi
111
129
 
112
130
  * @:minify@ - Minify the merged Javascript file using the JSMin library (default: true when in production environment)
113
131
  * @:always_update@ - Merge (and minify when specified) the Jzip templates on every page request when outdated (default: true when not in production environment)
132
+ * @:log_level@ - Which is used for logging, you can pass through the regular Rails log levels (@:error@, @:info@ and @:debug@) and even @:console@ which puts the output in your console (default: nil)
114
133
 
115
134
  You can specify a Jzip option by putting the following in your @environment.rb@ file:
116
135
 
117
136
  <pre>
118
137
  Jzip::Engine.options[:minify] = false
119
138
  Jzip::Engine.options[:always_update] = true
139
+ Jzip::Engine.options[:log_level] = :console
120
140
  </pre>
121
141
 
122
142
  h3. In the Rails console
@@ -143,6 +163,10 @@ SASS<br>
143
163
  Also, the Jzip engine makes use of the Ruby JavaScript Minifier created by Douglas Crockford<br>
144
164
  "http://www.crockford.com/javascript/jsmin.html":http://www.crockford.com/javascript/jsmin.html
145
165
 
166
+ h2. Contributors
167
+
168
+ Mark Mulder - "@bitterzoet":http://twitter.com/bitterzoet - "http://ikbenbitterzoet.com":http://ikbenbitterzoet.com
169
+
146
170
  h2. ToDo's
147
171
 
148
172
  None.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.10
1
+ 1.0.11
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jzip}
8
- s.version = "1.0.10"
8
+ s.version = "1.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Engel"]
12
- s.date = %q{2010-09-03}
12
+ s.date = %q{2010-11-02}
13
13
  s.description = %q{Jzip was created due to the need of simply merging and minifying Javascript files to reduce HTTP requests and file size of application assets. Using sprites for images and SASS for stylesheets only left javascripts not be optimized.
14
14
  AssetPackager almost suited the solution, but it hasn't got enough flexibility in configuration. So with AssetPackager (for minification) and SASS (for merging with templates) as inspiration, I came up with Jzip.}
15
15
  s.email = %q{paul.engel@holder.nl}
@@ -7,6 +7,8 @@ require "jzip/core"
7
7
  require "jzip/actionpack"
8
8
 
9
9
  require "jzip/engine/support/notifier"
10
+ require "jzip/engine/support/minifier"
10
11
  require "jzip/engine"
11
12
  require "jzip/engine/template"
12
13
  require "jzip/engine/requirement"
14
+ require "jzip/plugin"
@@ -1,8 +1,8 @@
1
1
 
2
2
  unless defined?(Jzip::CONTROLLER_HOOKED)
3
-
3
+
4
4
  module ActionController
5
-
5
+
6
6
  class Base
7
7
  alias_method :original_process, :process
8
8
  def process(*args)
@@ -10,9 +10,9 @@ unless defined?(Jzip::CONTROLLER_HOOKED)
10
10
  original_process(*args)
11
11
  end
12
12
  end
13
-
13
+
14
14
  end
15
-
15
+
16
16
  Jzip::CONTROLLER_HOOKED = true
17
-
17
+
18
18
  end
@@ -2,27 +2,27 @@
2
2
  module Jzip
3
3
  module Assets
4
4
  extend self
5
-
5
+
6
6
  def install_defaults
7
7
  puts "Installing defaults..."
8
8
 
9
9
  create_default_template_location
10
10
  File.open(File.join(default_template_location, "defaults.jz"), "w") do |f|
11
- f.write("\n//= require /defaults\n")
11
+ f.write("\n//= require /defaults\n")
12
12
  end
13
13
 
14
14
  puts "Done"
15
15
  end
16
-
16
+
17
17
  private
18
-
18
+
19
19
  def create_default_template_location
20
20
  FileUtils.mkdir_p default_template_location
21
21
  end
22
-
22
+
23
23
  def default_template_location
24
24
  File.join Jzip::Engine.root_dir, "assets", "jzip"
25
25
  end
26
-
26
+
27
27
  end
28
28
  end
@@ -3,19 +3,19 @@ module Jzip
3
3
  module Core
4
4
  module String
5
5
  module Analyzation
6
-
6
+
7
7
  def jzip_require_statement?
8
8
  !!self.strip.match(Jzip::Engine::REG_EXPS[:require_statement])
9
9
  end
10
-
10
+
11
11
  def required_jzip_source(exclude_exclamation_mark = true)
12
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
13
  end
14
-
14
+
15
15
  def overrule_jzip_minification?
16
16
  !!required_jzip_source(false).match(/^!/) if self.jzip_require_statement?
17
17
  end
18
-
18
+
19
19
  end
20
20
  end
21
21
  end
@@ -2,58 +2,60 @@
2
2
  module Jzip
3
3
  module Engine
4
4
  include Support::Notifier
5
-
5
+
6
6
  extend self
7
-
7
+
8
8
  PREDEFINED_SETS = {"defaults" => %w(prototype effects dragdrop controls application)}
9
9
  REG_EXPS = {:require_statement => /^\/\/\=\s*require\s*/, :partial => /^_/, :default_javascripts => /^\//}
10
-
10
+
11
11
  @options = {
12
- :minify => RAILS_ENV == "production",
13
- :always_update => RAILS_ENV != "production"
12
+ :minify => Rails.env.production?,
13
+ :always_update => !Rails.env.production?,
14
+ :log_level => nil
14
15
  }
16
+
15
17
  attr_reader :root_dir, :options
16
-
18
+
17
19
  def root_dir=(value)
18
20
  @template_locations.clear
19
21
  @initial_compile = true
20
22
  @root_dir = value
21
23
  end
22
-
24
+
23
25
  def options=(value)
24
26
  @options.merge! value
25
27
  end
26
-
28
+
27
29
  def add_template_location(location)
28
30
  @template_locations << location
29
31
  end
30
-
32
+
31
33
  def compile_javascript_files
32
34
  return unless @options[:always_update] or @initial_compile
33
-
35
+
34
36
  init if @initial_compile
35
37
  parse_templates
36
38
  @initial_compile = false
37
39
  end
38
-
40
+
39
41
  def init
40
42
  @template_locations.unshift File.join(root_dir, "assets", "jzip")
41
43
  FileUtils.mkdir_p tmp_dir
42
44
  end
43
-
45
+
44
46
  def root_dir
45
- @root_dir || RAILS_ROOT
47
+ @root_dir || Rails.root
46
48
  end
47
-
49
+
48
50
  def tmp_dir
49
51
  File.join(root_dir, "tmp", "jzip")
50
52
  end
51
-
53
+
52
54
  private
53
-
55
+
54
56
  @template_locations = []
55
57
  @initial_compile = true
56
-
58
+
57
59
  def template_refs
58
60
  Hash[
59
61
  *@template_locations.collect do |location|
@@ -64,19 +66,19 @@ module Jzip
64
66
  end.flatten
65
67
  ]
66
68
  end
67
-
69
+
68
70
  def parse_templates
69
71
  notify "Compiling templates..."
70
-
72
+
71
73
  Template.clear_instances
72
74
  template_refs.each do |source, target|
73
75
  Dir.glob(File.join(source, "**", "[^_]*.jz")).each do |template|
74
76
  Template.build(template, source, target).parse
75
77
  end
76
78
  end
77
-
79
+
78
80
  notify "Done"
79
81
  end
80
-
81
- end
82
+
83
+ end
82
84
  end
@@ -1,46 +1,46 @@
1
1
 
2
2
  module Jzip
3
3
  module Engine
4
-
4
+
5
5
  Requirement = Struct.new(:file, :source, :target, :overrule_minification) do
6
-
6
+
7
7
  include Support::Notifier
8
-
8
+
9
9
  def newer?(mtime)
10
10
  notify "Newer '#{target_file}'" if result = mtime < File.mtime(target_file)
11
11
  result
12
12
  end
13
-
13
+
14
14
  def parse
15
15
  @code ||= begin
16
16
  source_file = plain_javascript? ? self.file : (template.parse; template.target_file)
17
17
  File.read(minify? ? Support::Minifier.parse(source_file) : source_file)
18
18
  end
19
19
  end
20
-
20
+
21
21
  def code
22
22
  parse
23
23
  end
24
-
24
+
25
25
  private
26
-
26
+
27
27
  def plain_javascript?
28
28
  File.extname(self.file) == ".js"
29
29
  end
30
-
30
+
31
31
  def minify?
32
32
  Jzip::Engine::options[:minify] && !@overrule_minification
33
33
  end
34
-
34
+
35
35
  def template
36
36
  @template ||= Template.build(self.file, self.source, self.target) unless plain_javascript?
37
37
  end
38
-
38
+
39
39
  def target_file
40
40
  plain_javascript? ? self.file : template.target_file
41
41
  end
42
-
42
+
43
43
  end
44
-
44
+
45
45
  end
46
46
  end
@@ -4,27 +4,27 @@ module Jzip
4
4
  module Support
5
5
  module Minifier
6
6
  include Notifier
7
-
7
+
8
8
  extend self
9
-
9
+
10
10
  def parse(source_file)
11
11
  target_file = derive_target(source_file)
12
-
12
+
13
13
  unless File.exists?(target_file)
14
14
  notify "Minifying '#{source_file}'"
15
15
  FileUtils.mkdir_p File.dirname(target_file)
16
16
  `ruby #{File.join(File.dirname(__FILE__), "jsmin.rb")} <#{source_file} >#{target_file}`
17
17
  end
18
-
18
+
19
19
  target_file
20
20
  end
21
-
21
+
22
22
  private
23
-
23
+
24
24
  def derive_target(source_file)
25
25
  source_file.gsub source_file.match(REG_EXPS[:partial]) ? Engine.tmp_dir : Engine.root_dir, File.join(Engine.tmp_dir, "_minified_")
26
26
  end
27
-
27
+
28
28
  end
29
29
  end
30
30
  end
@@ -3,18 +3,23 @@ module Jzip
3
3
  module Engine
4
4
  module Support
5
5
  module Notifier
6
-
6
+
7
7
  def notify(message)
8
8
  string = wrap(message)
9
- RAILS_ENV == "test" ? puts(string) : RAILS_DEFAULT_LOGGER.info(string)
9
+ case Jzip::Engine.options[:log_level]
10
+ when :console
11
+ puts string
12
+ when :error, :info, :debug
13
+ Rails.logger.send Jzip::Engine.options[:log_level], string
14
+ end
10
15
  end
11
-
16
+
12
17
  private
13
-
18
+
14
19
  def wrap(message)
15
20
  "== JZIP: #{message}"
16
21
  end
17
-
22
+
18
23
  end
19
24
  end
20
25
  end
@@ -1,22 +1,22 @@
1
1
 
2
2
  module Jzip
3
3
  module Engine
4
-
4
+
5
5
  Template = Struct.new(:template, :source, :target) do
6
-
6
+
7
7
  include Support::Notifier
8
-
8
+
9
9
  @@instances = {}
10
10
  attr_reader :target_file
11
-
11
+
12
12
  def self.clear_instances
13
13
  @@instances.clear
14
14
  end
15
-
15
+
16
16
  def self.build(*args)
17
17
  @@instances[args.first] ||= self.new(*args)
18
18
  end
19
-
19
+
20
20
  def initialize(*args)
21
21
  super
22
22
 
@@ -26,46 +26,46 @@ module Jzip
26
26
  @target_dir.gsub! Engine.root_dir, Engine.tmp_dir
27
27
  end
28
28
  @target_file = File.join @target_dir, @file_name
29
-
29
+
30
30
  scan_template
31
31
  end
32
-
32
+
33
33
  def parse
34
34
  unless requires_parsing?
35
35
  notify "Skipping '#{self.template}'"
36
36
  else
37
37
  notify "Parsing '#{self.template}'"
38
-
38
+
39
39
  @code = @segments.collect do |segment|
40
40
  segment.is_a?(Requirement) ?
41
- segment.code :
41
+ segment.code :
42
42
  segment.join("")
43
43
  end.
44
44
  join("\n\n").
45
45
  gsub(/^\s*$\n{2,}/, "\n").
46
46
  strip.insert(0, "\n").insert(-1, "\n")
47
-
47
+
48
48
  write_file
49
49
  end
50
50
  @code ||= File.read(@target_file)
51
51
  end
52
-
52
+
53
53
  def code
54
54
  parse
55
55
  end
56
-
56
+
57
57
  def outdated?
58
58
  return true if missing?
59
59
  notify "Outdated '#{self.template}'" if result = File.mtime(@target_file) < File.mtime(self.template)
60
60
  result
61
61
  end
62
-
62
+
63
63
  def partial?
64
64
  !!@file_name.match(REG_EXPS[:partial])
65
65
  end
66
-
66
+
67
67
  private
68
-
68
+
69
69
  def scan_template
70
70
  @requirements = []
71
71
  @segments = File.readlines(self.template).inject([]) do |segments, line|
@@ -81,11 +81,11 @@ module Jzip
81
81
  segments
82
82
  end
83
83
  end
84
-
84
+
85
85
  def derive_required_source(required_source)
86
86
  basename = File.basename required_source
87
87
  dirname = File.dirname required_source
88
-
88
+
89
89
  source_dirname = required_source.match(REG_EXPS[:default_javascripts]) ?
90
90
  File.join(Engine.root_dir, "public", "javascripts") :
91
91
  File.dirname(self.template)
@@ -96,46 +96,46 @@ module Jzip
96
96
  [required_source]
97
97
  end
98
98
  end
99
-
99
+
100
100
  sources.collect do |x|
101
101
  source = File.join(source_dirname, x)
102
102
  dir = File.dirname source
103
103
  base = File.basename source
104
-
104
+
105
105
  [File.join(dir, "_#{base}.jz"),
106
106
  File.join(dir, "#{base}.jz"),
107
107
  File.join(dir, "#{base}.js")].detect{|f| File.exists?(f)}
108
108
  end.compact
109
109
  end
110
-
110
+
111
111
  def write_file
112
112
  notify "Writing '#{@target_file}'"
113
-
113
+
114
114
  FileUtils.mkdir_p @target_dir
115
115
  File.open(@target_file, "w") do |f|
116
116
  f.write @code
117
117
  end
118
118
  end
119
-
119
+
120
120
  def requires_parsing?
121
121
  return true if outdated?
122
122
 
123
123
  modification_time = File.mtime(@target_file)
124
-
124
+
125
125
  @requirements.each{|x| x.parse}
126
126
  @requirements.any?{|x| x.newer? modification_time}
127
127
  end
128
-
128
+
129
129
  def missing?
130
130
  notify "Missing '#{@target_file}'" if result = !target_file?
131
131
  result
132
132
  end
133
-
133
+
134
134
  def target_file?
135
135
  File.exists? @target_file
136
136
  end
137
-
137
+
138
138
  end
139
-
139
+
140
140
  end
141
141
  end