minit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/.watchr +7 -0
- data/Gemfile.lock +22 -0
- data/README.md +13 -6
- data/lib/minit.rb +37 -33
- data/minit.gemspec +4 -1
- data/spec/minit_spec.rb +117 -0
- metadata +29 -4
data/.rvmrc
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
rvm 1.9.2@minit
|
1
|
+
rvm use 1.9.2@minit --create
|
2
2
|
|
data/.watchr
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
minit (0.0.1)
|
5
|
+
cssmin
|
6
|
+
jsmin
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
cssmin (1.0.2)
|
12
|
+
fakefs (0.3.1)
|
13
|
+
jsmin (1.0.1)
|
14
|
+
watchr (0.7)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
fakefs
|
21
|
+
minit!
|
22
|
+
watchr
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
Minit!
|
2
2
|
====================================
|
3
3
|
|
4
|
-
Minify JS and CSS in all environments except development and test for Ruby on Rails
|
4
|
+
Minify JS and CSS in all environments except development and test for Ruby on Rails apps.
|
5
|
+
(so far tested on Rails 3 but will be testing on Rails 2 in the coming days)
|
5
6
|
|
6
7
|
No frills, no configuration, opinionated packager. Use it, fork it or use something else.
|
7
8
|
|
@@ -10,11 +11,11 @@ This gem aims to fix two shortcomings in the main two asset packaging libraries,
|
|
10
11
|
1. Jammit requires Java to package CSS
|
11
12
|
2. asset_packager requires a configuration file to specify every single CSS or JS file
|
12
13
|
|
13
|
-
It
|
14
|
+
It uses CSSMin and JSMin gems from rgrove. Thanks!
|
14
15
|
|
15
16
|
It will ignore files that don't exist. It will only include files once.
|
16
17
|
|
17
|
-
It's
|
18
|
+
It's about 50 lines of code.
|
18
19
|
|
19
20
|
Usage
|
20
21
|
====================================
|
@@ -40,6 +41,7 @@ Then ensure this folder structure to get the correct load order:
|
|
40
41
|
stylesheets/
|
41
42
|
reset.css
|
42
43
|
default.css
|
44
|
+
application.css
|
43
45
|
lib/
|
44
46
|
*
|
45
47
|
*
|
@@ -47,11 +49,16 @@ Then ensure this folder structure to get the correct load order:
|
|
47
49
|
Status / Todo
|
48
50
|
====================================
|
49
51
|
|
50
|
-
First
|
52
|
+
First release
|
51
53
|
|
52
54
|
This was hacked together one afternoon as I was fed up seeing the error message that
|
53
|
-
Jammit couldn't compress because Java wasn't installed on our
|
55
|
+
Jammit couldn't compress because Java wasn't installed on our server. I wanted
|
54
56
|
to see if it was easy enough to put together a simpler solution.
|
55
57
|
|
56
|
-
|
58
|
+
Feel free to report bugs in Issues.
|
59
|
+
|
60
|
+
Development
|
61
|
+
====================================
|
62
|
+
|
63
|
+
Minit uses MiniSpec, FakeFS, Watchr, RVM.
|
57
64
|
|
data/lib/minit.rb
CHANGED
@@ -1,48 +1,52 @@
|
|
1
1
|
require 'cssmin'
|
2
2
|
require 'jsmin'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
4
|
+
class Minit
|
5
|
+
def package type, globs, create
|
6
|
+
compressor = {:javascripts => JSMin, :stylesheets => CSSMin}[type]
|
7
|
+
extension = {:javascripts => 'js', :stylesheets => 'css'}[type]
|
8
|
+
include_method = {:javascripts => 'javascript_include_tag', :stylesheets => 'stylesheet_link_tag'}[type]
|
9
|
+
raise "package type unknown. Only :javascripts or :stylesheets supported." unless compressor && extension && include_method
|
10
|
+
package_name = "packaged.#{extension}"
|
11
|
+
return send(include_method, File.join('/assets', package_name)) if compress? && !create
|
12
|
+
|
13
|
+
files = []
|
14
|
+
includes = []
|
15
|
+
asset_path = File.join(Rails.root, 'public', type.to_s, '/')
|
16
|
+
|
17
|
+
file = File.open(File.join(Rails.root, 'public', 'assets', package_name), 'w') if (compress? && create)
|
18
|
+
globs.each do |glob|
|
19
|
+
Dir.glob(File.join(asset_path, glob)).each do |path|
|
20
|
+
next if files.include?(path)
|
21
|
+
files << path
|
22
|
+
if compress? && create
|
23
|
+
file.puts compressor.minify(File.read(path))
|
24
|
+
elsif !create
|
25
|
+
includes << path.gsub(asset_path, '')
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
29
|
+
file.close if file
|
25
30
|
end
|
26
|
-
file.close if file
|
27
|
-
send(include_method, includes)
|
28
|
-
end
|
29
31
|
|
30
|
-
def compress?
|
31
|
-
|
32
|
-
end
|
32
|
+
def compress?
|
33
|
+
!%w(development test).include?(Rails.env)
|
34
|
+
end
|
33
35
|
|
34
|
-
def include_stylesheets create = false
|
35
|
-
|
36
|
-
end
|
36
|
+
def include_stylesheets create = false
|
37
|
+
package :stylesheets, %w(reset.css default.css application.css lib/**/*.css **/*.css), create
|
38
|
+
end
|
37
39
|
|
38
|
-
def include_javascripts create = false
|
39
|
-
|
40
|
+
def include_javascripts create = false
|
41
|
+
package :javascripts, %w(lib/**/*.js plugins/**/*.js **/*.js), create
|
42
|
+
end
|
40
43
|
end
|
41
44
|
|
42
|
-
|
45
|
+
minit = Minit.new
|
46
|
+
if minit.compress?
|
43
47
|
puts 'Compressing assets...'
|
44
|
-
include_stylesheets true
|
45
|
-
include_javascripts true
|
48
|
+
minit.include_stylesheets true
|
49
|
+
minit.include_javascripts true
|
46
50
|
puts 'Finished compressing assets.'
|
47
51
|
end
|
48
52
|
|
data/minit.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'base64'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'minit'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.2'
|
6
6
|
s.author = 'Phil Thompson'
|
7
7
|
s.email = Base64.decode64("cGhpbEBlbGVjdHJpY3Zpc2lvbnMuY29t\n")
|
8
8
|
s.homepage = 'http://github.com/PhilT/minit'
|
@@ -14,6 +14,9 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.add_dependency 'jsmin'
|
15
15
|
s.add_dependency 'cssmin'
|
16
16
|
|
17
|
+
s.add_development_dependency 'fakefs'
|
18
|
+
s.add_development_dependency 'watchr'
|
19
|
+
|
17
20
|
s.files = `git ls-files`.split("\n")
|
18
21
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
19
22
|
s.require_path = 'lib'
|
data/spec/minit_spec.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
$LOAD_PATH << 'lib'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class Rails
|
5
|
+
@@env = 'development'
|
6
|
+
def self.env; @@env; end
|
7
|
+
def self.env= env; @@env = env; end
|
8
|
+
def self.root; '/root'; end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Outputs
|
12
|
+
attr_accessor :output, :stylesheets, :javascripts
|
13
|
+
def reset
|
14
|
+
self.output = []
|
15
|
+
self.stylesheets = []
|
16
|
+
self.javascripts = []
|
17
|
+
end
|
18
|
+
end
|
19
|
+
$outputs = Outputs.new
|
20
|
+
|
21
|
+
def puts str
|
22
|
+
$outputs.output << str
|
23
|
+
end
|
24
|
+
|
25
|
+
def stylesheet_link_tag *args
|
26
|
+
$outputs.stylesheets + args
|
27
|
+
end
|
28
|
+
|
29
|
+
def javascript_include_tag *args
|
30
|
+
$outputs.javascripts + args
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'jsmin'
|
34
|
+
require 'cssmin'
|
35
|
+
require 'fakefs'
|
36
|
+
require 'minit'
|
37
|
+
def create path, content
|
38
|
+
path = File.join(Rails.root, 'public', path)
|
39
|
+
FileUtils.mkdir_p File.dirname(path)
|
40
|
+
File.open path, 'w' do |f|
|
41
|
+
f.puts content
|
42
|
+
end
|
43
|
+
end
|
44
|
+
FileUtils.mkdir_p File.join(Rails.root, 'public/assets')
|
45
|
+
create 'stylesheets/reset.css', 'body {padding: 0}'
|
46
|
+
create 'stylesheets/default.css', 'img {border: none}'
|
47
|
+
create 'stylesheets/some.css', 'p {margin-bottom: 20px}'
|
48
|
+
create 'stylesheets/application.css', 'body {margin: 20px auto}'
|
49
|
+
create 'stylesheets/lib/jquery.ui.css', '.some_ui {}'
|
50
|
+
create 'javascripts/lib/jquery.js', 'var jquery;'
|
51
|
+
create 'javascripts/plugins/jquery_ui/jquery.menu.js', 'var menu;'
|
52
|
+
create 'javascripts/application.js', '$(function(){});'
|
53
|
+
|
54
|
+
describe 'Minit' do
|
55
|
+
before(:each) do
|
56
|
+
$outputs.reset
|
57
|
+
@subject = Minit.new
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'initialization' do
|
61
|
+
it 'packs CSS and JS into single files' do
|
62
|
+
Rails.env = 'production'
|
63
|
+
load 'minit.rb'
|
64
|
+
$outputs.output.must_equal ['Compressing assets...', 'Finished compressing assets.']
|
65
|
+
$outputs.stylesheets.must_equal []
|
66
|
+
$outputs.javascripts.must_equal []
|
67
|
+
File.read('/root/public/assets/packaged.css').must_equal "body{padding:0;}\nimg{border:none;}\nbody{margin:20px auto;}\n.some_ui{;}\np{margin-bottom:20px;}\n"
|
68
|
+
File.read('/root/public/assets/packaged.js').must_equal "\nvar jquery;\n\nvar menu;\n\n$(function(){});\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'does not do anything when no compression required' do
|
72
|
+
Rails.env = 'development'
|
73
|
+
load 'minit.rb'
|
74
|
+
$outputs.output.must_equal []
|
75
|
+
$outputs.stylesheets.must_equal []
|
76
|
+
$outputs.javascripts.must_equal []
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'compress?' do
|
81
|
+
it 'returns false for development environment' do
|
82
|
+
Rails.env = 'development'
|
83
|
+
@subject.compress?.must_equal false
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns false for test environment' do
|
87
|
+
Rails.env = 'test'
|
88
|
+
@subject.compress?.must_equal false
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns true for production environment' do
|
92
|
+
Rails.env = 'production'
|
93
|
+
@subject.compress?.must_equal true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns true for any other environment' do
|
97
|
+
Rails.env = 'other'
|
98
|
+
@subject.compress?.must_equal true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'include_stylesheets' do
|
103
|
+
it 'defaults to not create' do
|
104
|
+
Rails.env = 'development'
|
105
|
+
@subject.include_stylesheets
|
106
|
+
$outputs.stylesheets.must_equal []
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'package' do
|
111
|
+
it 'raises when type is not javascripts or stylesheets' do
|
112
|
+
lambda { @subject.package :something, nil, nil }.must_raise RuntimeError
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: minit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Phil Thompson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-09 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -35,6 +35,28 @@ dependencies:
|
|
35
35
|
version: "0"
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: fakefs
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: watchr
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
38
60
|
description:
|
39
61
|
email: phil@electricvisions.com
|
40
62
|
executables: []
|
@@ -45,11 +67,14 @@ extra_rdoc_files: []
|
|
45
67
|
|
46
68
|
files:
|
47
69
|
- .rvmrc
|
70
|
+
- .watchr
|
48
71
|
- Gemfile
|
72
|
+
- Gemfile.lock
|
49
73
|
- README.md
|
50
74
|
- Rakefile
|
51
75
|
- lib/minit.rb
|
52
76
|
- minit.gemspec
|
77
|
+
- spec/minit_spec.rb
|
53
78
|
has_rdoc: true
|
54
79
|
homepage: http://github.com/PhilT/minit
|
55
80
|
licenses: []
|
@@ -78,5 +103,5 @@ rubygems_version: 1.5.2
|
|
78
103
|
signing_key:
|
79
104
|
specification_version: 3
|
80
105
|
summary: Minify CSS and JS without requiring Java nor specifying individual files
|
81
|
-
test_files:
|
82
|
-
|
106
|
+
test_files:
|
107
|
+
- spec/minit_spec.rb
|