githubbish_assets 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/githubbish_assets.gemspec +73 -0
- data/lib/githubbish_assets.rb +45 -0
- data/lib/githubbish_assets/helper.rb +74 -0
- data/lib/githubbish_assets/packer.rb +120 -0
- data/lib/vendor/js_minimizer.rb +217 -0
- data/test/helper.rb +18 -0
- data/test/test_githubbish_assets.rb +7 -0
- metadata +171 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'rails', '~> 3.0.0'
|
7
|
+
gem 'closure-compiler', :require => nil
|
8
|
+
gem 'yui-compressor', :require => nil
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
# gem "shoulda", ">= 0"
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.5.2"
|
16
|
+
gem "rcov", ">= 0"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.3)
|
6
|
+
actionpack (= 3.0.3)
|
7
|
+
mail (~> 2.2.9)
|
8
|
+
actionpack (3.0.3)
|
9
|
+
activemodel (= 3.0.3)
|
10
|
+
activesupport (= 3.0.3)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.6)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.3)
|
19
|
+
activesupport (= 3.0.3)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.3)
|
23
|
+
activemodel (= 3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
activesupport (3.0.3)
|
31
|
+
arel (2.0.6)
|
32
|
+
builder (2.1.2)
|
33
|
+
closure-compiler (0.3.2)
|
34
|
+
erubis (2.6.6)
|
35
|
+
abstract (>= 1.0.0)
|
36
|
+
git (1.2.5)
|
37
|
+
i18n (0.5.0)
|
38
|
+
jeweler (1.5.2)
|
39
|
+
bundler (~> 1.0.0)
|
40
|
+
git (>= 1.2.5)
|
41
|
+
rake
|
42
|
+
mail (2.2.14)
|
43
|
+
activesupport (>= 2.3.6)
|
44
|
+
i18n (>= 0.4.0)
|
45
|
+
mime-types (~> 1.16)
|
46
|
+
treetop (~> 1.4.8)
|
47
|
+
mime-types (1.16)
|
48
|
+
polyglot (0.3.1)
|
49
|
+
rack (1.2.1)
|
50
|
+
rack-mount (0.6.13)
|
51
|
+
rack (>= 1.0.0)
|
52
|
+
rack-test (0.5.7)
|
53
|
+
rack (>= 1.0)
|
54
|
+
rails (3.0.3)
|
55
|
+
actionmailer (= 3.0.3)
|
56
|
+
actionpack (= 3.0.3)
|
57
|
+
activerecord (= 3.0.3)
|
58
|
+
activeresource (= 3.0.3)
|
59
|
+
activesupport (= 3.0.3)
|
60
|
+
bundler (~> 1.0)
|
61
|
+
railties (= 3.0.3)
|
62
|
+
railties (3.0.3)
|
63
|
+
actionpack (= 3.0.3)
|
64
|
+
activesupport (= 3.0.3)
|
65
|
+
rake (>= 0.8.7)
|
66
|
+
thor (~> 0.14.4)
|
67
|
+
rake (0.8.7)
|
68
|
+
rcov (0.9.8)
|
69
|
+
thor (0.14.6)
|
70
|
+
treetop (1.4.9)
|
71
|
+
polyglot (>= 0.3.1)
|
72
|
+
tzinfo (0.3.23)
|
73
|
+
yui-compressor (0.9.1)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler (~> 1.0.0)
|
80
|
+
closure-compiler
|
81
|
+
jeweler (~> 1.5.2)
|
82
|
+
rails (~> 3.0.0)
|
83
|
+
rcov
|
84
|
+
yui-compressor
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Oleg Dashevskii
|
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,22 @@
|
|
1
|
+
= githubbish_assets
|
2
|
+
|
3
|
+
Implement the Github's approach to bundling assets in a Rails 3 engine, as
|
4
|
+
described in here:
|
5
|
+
|
6
|
+
https://github.com/blog/551-optimizing-asset-bundling-and-serving-with-rails
|
7
|
+
|
8
|
+
|
9
|
+
== Contributing to githubbish_assets
|
10
|
+
|
11
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
12
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
13
|
+
* Fork the project
|
14
|
+
* Start a feature/bugfix branch
|
15
|
+
* Commit and push until you are happy with your contribution
|
16
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
17
|
+
* 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.
|
18
|
+
|
19
|
+
== Copyright
|
20
|
+
|
21
|
+
Copyright (c) 2011 Oleg Dashevskii. See LICENSE.txt for
|
22
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "githubbish_assets"
|
16
|
+
gem.homepage = "http://github.com/be9/githubbish_assets"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Github style assets bundling}
|
19
|
+
gem.description = %Q{Github style assets bundling in a Rails 3 engine}
|
20
|
+
gem.email = "olegdashevski@gmail.com"
|
21
|
+
gem.authors = ["Oleg Dashevskii"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "githubbish_assets #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,73 @@
|
|
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{githubbish_assets}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Oleg Dashevskii"]
|
12
|
+
s.date = %q{2011-01-06}
|
13
|
+
s.description = %q{Github style assets bundling in a Rails 3 engine}
|
14
|
+
s.email = %q{olegdashevski@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"githubbish_assets.gemspec",
|
28
|
+
"lib/githubbish_assets.rb",
|
29
|
+
"lib/githubbish_assets/helper.rb",
|
30
|
+
"lib/githubbish_assets/packer.rb",
|
31
|
+
"lib/vendor/js_minimizer.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_githubbish_assets.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/be9/githubbish_assets}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Github style assets bundling}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_githubbish_assets.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"])
|
51
|
+
s.add_runtime_dependency(%q<closure-compiler>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<yui-compressor>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
58
|
+
s.add_dependency(%q<closure-compiler>, [">= 0"])
|
59
|
+
s.add_dependency(%q<yui-compressor>, [">= 0"])
|
60
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
61
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
62
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
63
|
+
end
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
66
|
+
s.add_dependency(%q<closure-compiler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<yui-compressor>, [">= 0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'active_support'
|
3
|
+
require 'githubbish_assets/packer'
|
4
|
+
require 'githubbish_assets/helper'
|
5
|
+
|
6
|
+
module GithubbishAssets
|
7
|
+
# The compressor used to compress javascript.
|
8
|
+
# Might be :closure, :jsmin or :yui
|
9
|
+
mattr_accessor :js_compressor
|
10
|
+
@@js_compressor = :closure
|
11
|
+
|
12
|
+
# Whether to create javascript source map or not.
|
13
|
+
# Has sense only when js_compressor is set to :closure
|
14
|
+
mattr_accessor :closure_source_map
|
15
|
+
@@closure_source_map = false
|
16
|
+
|
17
|
+
###
|
18
|
+
|
19
|
+
class Engine < Rails::Engine
|
20
|
+
initializer 'githubbish_assets.helper' do |app|
|
21
|
+
ActionView::Base.send :include, GithubbishAssets::Helper
|
22
|
+
end
|
23
|
+
|
24
|
+
rake_tasks do
|
25
|
+
namespace :ghbundle do
|
26
|
+
desc 'Create JS and CSS bundles'
|
27
|
+
task :all => [ :js, :css ]
|
28
|
+
|
29
|
+
desc 'Create JS bundles'
|
30
|
+
task :js do
|
31
|
+
verbose false
|
32
|
+
|
33
|
+
Packer.js
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Create CSS bundles'
|
37
|
+
task :css do
|
38
|
+
verbose false
|
39
|
+
|
40
|
+
Packer.css
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module GithubbishAssets
|
2
|
+
module Helper
|
3
|
+
def bundle_files?
|
4
|
+
Rails.env.production? || Rails.env.staging? || params[:bundle] || cookies[:bundle] == "yes"
|
5
|
+
end
|
6
|
+
|
7
|
+
def js_use(*bundles)
|
8
|
+
@js_bundles = ((@js_bundles || []) + bundles.map(&:to_s)).compact.uniq
|
9
|
+
end
|
10
|
+
|
11
|
+
def css_use(*bundles)
|
12
|
+
@css_bundles = ((@css_bundles || []) + bundles.map(&:to_s)).compact.uniq
|
13
|
+
end
|
14
|
+
|
15
|
+
def javascript_bundle(*sources)
|
16
|
+
sources = sources.to_a
|
17
|
+
bundle_files? ? javascript_include_bundles(sources) : javascript_include_files(sources)
|
18
|
+
end
|
19
|
+
|
20
|
+
# This method assumes you have manually bundled js using a rake command
|
21
|
+
# or similar. So there better be bundle_* files.
|
22
|
+
def javascript_include_bundles(bundles)
|
23
|
+
output = ""
|
24
|
+
bundles.each do |bundle|
|
25
|
+
output << javascript_src_tag("bundle_#{bundle}", {}) + "\n"
|
26
|
+
end
|
27
|
+
output.html_safe
|
28
|
+
end
|
29
|
+
|
30
|
+
def javascript_include_files(bundles)
|
31
|
+
output = ""
|
32
|
+
bundles.each do |bundle|
|
33
|
+
files = GithubbishAssets::Packer.recursive_file_list("public/javascripts/#{bundle}", ".js")
|
34
|
+
files.each do |file|
|
35
|
+
file = file.gsub('public/javascripts/', '')
|
36
|
+
output << javascript_src_tag(file, {}) + "\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
output.html_safe
|
40
|
+
end
|
41
|
+
|
42
|
+
def javascript_dev(*sources)
|
43
|
+
output = ""
|
44
|
+
sources = sources.to_a
|
45
|
+
sources.each do |pair|
|
46
|
+
output << javascript_src_tag(Rails.env.development? ? "dev/#{pair[0]}" : pair[1], {})
|
47
|
+
end
|
48
|
+
output.html_safe
|
49
|
+
end
|
50
|
+
|
51
|
+
def stylesheet_bundle(*sources)
|
52
|
+
sources = sources.to_a
|
53
|
+
bundle_files? ? stylesheet_include_bundles(sources) : stylesheet_include_files(sources)
|
54
|
+
end
|
55
|
+
|
56
|
+
# This method assumes you have manually bundled css using a rake command
|
57
|
+
# or similar. So there better be bundle_* files.
|
58
|
+
def stylesheet_include_bundles(bundles)
|
59
|
+
stylesheet_link_tag(bundles.collect{ |b| "bundle_#{b}"})
|
60
|
+
end
|
61
|
+
|
62
|
+
def stylesheet_include_files(bundles)
|
63
|
+
output = ""
|
64
|
+
bundles.each do |bundle|
|
65
|
+
files = GithubbishAssets::Packer.recursive_file_list("public/stylesheets/#{bundle}", ".css")
|
66
|
+
files.each do |file|
|
67
|
+
file = file.gsub('public/stylesheets/', '')
|
68
|
+
output << stylesheet_link_tag(file) + "\n"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
output.html_safe
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'yui/compressor'
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
module GithubbishAssets
|
5
|
+
class Packer
|
6
|
+
def self.js
|
7
|
+
case GithubbishAssets.js_compressor
|
8
|
+
when :jsmin
|
9
|
+
require 'vendor/js_minimizer'
|
10
|
+
when :closure
|
11
|
+
require 'closure-compiler'
|
12
|
+
end
|
13
|
+
|
14
|
+
pack('public/javascripts', '.js') do |target, files|
|
15
|
+
case GithubbishAssets.js_compressor
|
16
|
+
when :closure
|
17
|
+
opts = [ [:js_output_file, target] ]
|
18
|
+
|
19
|
+
if GithubbishAssets.closure_source_map
|
20
|
+
opts << [:create_source_map, "#{target}.map"]
|
21
|
+
end
|
22
|
+
|
23
|
+
files.each do |file|
|
24
|
+
opts << [:js, file]
|
25
|
+
end
|
26
|
+
|
27
|
+
Closure::Compiler.new(opts).compile('')
|
28
|
+
when :yui
|
29
|
+
compress_with_yui(YUI::JavaScriptCompressor.new, files, target)
|
30
|
+
else
|
31
|
+
File.open(target, 'w+') do |f|
|
32
|
+
f.puts GithubbishAssets::JSMinimizer.minimize_files(*files)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.css
|
39
|
+
pack('public/stylesheets', '.css') do |target, files|
|
40
|
+
compress_with_yui(YUI::CssCompressor.new(:line_break => 0), files, target)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.recursive_file_list(basedir, ext)
|
45
|
+
files = []
|
46
|
+
Find.find(basedir) do |path|
|
47
|
+
if FileTest.directory?(path)
|
48
|
+
if File.basename(path)[0] == ?. # Skip dot directories
|
49
|
+
Find.prune
|
50
|
+
else
|
51
|
+
next
|
52
|
+
end
|
53
|
+
end
|
54
|
+
files << path if File.extname(path) == ext
|
55
|
+
end
|
56
|
+
files.sort
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def self.pack(relpath, ext)
|
63
|
+
targets = []
|
64
|
+
get_top_level_directories(relpath).each do |bundle_directory|
|
65
|
+
bundle_name = bundle_directory.basename
|
66
|
+
|
67
|
+
files = recursive_file_list(bundle_directory, ext)
|
68
|
+
next if files.empty? || bundle_name == 'dev'
|
69
|
+
|
70
|
+
target = Rails.root + relpath + "bundle_#{bundle_name}#{ext}"
|
71
|
+
|
72
|
+
yield target, files
|
73
|
+
|
74
|
+
targets << target
|
75
|
+
end
|
76
|
+
|
77
|
+
targets
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.get_top_level_directories(base_path)
|
81
|
+
Dir.entries(Rails.root + base_path).collect do |path|
|
82
|
+
if path[0] != ?. && (Rails.root + base_path + path).directory?
|
83
|
+
path
|
84
|
+
end
|
85
|
+
end.compact
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.compress_with_yui(compressor, files, target)
|
89
|
+
File.open(target, 'w') do |f|
|
90
|
+
compressor.compress(MultiFile.new(files)) do |compressed|
|
91
|
+
while buffer = compressed.read(4096)
|
92
|
+
f.write(buffer)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# A class that emulates continuous reading from a bunch of files
|
99
|
+
class MultiFile
|
100
|
+
def initialize(files)
|
101
|
+
@files = files
|
102
|
+
@file = nil
|
103
|
+
end
|
104
|
+
|
105
|
+
def read(size)
|
106
|
+
while true
|
107
|
+
if @file
|
108
|
+
res = @file.read(size)
|
109
|
+
|
110
|
+
return res if res
|
111
|
+
end
|
112
|
+
|
113
|
+
return if @files.empty?
|
114
|
+
|
115
|
+
@file = File.open(@files.shift, 'r')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,217 @@
|
|
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
|
+
require 'stringio'
|
35
|
+
|
36
|
+
class GithubbishAssets::JSMinimizer
|
37
|
+
attr_accessor :input
|
38
|
+
attr_accessor :output
|
39
|
+
|
40
|
+
EOF = -1
|
41
|
+
@theA = ""
|
42
|
+
@theB = ""
|
43
|
+
|
44
|
+
# isAlphanum -- return true if the character is a letter, digit, underscore,
|
45
|
+
# dollar sign, or non-ASCII character
|
46
|
+
def isAlphanum(c)
|
47
|
+
return false if !c || c == EOF
|
48
|
+
return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
|
49
|
+
(c >= 'A' && c <= 'Z') || c == '_' || c == '$' ||
|
50
|
+
c == '\\' || c[0] > 126)
|
51
|
+
end
|
52
|
+
|
53
|
+
# get -- return the next character from input. Watch out for lookahead. If
|
54
|
+
# the character is a control character, translate it to a space or linefeed.
|
55
|
+
def get()
|
56
|
+
c = @input.getc
|
57
|
+
return EOF if(!c)
|
58
|
+
c = c.chr
|
59
|
+
return c if (c >= " " || c == "\n" || c.unpack("c") == EOF)
|
60
|
+
return "\n" if (c == "\r")
|
61
|
+
return " "
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get the next character without getting it.
|
65
|
+
def peek()
|
66
|
+
lookaheadChar = @input.getc
|
67
|
+
@input.ungetc(lookaheadChar)
|
68
|
+
return lookaheadChar.chr
|
69
|
+
end
|
70
|
+
|
71
|
+
# mynext -- get the next character, excluding comments.
|
72
|
+
# peek() is used to see if a '/' is followed by a '/' or '*'.
|
73
|
+
def mynext()
|
74
|
+
c = get
|
75
|
+
if (c == "/")
|
76
|
+
if(peek == "/")
|
77
|
+
while(true)
|
78
|
+
c = get
|
79
|
+
if (c <= "\n")
|
80
|
+
return c
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
if(peek == "*")
|
85
|
+
get
|
86
|
+
while(true)
|
87
|
+
case get
|
88
|
+
when "*"
|
89
|
+
if (peek == "/")
|
90
|
+
get
|
91
|
+
return " "
|
92
|
+
end
|
93
|
+
when EOF
|
94
|
+
raise "Unterminated comment"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
return c
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# action -- do something! What you do is determined by the argument: 1
|
104
|
+
# Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B.
|
105
|
+
# (Delete A). 3 Get the next B. (Delete B). action treats a string as a
|
106
|
+
# single character. Wow! action recognizes a regular expression if it is
|
107
|
+
# preceded by ( or , or =.
|
108
|
+
def action(a)
|
109
|
+
if(a==1)
|
110
|
+
@output.write @theA
|
111
|
+
end
|
112
|
+
if(a==1 || a==2)
|
113
|
+
@theA = @theB
|
114
|
+
if (@theA == "\'" || @theA == "\"")
|
115
|
+
while (true)
|
116
|
+
@output.write @theA
|
117
|
+
@theA = get
|
118
|
+
break if (@theA == @theB)
|
119
|
+
raise "Unterminated string literal" if (@theA <= "\n")
|
120
|
+
if (@theA == "\\")
|
121
|
+
@output.write @theA
|
122
|
+
@theA = get
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
if(a==1 || a==2 || a==3)
|
128
|
+
@theB = mynext
|
129
|
+
if (@theB == "/" && (@theA == "(" || @theA == "," || @theA == "=" ||
|
130
|
+
@theA == ":" || @theA == "[" || @theA == "!" ||
|
131
|
+
@theA == "&" || @theA == "|" || @theA == "?" ||
|
132
|
+
@theA == "{" || @theA == "}" || @theA == ";" ||
|
133
|
+
@theA == "\n"))
|
134
|
+
@output.write @theA
|
135
|
+
@output.write @theB
|
136
|
+
while (true)
|
137
|
+
@theA = get
|
138
|
+
if (@theA == "/")
|
139
|
+
break
|
140
|
+
elsif (@theA == "\\")
|
141
|
+
@output.write @theA
|
142
|
+
@theA = get
|
143
|
+
elsif (@theA <= "\n")
|
144
|
+
raise "Unterminated RegExp Literal"
|
145
|
+
end
|
146
|
+
@output.write @theA
|
147
|
+
end
|
148
|
+
@theB = mynext
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# jsmin -- Copy the input to the output, deleting the characters which are
|
154
|
+
# insignificant to JavaScript. Comments will be removed. Tabs will be
|
155
|
+
# replaced with spaces. Carriage returns will be replaced with linefeeds.
|
156
|
+
# Most spaces and linefeeds will be removed.
|
157
|
+
def jsmin
|
158
|
+
@theA = "\n"
|
159
|
+
action(3)
|
160
|
+
while (@theA != EOF)
|
161
|
+
case @theA
|
162
|
+
when " "
|
163
|
+
if (isAlphanum(@theB))
|
164
|
+
action(1)
|
165
|
+
else
|
166
|
+
action(2)
|
167
|
+
end
|
168
|
+
when "\n"
|
169
|
+
case (@theB)
|
170
|
+
when "{","[","(","+","-"
|
171
|
+
action(1)
|
172
|
+
when " "
|
173
|
+
action(3)
|
174
|
+
else
|
175
|
+
if (isAlphanum(@theB))
|
176
|
+
action(1)
|
177
|
+
else
|
178
|
+
action(2)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
else
|
182
|
+
case (@theB)
|
183
|
+
when " "
|
184
|
+
if (isAlphanum(@theA))
|
185
|
+
action(1)
|
186
|
+
else
|
187
|
+
action(3)
|
188
|
+
end
|
189
|
+
when "\n"
|
190
|
+
case (@theA)
|
191
|
+
when "}","]",")","+","-","\"","\\", "'", '"'
|
192
|
+
action(1)
|
193
|
+
else
|
194
|
+
if (isAlphanum(@theA))
|
195
|
+
action(1)
|
196
|
+
else
|
197
|
+
action(3)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
else
|
201
|
+
action(1)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.minimize_content(content)
|
208
|
+
js_minimizer = new
|
209
|
+
js_minimizer.input = StringIO.new(content)
|
210
|
+
js_minimizer.output = StringIO.new
|
211
|
+
|
212
|
+
js_minimizer.jsmin
|
213
|
+
|
214
|
+
js_minimizer.output.string
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'githubbish_assets'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: githubbish_assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Oleg Dashevskii
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-06 00:00:00 +06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 7
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 3.0.0
|
33
|
+
requirement: *id001
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
name: rails
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
requirement: *id002
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
name: closure-compiler
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirement: *id003
|
62
|
+
prerelease: false
|
63
|
+
type: :runtime
|
64
|
+
name: yui-compressor
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 23
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 0
|
75
|
+
- 0
|
76
|
+
version: 1.0.0
|
77
|
+
requirement: *id004
|
78
|
+
prerelease: false
|
79
|
+
type: :development
|
80
|
+
name: bundler
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 7
|
88
|
+
segments:
|
89
|
+
- 1
|
90
|
+
- 5
|
91
|
+
- 2
|
92
|
+
version: 1.5.2
|
93
|
+
requirement: *id005
|
94
|
+
prerelease: false
|
95
|
+
type: :development
|
96
|
+
name: jeweler
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
requirement: *id006
|
108
|
+
prerelease: false
|
109
|
+
type: :development
|
110
|
+
name: rcov
|
111
|
+
description: Github style assets bundling in a Rails 3 engine
|
112
|
+
email: olegdashevski@gmail.com
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.rdoc
|
120
|
+
files:
|
121
|
+
- .document
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.rdoc
|
126
|
+
- Rakefile
|
127
|
+
- VERSION
|
128
|
+
- githubbish_assets.gemspec
|
129
|
+
- lib/githubbish_assets.rb
|
130
|
+
- lib/githubbish_assets/helper.rb
|
131
|
+
- lib/githubbish_assets/packer.rb
|
132
|
+
- lib/vendor/js_minimizer.rb
|
133
|
+
- test/helper.rb
|
134
|
+
- test/test_githubbish_assets.rb
|
135
|
+
has_rdoc: true
|
136
|
+
homepage: http://github.com/be9/githubbish_assets
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.3.7
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Github style assets bundling
|
169
|
+
test_files:
|
170
|
+
- test/helper.rb
|
171
|
+
- test/test_githubbish_assets.rb
|