minit 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. data/.rvmrc +2 -0
  2. data/Gemfile +3 -0
  3. data/README.md +57 -0
  4. data/Rakefile +33 -0
  5. data/lib/minit.rb +48 -0
  6. data/minit.gemspec +21 -0
  7. metadata +82 -0
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm 1.9.2@minit
2
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+ gemspec
3
+
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ Minit!
2
+ ====================================
3
+
4
+ Minify JS and CSS in all environments except development and test for Ruby on Rails 3 apps.
5
+
6
+ No frills, no configuration, opinionated packager. Use it, fork it or use something else.
7
+
8
+ This gem aims to fix two shortcomings in the main two asset packaging libraries, namely:
9
+
10
+ 1. Jammit requires Java to package CSS
11
+ 2. asset_packager requires a configuration file to specify every single CSS or JS file
12
+
13
+ It use CSSMin and JSMin gems from rgrove. Thanks!
14
+
15
+ It will ignore files that don't exist. It will only include files once.
16
+
17
+ It's less than 50 lines of code (and no, it's not forced)
18
+
19
+ Usage
20
+ ====================================
21
+
22
+ gem install minit
23
+
24
+ In your layout file add the following to `<head>`:
25
+
26
+ = include_stylesheets
27
+ = include_javascripts
28
+
29
+ Then ensure this folder structure to get the correct load order:
30
+
31
+ public/
32
+ javascripts/
33
+ lib/
34
+ jquery.js (for example)
35
+ plugins/
36
+ jquery_ui/ (for example)
37
+ jquery.menu.js (for example)
38
+ application.js (your own JS for example)
39
+
40
+ stylesheets/
41
+ reset.css
42
+ default.css
43
+ lib/
44
+ *
45
+ *
46
+
47
+ Status / Todo
48
+ ====================================
49
+
50
+ First alpha release
51
+
52
+ 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 CentOS server. I wanted
54
+ to see if it was easy enough to put together a simpler solution.
55
+
56
+ So it needs some tests which will follow shortly.
57
+
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'rake/testtask'
2
+
3
+ desc 'Test, build and install the gem'
4
+ task :default => [:spec, :install]
5
+
6
+ Rake::TestTask.new(:spec) do |t|
7
+ t.pattern = 'spec/*_spec.rb'
8
+ end
9
+
10
+ desc 'Build and install the gem'
11
+ task :install do
12
+ gemspec_path = Dir['*.gemspec'].first
13
+ spec = eval(File.read(gemspec_path))
14
+
15
+ result = `gem build #{gemspec_path} 2>&1`
16
+ if result =~ /Successfully built/
17
+ system "gem uninstall -x #{spec.name} 2>&1"
18
+ system "gem install #{spec.file_name} --no-rdoc --no-ri 2>&1"
19
+ else
20
+ raise result
21
+ end
22
+ end
23
+
24
+ desc 'Take the version in the gemspec, create a git tag and send the gem to rubygems'
25
+ task :release do
26
+ gemspec_path = Dir['*.gemspec'].first
27
+ spec = eval(File.read(gemspec_path))
28
+
29
+ system "git tag -f -a v#{spec.version} -m 'Version #{spec.version}'"
30
+ system "git push --tags"
31
+ system "gem push #{spec.file_name}"
32
+ end
33
+
data/lib/minit.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'cssmin'
2
+ require 'jsmin'
3
+
4
+ def package type, globs, create = true
5
+ compressor = {:javascripts => JSMin, :stylesheets => CSSMin}[type]
6
+ extension = {:javascripts => 'js', :stylesheets => 'css'}[type]
7
+ include_method = {:javascripts => 'javascript_include_tag', :stylesheets => 'stylesheet_link_tag'}[type]
8
+ raise "package type unknown. Only :javascripts or :stylesheets supported." unless compressor && extension && include_method
9
+ package_name = "packaged.#{extension}"
10
+ files = []
11
+ includes = (compress? && !create) ? File.join('/assets', package_name) : []
12
+ asset_path = File.join(Rails.root, 'public', type.to_s, '/')
13
+
14
+ file = File.open(File.join(Rails.root, 'public', 'assets', package_name), 'w') if (compress? && create)
15
+ globs.each do |glob|
16
+ Dir.glob(File.join(asset_path, glob)).each do |path|
17
+ next if files.include?(path)
18
+ files << path
19
+ if compress? && create
20
+ file.puts compressor.minify(File.open(path))
21
+ elsif !create
22
+ includes << path.gsub(asset_path, '')
23
+ end
24
+ end
25
+ end
26
+ file.close if file
27
+ send(include_method, includes)
28
+ end
29
+
30
+ def compress?
31
+ !%w(development test).include?(Rails.env)
32
+ end
33
+
34
+ def include_stylesheets create = false
35
+ package :stylesheets, %w(reset.css default.css lib/**/*.css **/*.css), create
36
+ end
37
+
38
+ def include_javascripts create = false
39
+ package :javascripts, %w(lib/**/*.js plugins/**/*.js **/*.js), create
40
+ end
41
+
42
+ if compress?
43
+ puts 'Compressing assets...'
44
+ include_stylesheets true
45
+ include_javascripts true
46
+ puts 'Finished compressing assets.'
47
+ end
48
+
data/minit.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ require 'base64'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'minit'
5
+ s.version = '0.0.1'
6
+ s.author = 'Phil Thompson'
7
+ s.email = Base64.decode64("cGhpbEBlbGVjdHJpY3Zpc2lvbnMuY29t\n")
8
+ s.homepage = 'http://github.com/PhilT/minit'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'Minify CSS and JS without requiring Java nor specifying individual files'
11
+ s.required_rubygems_version = '>= 1.3.6'
12
+ s.rubyforge_project = 'minit'
13
+
14
+ s.add_dependency 'jsmin'
15
+ s.add_dependency 'cssmin'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- spec/*`.split("\n")
19
+ s.require_path = 'lib'
20
+ end
21
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minit
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Phil Thompson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-22 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: jsmin
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: cssmin
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description:
39
+ email: phil@electricvisions.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .rvmrc
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - lib/minit.rb
52
+ - minit.gemspec
53
+ has_rdoc: true
54
+ homepage: http://github.com/PhilT/minit
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.3.6
74
+ requirements: []
75
+
76
+ rubyforge_project: minit
77
+ rubygems_version: 1.5.2
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Minify CSS and JS without requiring Java nor specifying individual files
81
+ test_files: []
82
+