Skip to content

Instantly share code, notes, and snippets.

@bobspryn
Created February 16, 2012 23:04
Show Gist options
  • Save bobspryn/1848601 to your computer and use it in GitHub Desktop.
Save bobspryn/1848601 to your computer and use it in GitHub Desktop.
AssetFile
require "json"
require "uglifier"
require "rake-pipeline-web-filters"
# this gives you concat, coffee_script, and minispade methods
require "rake-pipeline-web-filters/helpers"
class ImportFilter < Rake::Pipeline::Filter
def generate_output(inputs, output)
inputs.each do |input|
path = input.root + "/" + input.path.sub(/[^\/]+\.\w+/, "")
output.write input.read.gsub(/(@import\s+\"([^\"]+)\";)/) {
File.read("#{path}#{$2}")
}
end
end
end
class CdnFilter < Rake::Pipeline::Filter
def generate_output(inputs, output)
inputs.each do |input|
output.write input.read.gsub(/url\("\/content/) {
"url(\"//d1nc899te42izg.cloudfront.net/content"
}
end
end
end
class FixUglifyFilter < Rake::Pipeline::Filter
def generate_output(inputs, output)
inputs.each do |input|
output.write input.read + ";"
end
end
end
class GzipFilter < Rake::Pipeline::Filter
processes_binary_files
def generate_output(inputs, output)
inputs.each do |input|
strio = StringIO.open('','w')
gz = Zlib::GzipWriter.new(strio)
gz.write(input.read)
gz.close
output.write strio.string
end
end
end
VERS = File.read('VERSION')
# processed files go to build
output "content/build"
# the admin site
input "content/dev" do
match "css/*.css" do
filter ImportFilter
filter CdnFilter
yui_css do |input|
input
end
concat do |filename|
# we only care about these two files
group = ['jquery-ui-1.8.17.custom.css', 'main.css']
if group.include?(filename.split('/').last)
"main.admin.min." + VERS + ".gz.css"
end
end
filter GzipFilter
end
match "**/jquery-1.7.1.min.gz.js" do
concat
end
match "**/*.js" do
# block so uglify doesn't change name
uglify do |input|
input
end
filter FixUglifyFilter
# immediate has to come before modernizr
# block to filter if files even end up in a file at all
# need to decide between immediate and main (top of bottom of html file)
concat ['immediate.js', 'modernizr-2.0.min.js', 'main.js', 'highcharts.js', 'list.js', 'list.paging.js'], do |filename|
immedateGroup = ['immediate.js', 'modernizr-2.0.min.js']
if immedateGroup.include?(filename.split('/').last)
"immediate.admin.min." + VERS + ".gz.js"
else
"main.admin.min." + VERS + ".gz.js"
end
end
filter GzipFilter
end
match "css/*.{css,styl}" do
concat do |filename|
end
end
match "**/*.{csv,tsv,htm,png,jpg,php,json}" do
concat do |filename|
end
end
end
# the marketing site
input "content/sitedev" do
match "css/main.css" do
filter ImportFilter
filter CdnFilter
yui_css
concat "main.min." + VERS + ".gz.css"
filter GzipFilter
end
match "**/*.js" do
# block so uglify doesn't change name
uglify do |input|
input
end
filter FixUglifyFilter
# immediate has to come before modernizr
# block to filter if files even end up in a file at all
# need to decide between immediate and main (top of bottom of html file)
concat ['immediate.js', 'modernizr-2.0.min.js'], do |filename|
immedateGroup = ['immediate.js', 'modernizr-2.0.min.js']
laterGroup = ['main.js', 'jquery.form.js', 'jquery.animate-enhanced.js']
if immedateGroup.include?(filename.split('/').last)
"immediate.min." + VERS + ".gz.js"
elsif laterGroup.include?(filename.split('/').last)
"main.min." + VERS + ".gz.js"
end
end
filter GzipFilter
end
match "css/*.{css,styl}" do
concat do |filename|
end
end
match "**/*.{csv,tsv,htm,png,jpg,php,json}" do
concat do |filename|
end
end
end
@bobspryn
Copy link
Author

Apparently I can't match that file separately on line 75.

@ppcano
Copy link

ppcano commented Mar 13, 2012

very useful, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment