rake-minify 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require 'test_notifier/runner/autotest'
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create @rake-minify
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Matteo Collina
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = rake-minify
2
+
3
+ Rake Minify is an exetremely simple solution for minifying javascript files using a rake task.
4
+
5
+ == Installation
6
+
7
+ First, install the gem:
8
+
9
+ gem install rake-minify
10
+
11
+ Or if your are using Bundler:
12
+
13
+ echo "gem 'rake-minify'" >> Gemfile
14
+ bundle install
15
+
16
+ == Minifying a single JavaScript file
17
+
18
+ Open your Rakefile and add:
19
+
20
+ Rake::Minify.new(:minify_single) do
21
+ dir("path/to/your/dir") do # we specify only the source directory
22
+ add("output.js", "source.js") # the output file name is full path
23
+ end
24
+ end
25
+
26
+ == Minify multiple JavaScript files
27
+
28
+ Open your Rakefile and add:
29
+
30
+ Rake::Minify.new(:minify_multiple) do
31
+ dir("path/to/your/dir") do # we specify only the source directory
32
+ add("output-multi.js", "first.js") # the output file name is full path
33
+ add("output-multi.js", "second.js")
34
+ end
35
+ end
36
+
37
+ == Combine only multiple JavaScript files
38
+
39
+ Open your Rakefile and add:
40
+
41
+ Rake::Minify.new(:minify_and_combine) do
42
+ dir("path/to/your/dir") do # we specify only the source directory
43
+ add("output-first-second.js", "first.js", :minify => false) # this file is not minified
44
+ add("output-first-second.js", "second.js") # this file is minified
45
+ end
46
+ end
47
+
48
+
49
+ == Contributing to rake-minify
50
+
51
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
52
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
53
+ * Fork the project
54
+ * Start a feature/bugfix branch
55
+ * Commit and push until you are happy with your contribution
56
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
57
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
58
+
59
+ == Copyright
60
+
61
+ Copyright (c) 2011 Matteo Collina. See LICENSE.txt for
62
+ further details.
63
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
7
+ gem.name = "rake-minify"
8
+ gem.homepage = "http://github.com/mcollina/rake-minify"
9
+ gem.license = "MIT"
10
+ gem.summary = %Q{A rake task to minify javascripts}
11
+ gem.description = %Q{A rake task to minify javascripts}
12
+ gem.email = "matteo.collina@gmail.com"
13
+ gem.authors = ["Matteo Collina"]
14
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
15
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
16
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
17
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
18
+ gem.add_dependency "jsmin", "~> 1.0.1"
19
+ gem.add_development_dependency "rspec", "~> 2.5.0"
20
+ gem.add_development_dependency "cucumber", ">= 0"
21
+ gem.add_development_dependency "jeweler", "~> 1.5.2"
22
+ gem.add_development_dependency 'test_notifier', '~> 0.3.6'
23
+ gem.add_development_dependency 'autotest', '~> 4.4'
24
+ gem.add_development_dependency "rcov", ">= 0"
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ require 'cucumber/rake/task'
40
+ Cucumber::Rake::Task.new(:features)
41
+
42
+ task :default => [:spec, :features]
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "rake-minify #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1 @@
1
+ alert("hello a");
@@ -0,0 +1 @@
1
+ alert("hello b");
@@ -0,0 +1,6 @@
1
+
2
+ alert( "hello a" );
3
+
4
+
5
+
6
+
@@ -0,0 +1,2 @@
1
+
2
+ alert( "hello b" );
@@ -0,0 +1,48 @@
1
+ Feature: Minify Javascripts
2
+ In order to build awesome javascript applications
3
+ A ruby programmer
4
+ Wants to minify its javascripts using rake
5
+
6
+ Scenario: Minify single javascript
7
+ Given we want to minify the js file "a.js" into "a.min.js"
8
+ When I run rake minify
9
+ Then "a.min.js" should be minified
10
+
11
+ Scenario: Combine multiple javascripts into a single file
12
+ Given we want to combine the js file "a.js" into "app.js"
13
+ And we want to combine the js file "b.js" into "app.js"
14
+ When I run rake minify
15
+ Then "app.js" should include "a.js" and "b.js"
16
+
17
+ Scenario: Minify multiple javascripts into a single file
18
+ Given we want to minify the js file "a.js" into "app.min.js"
19
+ And we want to minify the js file "b.js" into "app.min.js"
20
+ When I run rake minify
21
+ Then "app.min.js" should include "a.min.js" and "b.min.js"
22
+
23
+ Scenario: Minify multiple javascripts into multiple files
24
+ Given we want to minify the js file "a.js" into "app.min.js"
25
+ And we want to minify the js file "b.js" into "app.min.js"
26
+ And we want to minify the js file "a.js" into "a.min.js"
27
+ When I run rake minify
28
+ Then "app.min.js" should include "a.min.js" and "b.min.js"
29
+ And "a.min.js" should be minified
30
+
31
+ Scenario: Combine and minify only one js file
32
+ Given we want to combine the js file "a.js" into "app.js"
33
+ And we want to minify the js file "b.js" into "app.js"
34
+ When I run rake minify
35
+ Then "app.js" should include "a.js" and "b.min.js"
36
+
37
+ Scenario: Minify single javascript with basedir
38
+ Given the basedir "public"
39
+ And we want to minify the js file "a.js" into "a.min.js"
40
+ When I run rake minify
41
+ Then "a.min.js" should be minified
42
+
43
+ Scenario: Minify multiple javascripts with basedir
44
+ Given the basedir "public"
45
+ And we want to minify the js file "a.js" into "app.min.js"
46
+ And we want to minify the js file "b.js" into "app.min.js"
47
+ When I run rake minify
48
+ Then "app.min.js" should include "a.min.js" and "b.min.js"
@@ -0,0 +1,18 @@
1
+ Feature: Rake Interface
2
+ In order to build a well structured Rakefile
3
+ A ruby programmer
4
+ Wants to customize the minify task
5
+
6
+ Background:
7
+ Given we want to minify the js file "a.js" into "a.min.js"
8
+
9
+ Scenario: Custom name for the task
10
+ Given I have configured rake to minify at the ":my_minify" command
11
+ When I run rake "my_minify"
12
+ Then "a.min.js" should be minified
13
+
14
+ Scenario: Prerequisites for the task
15
+ Given I have a ":pre" rake task
16
+ And I have configured rake to minify at the ":my_minify => :pre" command
17
+ When I run rake "my_minify"
18
+ Then "a.min.js" should be minified
@@ -0,0 +1,58 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+ require 'rake'
4
+
5
+ Given /^we want to minify the js file "([^"]*)" into "([^"]*)"$/ do |file, output|
6
+ add_to_groups(output, true, file)
7
+ end
8
+
9
+ When /^I run rake minify$/ do
10
+ run_task
11
+ end
12
+
13
+ Then /^"([^"]*)" should be minified$/ do |file|
14
+ open(File.join(@dir, basedir, file)) do |result|
15
+ open(File.join(File.dirname(__FILE__), "..", "js-expected", file)) do |expected|
16
+ (result.read + "\n").should == expected.read
17
+ end
18
+ end
19
+ end
20
+
21
+ Given /^we want to combine the js file "([^"]*)" into "([^"]*)"$/ do |file, output|
22
+ add_to_groups(output, false, file)
23
+ end
24
+
25
+ Then /^"([^"]*)" should include "([^"]*)" and "([^"]*)"$/ do |result, source1, source2|
26
+ sources = [source1, source2].map do |s|
27
+ file = File.join(File.dirname(__FILE__), "..", "js-expected", s)
28
+ unless File.exists? file
29
+ file = File.join(File.dirname(__FILE__), "..", "js-sources", s)
30
+ end
31
+
32
+ open(file) do |e|
33
+ e.read
34
+ end
35
+ end
36
+
37
+ open(File.join(@dir, basedir, result)) do |result|
38
+ content = result.read
39
+ sources.each { |s| content.should include(s.gsub(/\n$/,'')) } # this is unfortunate :/
40
+ end
41
+ end
42
+
43
+ Given /^the basedir "([^"]*)"$/ do |dir|
44
+ basedir(dir)
45
+ end
46
+
47
+ Given /^I have configured rake to minify at the "([^"]*)" command$/ do |name|
48
+ @name_for_generation = name
49
+ end
50
+
51
+ When /^I run rake "([^"]*)"$/ do |task_name|
52
+ run_task task_name
53
+ end
54
+
55
+ Given /^I have a "([^"]*)" rake task$/ do |arg1|
56
+ pre << "task #{arg1} "
57
+ end
58
+
@@ -0,0 +1,5 @@
1
+
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
3
+ require 'rake-minify'
4
+
5
+ require 'rspec/expectations'
@@ -0,0 +1,81 @@
1
+ require 'erb'
2
+
3
+ class Group
4
+ attr_reader :sources
5
+ attr_reader :output
6
+
7
+ def initialize(output)
8
+ @output = output
9
+ @sources = []
10
+ end
11
+
12
+ def add(source, minify)
13
+ @sources << GroupElement.new(source, minify)
14
+ end
15
+ end
16
+
17
+ GroupElement = Struct.new(:source, :minify)
18
+
19
+ def groups
20
+ @groups ||= Hash.new do |h, k|
21
+ h[k] = Group.new(k)
22
+ end
23
+ end
24
+
25
+ def add_to_groups(output, minify, file)
26
+ groups[output].add(file, minify)
27
+ end
28
+
29
+ def generate_rakefile
30
+ template = <<-EOF
31
+ <%= pre.join("\n") %>
32
+
33
+ Rake::Minify.new(<%= @name_for_generation %>) do
34
+ <% if basedir.size > 0 %>
35
+ dir(File.join(File.dirname(__FILE__), <%= basedir.inspect %>)) do
36
+ <% end %>
37
+ <% groups.values.each do |group| %>
38
+ <% if group.sources.size == 1 %>
39
+ add(<%= group.output.inspect %>, <%= group.sources.first.source.inspect %>)
40
+ <% else %>
41
+ group(<%= group.output.inspect %>) do |group|
42
+ <% group.sources.each do |element| %>
43
+ add(<%= element.source.inspect %>, :minify => <%= element.minify %>)
44
+ <% end %>
45
+ end
46
+ <% end %>
47
+ <% end %>
48
+ <% if basedir.size > 0 %>
49
+ end
50
+ <% end %>
51
+ end
52
+ EOF
53
+ erb = ERB.new(template)
54
+ erb.result(binding)
55
+ end
56
+
57
+ def basedir(dir="")
58
+ @basedir ||= dir
59
+ end
60
+
61
+ def run_task(task_name="minify")
62
+ @dir = Dir.mktmpdir
63
+ FileUtils.mkdir File.join(@dir, basedir) if basedir.size > 0
64
+ Dir.glob(File.join(File.dirname(__FILE__), "..", "js-sources", "*")) do |file|
65
+ FileUtils.cp(file, File.join(@dir, basedir))
66
+ end
67
+ rakefile = File.join(@dir, "Rakefile")
68
+ open(rakefile, "w") { |io| io << generate_rakefile }
69
+
70
+ application = Rake::Application.new
71
+ Rake.application = application
72
+ application.add_import(rakefile)
73
+ application.load_imports
74
+ FileUtils.cd(@dir) do
75
+ application[task_name].invoke
76
+ end
77
+ end
78
+
79
+ def pre
80
+ @pre ||= []
81
+ end
@@ -0,0 +1,21 @@
1
+
2
+ class Rake::Minify
3
+ class Group
4
+ attr_reader :parent
5
+
6
+ def initialize(parent, &block)
7
+ @sources = []
8
+ @parent = parent
9
+
10
+ instance_eval &block if block
11
+ end
12
+
13
+ def add(source, opts={:minify => true})
14
+ @sources << Source.new(parent.build_path(source), opts[:minify])
15
+ end
16
+
17
+ def build
18
+ @sources.map { |s| s.build }.join("\n")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+
2
+ class Rake::Minify::Source
3
+ attr_reader :source, :minify
4
+
5
+ def initialize(source, minify)
6
+ @source = source
7
+ @minify = minify
8
+ end
9
+
10
+ def build
11
+ Kernel.open(source) do |input|
12
+ minify && JSMin.minify(input.read).strip || input.read
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'jsmin'
4
+
5
+ class Rake::Minify < Rake::TaskLib
6
+
7
+ autoload :Source, "rake/minify/source"
8
+ autoload :Group, "rake/minify/group"
9
+
10
+ def initialize(name=:minify, &block)
11
+ @sources = {}
12
+ @dir = nil
13
+ @config = block
14
+
15
+ desc "Minifies the specified javascripts" unless Rake.application.last_comment
16
+ task name do
17
+ invoke
18
+ end
19
+ end
20
+
21
+ def add(output, source, opts = { :minify => true })
22
+ @sources[build_path(output)] = Source.new(build_path(source), opts[:minify])
23
+ end
24
+
25
+ def group(output, &block)
26
+ @sources[build_path(output)] = Group.new(self, &block)
27
+ end
28
+
29
+ def dir(dir, &block)
30
+ @dir = dir
31
+ instance_eval &block # to be configured like the pros
32
+ @dir = nil
33
+ end
34
+
35
+ def invoke
36
+ instance_eval &@config # to be configured like the pros
37
+
38
+ @sources.each do |dest, source|
39
+ Kernel.open(dest, "w") do |output|
40
+ output << source.build
41
+ end
42
+ end
43
+ end
44
+
45
+ def build_path(file)
46
+ @dir.nil? && file || File.join(@dir, file)
47
+ end
48
+ end
@@ -0,0 +1,2 @@
1
+
2
+ require 'rake/minify'
@@ -0,0 +1,89 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rake-minify}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matteo Collina"]
12
+ s.date = %q{2011-04-06}
13
+ s.description = %q{A rake task to minify javascripts}
14
+ s.email = %q{matteo.collina@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".autotest",
21
+ ".document",
22
+ ".rspec",
23
+ ".rvmrc",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "features/js-expected/a.min.js",
29
+ "features/js-expected/b.min.js",
30
+ "features/js-sources/a.js",
31
+ "features/js-sources/b.js",
32
+ "features/minify.feature",
33
+ "features/rake-interface.feature",
34
+ "features/step_definitions/rake-minify_steps.rb",
35
+ "features/support/env.rb",
36
+ "features/support/generate_rakefiles.rb",
37
+ "lib/rake-minify.rb",
38
+ "lib/rake/minify.rb",
39
+ "lib/rake/minify/group.rb",
40
+ "lib/rake/minify/source.rb",
41
+ "rake-minify.gemspec",
42
+ "spec/rake/minify/group_spec.rb",
43
+ "spec/rake/minify/source_spec.rb",
44
+ "spec/rake/minify_spec.rb",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+ s.homepage = %q{http://github.com/mcollina/rake-minify}
48
+ s.licenses = ["MIT"]
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.5.3}
51
+ s.summary = %q{A rake task to minify javascripts}
52
+ s.test_files = [
53
+ "spec/rake/minify/group_spec.rb",
54
+ "spec/rake/minify/source_spec.rb",
55
+ "spec/rake/minify_spec.rb",
56
+ "spec/spec_helper.rb"
57
+ ]
58
+
59
+ if s.respond_to? :specification_version then
60
+ s.specification_version = 3
61
+
62
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
+ s.add_runtime_dependency(%q<jsmin>, ["~> 1.0.1"])
64
+ s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
65
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
66
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
67
+ s.add_development_dependency(%q<test_notifier>, ["~> 0.3.6"])
68
+ s.add_development_dependency(%q<autotest>, ["~> 4.4"])
69
+ s.add_development_dependency(%q<rcov>, [">= 0"])
70
+ else
71
+ s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
72
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
73
+ s.add_dependency(%q<cucumber>, [">= 0"])
74
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
75
+ s.add_dependency(%q<test_notifier>, ["~> 0.3.6"])
76
+ s.add_dependency(%q<autotest>, ["~> 4.4"])
77
+ s.add_dependency(%q<rcov>, [">= 0"])
78
+ end
79
+ else
80
+ s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
81
+ s.add_dependency(%q<rspec>, ["~> 2.5.0"])
82
+ s.add_dependency(%q<cucumber>, [">= 0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
84
+ s.add_dependency(%q<test_notifier>, ["~> 0.3.6"])
85
+ s.add_dependency(%q<autotest>, ["~> 4.4"])
86
+ s.add_dependency(%q<rcov>, [">= 0"])
87
+ end
88
+ end
89
+
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper.rb"
2
+ require 'stringio'
3
+
4
+ class Rake::Minify
5
+ describe Group do
6
+
7
+ let(:parent) { double("parent") }
8
+ subject { Group.new(parent) }
9
+
10
+ before(:each) do
11
+ parent.stub!(:build_path).and_return { |arg| arg }
12
+ end
13
+
14
+ def build_source(source_name, minify, stubs = {})
15
+ source = double("source", stubs)
16
+ Source.stub!(:new).with(source_name, minify).and_return(source)
17
+ source
18
+ end
19
+
20
+ it "should have an add method that accepts a string" do
21
+ lambda { subject.add("something") }.should_not raise_error
22
+ end
23
+
24
+ it "should have an add method that accepts a string and an hash" do
25
+ lambda { subject.add("something", :minify => false) }.should_not raise_error
26
+ end
27
+
28
+ it "should create a new source with the passed args when calling add" do
29
+ Source.should_receive(:new).with("something", false)
30
+ subject.add("something", :minify => false)
31
+ end
32
+
33
+ it "should create a new source with the passed single arg when calling add" do
34
+ Source.should_receive(:new).with("another", true)
35
+ subject.add("another")
36
+ end
37
+
38
+ it "should concatenate all the sources when calling build" do
39
+ s1 = build_source("a", false, :build => "aaaa");
40
+ s2 = build_source("b", true, :build => "bbbb");
41
+
42
+ subject.add("a", :minify => false)
43
+ subject.add("b")
44
+ subject.build.should == "aaaa\nbbbb"
45
+ end
46
+
47
+ it "should accept add inside the block passed to new" do
48
+ s1 = build_source("a", false, :build => "aaaa");
49
+
50
+ subject = Group.new(parent) do
51
+ add("a", :minify => false)
52
+ end
53
+
54
+ subject.build.should == "aaaa"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper.rb"
2
+ require 'stringio'
3
+
4
+ class Rake::Minify
5
+ describe Source do
6
+ context "configured to open 'a_source' and minify it" do
7
+ subject { Source.new("a_source", true) }
8
+
9
+ it "should open and minify the file" do
10
+ input = StringIO.new(' var a = "b" ;')
11
+ Kernel.stub!(:open).with("a_source").and_yield(input)
12
+ subject.build.should == "var a=\"b\";"
13
+ end
14
+ end
15
+
16
+ context "configured to open 'another_source' and to not minify it" do
17
+ subject { Source.new("another_source", false) }
18
+
19
+ it "should open and clone the file" do
20
+ input = StringIO.new(' var a = "b" ;')
21
+ Kernel.stub!(:open).with("another_source").and_yield(input)
22
+ subject.build.should == ' var a = "b" ;'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,102 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+ require 'stringio'
3
+
4
+ describe Rake::Minify do
5
+
6
+ def stub_open(source, content, mode=nil)
7
+ io = StringIO.new(content)
8
+ args = [source]
9
+ args << mode if mode
10
+ Kernel.stub!(:open).with(*args).and_yield(io)
11
+ io
12
+ end
13
+
14
+ def do_invoke
15
+ subject.invoke
16
+ end
17
+
18
+ context "configured to minify a single file" do
19
+ subject do
20
+ Rake::Minify.new do
21
+ add("output", "source")
22
+ end
23
+ end
24
+
25
+ before :each do
26
+ stub_open("source",' var a = "b" ;')
27
+ @output = stub_open("output","", "w")
28
+ end
29
+
30
+ it "should minify the input file when invoked" do
31
+ do_invoke
32
+ @output.string.should == "var a=\"b\";"
33
+ end
34
+ end
35
+
36
+ context "configured not to minify a single file" do
37
+ subject do
38
+ Rake::Minify.new do
39
+ add("output", "source", :minify => false)
40
+ end
41
+ end
42
+
43
+ before :each do
44
+ stub_open("source",' var a = "b" ;')
45
+ @output = stub_open("output","", "w")
46
+ end
47
+
48
+ it "should not minify the input file when invoked" do
49
+ do_invoke
50
+ @output.string.should == ' var a = "b" ;'
51
+ end
52
+ end
53
+
54
+ context "configured to minify a group of files" do
55
+ subject do
56
+ Rake::Minify.new do
57
+ group("output") do
58
+ add("a")
59
+ add("b")
60
+ end
61
+ end
62
+ end
63
+
64
+ before :each do
65
+ stub_open("a",' var a = "hello" ;')
66
+ stub_open("b",' var b = "hello2" ;')
67
+ @output = stub_open("output","", "w")
68
+ end
69
+
70
+ it "should minify and concatenate the inputs" do
71
+ do_invoke
72
+ @output.string.should == "var a=\"hello\";\nvar b=\"hello2\";"
73
+ end
74
+ end
75
+
76
+ context "configured to minify a file in a directory" do
77
+ subject do
78
+ Rake::Minify.new do
79
+ dir("the_dir") do
80
+ add("output", "source")
81
+ end
82
+ end
83
+ end
84
+
85
+ before :each do
86
+ stub_open("the_dir/source",' var a = "b" ;')
87
+ @output = stub_open("the_dir/output","", "w")
88
+ end
89
+
90
+ it "should minify the input file when invoked" do
91
+ do_invoke
92
+ @output.string.should == "var a=\"b\";"
93
+ end
94
+ end
95
+
96
+ it "should accepts arguments" do
97
+ Rake::Task.should_receive(:define_task).with(:a_task)
98
+ Rake::Minify.new(:a_task) do
99
+ add("output", "source")
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rake-minify'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-minify
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Matteo Collina
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-06 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: jsmin
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 21
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 1
34
+ version: 1.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 27
46
+ segments:
47
+ - 2
48
+ - 5
49
+ - 0
50
+ version: 2.5.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: cucumber
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: jeweler
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 7
76
+ segments:
77
+ - 1
78
+ - 5
79
+ - 2
80
+ version: 1.5.2
81
+ type: :development
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: test_notifier
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 31
92
+ segments:
93
+ - 0
94
+ - 3
95
+ - 6
96
+ version: 0.3.6
97
+ type: :development
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: autotest
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ hash: 19
108
+ segments:
109
+ - 4
110
+ - 4
111
+ version: "4.4"
112
+ type: :development
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: rcov
116
+ prerelease: false
117
+ requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ type: :development
127
+ version_requirements: *id007
128
+ description: A rake task to minify javascripts
129
+ email: matteo.collina@gmail.com
130
+ executables: []
131
+
132
+ extensions: []
133
+
134
+ extra_rdoc_files:
135
+ - LICENSE.txt
136
+ - README.rdoc
137
+ files:
138
+ - .autotest
139
+ - .document
140
+ - .rspec
141
+ - .rvmrc
142
+ - LICENSE.txt
143
+ - README.rdoc
144
+ - Rakefile
145
+ - VERSION
146
+ - features/js-expected/a.min.js
147
+ - features/js-expected/b.min.js
148
+ - features/js-sources/a.js
149
+ - features/js-sources/b.js
150
+ - features/minify.feature
151
+ - features/rake-interface.feature
152
+ - features/step_definitions/rake-minify_steps.rb
153
+ - features/support/env.rb
154
+ - features/support/generate_rakefiles.rb
155
+ - lib/rake-minify.rb
156
+ - lib/rake/minify.rb
157
+ - lib/rake/minify/group.rb
158
+ - lib/rake/minify/source.rb
159
+ - rake-minify.gemspec
160
+ - spec/rake/minify/group_spec.rb
161
+ - spec/rake/minify/source_spec.rb
162
+ - spec/rake/minify_spec.rb
163
+ - spec/spec_helper.rb
164
+ has_rdoc: true
165
+ homepage: http://github.com/mcollina/rake-minify
166
+ licenses:
167
+ - MIT
168
+ post_install_message:
169
+ rdoc_options: []
170
+
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ hash: 3
179
+ segments:
180
+ - 0
181
+ version: "0"
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ hash: 3
188
+ segments:
189
+ - 0
190
+ version: "0"
191
+ requirements: []
192
+
193
+ rubyforge_project:
194
+ rubygems_version: 1.5.3
195
+ signing_key:
196
+ specification_version: 3
197
+ summary: A rake task to minify javascripts
198
+ test_files:
199
+ - spec/rake/minify/group_spec.rb
200
+ - spec/rake/minify/source_spec.rb
201
+ - spec/rake/minify_spec.rb
202
+ - spec/spec_helper.rb