Skip to content

Instantly share code, notes, and snippets.

@disusered
Created September 27, 2011 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disusered/1244364 to your computer and use it in GitHub Desktop.
Save disusered/1244364 to your computer and use it in GitHub Desktop.
LiveReload, Compass, Sprockets & JSMin with Guard
# Require any additional compass plugins here.
require 'susy'
# HTTP paths
http_path = '/'
http_stylesheets_path = '/stylesheets'
http_javascripts_path = '/javascripts'
http_images_path = '/assets/images'
http_fonts_dir = '/assets/fonts'
# File system locations
sass_dir = 'assets/stylesheets'
css_dir = 'stylesheets'
javascripts_dir = 'assets/javascripts'
images_dir = 'assets/images'
fonts_dir = 'assets/fonts'
# You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed
output_style= :nested
# To enable relative paths to assets via compass helper functions. Uncomment:
relative_assets = true
# Set syntax to Sass
preferred_syntax = :sass
source "http://rubygems.org"
# Rake
gem 'rake'
gem 'guard-shell'
# Sprockets
gem 'sprockets','~> 1.0.2'
# JSMin
gem 'jsmin'
# Guard
gem 'guard'
gem 'yajl-ruby'
# Guard Mac dependencies
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
gem 'growl_notify', :require => false if RUBY_PLATFORM =~ /darwin/i
# Guard Linux dependencies
gem 'rb-inotify', :require => false if RUBY_PLATFORM =~ /linux/i
gem 'libnotify', :require => false if RUBY_PLATFORM =~ /linux/i
# Guard Windows dependencies
gem 'rb-fchange', :require => false if RUBY_PLATFORM =~ /mswin32/i
gem 'win32console', :require => false if RUBY_PLATFORM =~ /mswin32/i
gem 'rb-notifu', :require => false if RUBY_PLATFORM =~ /mswin32/i
# Compass and Sass
gem 'compass'
gem 'compass-susy-plugin'
gem 'oily_png'
# LiveReload
gem 'livereload'
gem 'guard-livereload'
# Guardfile
# LiveReload
guard 'livereload' do
watch (%r{^.+\.(php|html)})
watch (%r{^stylesheets.+\.css})
watch (%r{^javascripts.+\.js})
watch (%r{^assets\/images.+\.(png|gif|jpg|jpeg)})
watch (%r{^assets\/fonts.+\.(woff|ttf|otf|svg|eot)})
end
# Compass
guard 'shell' do
watch (%r{^assets\/stylesheets.+\.(sass|scss)}) { `bundle exec compass compile` }
watch (%r{^assets\/images.+\.(png|gif|jpg|jpeg)}) { `bundle exec compass compile` }
end
# Sprockets & JSMin
guard 'shell' do
watch (%r{^assets\/javascripts\/libs.+\.js}) { `bundle exec rake library` }
watch (%r{^assets\/javascripts(?!\/libs\/).+\.js}) { `bundle exec rake application` }
end
#!/usr/bin/env ruby
require 'rubygems'
require 'sprockets'
require 'jsmin'
# Plugins and libraries
task :library do
puts "Updated file: javascripts/library.js"
concatenated = "javascripts/library.js"
minified = "javascripts/library.min.js"
secretary = Sprockets::Secretary.new(
:asset_root => '.',
:load_path => ['.', 'assets/javascripts/libs'],
:source_files => ['assets/javascripts/libs/*.js'],
:strip_comments => true
)
concatenation = secretary.concatenation
glue = concatenation.to_s
concatenation.save_to(concatenated)
File.open(minified, 'w') { |file| file.write(JSMin.minify(glue)) }
puts "#{concatenated} updated."
end
# User scripts and polyfills
task :application do
puts "Updated file: javascripts/application.js"
concatenated = "javascripts/application.js"
minified = "javascripts/application.min.js"
secretary = Sprockets::Secretary.new(
:asset_root => '.',
:load_path => ['.', 'assets/javascripts', 'assets/javascripts/polyfills'],
:source_files => ['assets/javascripts/*.js', 'assets/javascripts/polyfills/*.js'],
:strip_comments => true
)
concatenation = secretary.concatenation
glue = concatenation.to_s
concatenation.save_to(concatenated)
File.open(minified, 'w') { |file| file.write(JSMin.minify(glue)) }
puts "#{concatenated} updated."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment