This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbuild.rb
62 lines (52 loc) · 1.89 KB
/
build.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
require 'rubygems'
require 'Sprockets'
require 'Jsmin'
class SprocketPackage
DEFAULT_OPTIONS = {
:asset_root => '.',
:load_path => ['.'],
:concat_file_suffix => '.concat.js',
:min_file_suffix => '.build.js',
:strip_comments => true
}
def initialize(source, options = {})
@source = source
if @source.empty?
puts 'please enter a source file to be sprocketized'
else
setup(options)
@sourcefile = source.to_s + '.js'
@concatfile = source.to_s + @options[:concat_file_suffix]
@minfile = source.to_s + @options[:min_file_suffix]
end
end
def setup(options = @options)
@options = DEFAULT_OPTIONS.merge(options)
end
def sprocketize
puts 'beginning sprocketization of ' + @source
secretary = Sprockets::Secretary.new(
:asset_root => @options[:asset_root],
:load_path => @options[:load_path],
:source_files => [@sourcefile],
:strip_comments => @options[:strip_comments]
)
concatenation = secretary.concatenation
gluedFiles = concatenation.to_s
concatenation.save_to(@concatfile)
# File.open(@minfile, 'w') { |file| file.write(JSMin.minify(gluedFiles)) }
puts 'beginning compression of ' + @concatfile
system("java -jar build/yuicompressor.jar " + @concatfile + " > " + @minfile)
end
end
end
cpb = SprocketPackage.new('webroot/js/cpb', { :load_path => ['webroot/js/.', 'webroot/js/plugins', 'webroot/js/cpb', 'webroot/js/cpb/modules']})
cpb.sprocketize
puts 'beginning concatenation of site css'
css = ["webroot/css/basic.css", "webroot/css/layout.css"]
puts 'beginning compression of site css'
File.open("webroot/css/cpb.concat.css","w"){|f|
f.puts css.sort.map{|s| IO.read(s)} }
system("java -jar build/yuicompressor.jar webroot/css/cpb.concat.css > webroot/css/cpb.build.css")