update to work with the Rails 3.1.1 final. Closes #14

This commit is contained in:
Dmytrii Nagirniak 2011-10-11 09:28:23 +11:00
parent e758a18f70
commit d4d929db49
3 changed files with 24 additions and 30 deletions

View File

@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.add_dependency 'guard' s.add_dependency 'guard'
s.add_dependency 'rake' s.add_dependency 'rake'
s.add_dependency 'rails', '>= 3.1.1.rc2' s.add_dependency 'rails', '>= 3.1.1'
s.add_development_dependency 'rspec' s.add_development_dependency 'rspec'
s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split("\n")

View File

@ -6,9 +6,11 @@ module Guard
@@rails_booted = false # Only one rails app is allowed, so make it a class var @@rails_booted = false # Only one rails app is allowed, so make it a class var
@@rails_env = nil @@rails_env = nil
@@digest = nil
def initialize(options={}) def initialize(options={})
@@rails_env = (options[:rails_env] || 'test').to_s unless @@rails_booted @@rails_env = (options[:rails_env] || 'test').to_s unless @@rails_booted
@@digest = options[:digest]
end end
def self.apply_hacks def self.apply_hacks
@ -35,39 +37,32 @@ module Guard
end end
def clean def precompile
Rake::Task["tmp:cache:clear"].execute config = Rails.application.config
# copy from the "assets:clean" Rake task unless config.assets.enabled
config = ::Rails.application.config warn "Cannot precompile assets if sprockets is disabled. Enabling it."
public_asset_path = File.join(Rails.public_path, config.assets.prefix) config.assets.enabled = true
rm_rf public_asset_path, :secure => true
end end
def precompile # Ensure that action view is loaded and the appropriate
# copy from the "assets:precompile" Rake task # sprockets hooks get executed
_ = ActionView::Base
# Ensure that action view is loaded and the appropriate sprockets hooks get executed digest = @@digest.nil? ? config.assets.digest : @@digest
ActionView::Base
config = ::Rails.application.config
config.assets.compile = true
env = ::Rails.application.assets
# Always compile files and avoid use of existing precompiled assets
config.assets.compile = true config.assets.compile = true
config.assets.digest = digest
config.assets.digests = {} config.assets.digests = {}
target = File.join(::Rails.public_path, config.assets.prefix) env = Rails.application.assets
static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest) target = File.join(Rails.public_path, config.assets.prefix)
compiler = Sprockets::StaticCompiler.new(env,
manifest = static_compiler.precompile(config.assets.precompile) target,
manifest_path = config.assets.manifest || target config.assets.precompile,
FileUtils.mkdir_p(manifest_path) :manifest_path => config.assets.manifest,
:digest => config.assets.digest,
File.open("#{manifest_path}/manifest.yml", 'wb') do |f| :manifest => config.assets.digest.nil?)
YAML.dump(manifest, f) compiler.compile
end
end end
@ -78,7 +73,6 @@ module Guard
self.class.boot_rails self.class.boot_rails
return false unless @@rails_booted return false unless @@rails_booted
begin begin
clean
precompile precompile
true true
rescue => e rescue => e

View File

@ -1,5 +1,5 @@
module Guard module Guard
module RailsAssetsVersion module RailsAssetsVersion
VERSION = "0.0.9" VERSION = "0.1.0"
end end
end end