Skip to content

Commit

Permalink
update to work with the Rails 3.1.1 final. Closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
dnagir committed Oct 10, 2011
1 parent e758a18 commit d4d929d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion guard-rails-assets.gemspec
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|

s.add_dependency 'guard'
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.files = `git ls-files`.split("\n")
Expand Down
48 changes: 21 additions & 27 deletions lib/guard/rails-assets/rails_runner.rb
Expand Up @@ -6,9 +6,11 @@ class RailsAssets::RailsRunner

@@rails_booted = false # Only one rails app is allowed, so make it a class var
@@rails_env = nil
@@digest = nil

def initialize(options={})
@@rails_env = (options[:rails_env] || 'test').to_s unless @@rails_booted
@@digest = options[:digest]
end

def self.apply_hacks
Expand All @@ -35,39 +37,32 @@ def self.boot_rails
end


def clean
Rake::Task["tmp:cache:clear"].execute
# copy from the "assets:clean" Rake task
config = ::Rails.application.config
public_asset_path = File.join(Rails.public_path, config.assets.prefix)
rm_rf public_asset_path, :secure => true
end

def precompile
# copy from the "assets:precompile" Rake task

# Ensure that action view is loaded and the appropriate sprockets hooks get executed
ActionView::Base
config = Rails.application.config
unless config.assets.enabled
warn "Cannot precompile assets if sprockets is disabled. Enabling it."
config.assets.enabled = true
end

config = ::Rails.application.config
config.assets.compile = true
# Ensure that action view is loaded and the appropriate
# sprockets hooks get executed
_ = ActionView::Base

env = ::Rails.application.assets
digest = @@digest.nil? ? config.assets.digest : @@digest

# Always compile files and avoid use of existing precompiled assets
config.assets.compile = true
config.assets.digest = digest
config.assets.digests = {}

target = File.join(::Rails.public_path, config.assets.prefix)
static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest)

manifest = static_compiler.precompile(config.assets.precompile)
manifest_path = config.assets.manifest || target
FileUtils.mkdir_p(manifest_path)

File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
YAML.dump(manifest, f)
end
env = Rails.application.assets
target = File.join(Rails.public_path, config.assets.prefix)
compiler = Sprockets::StaticCompiler.new(env,
target,
config.assets.precompile,
:manifest_path => config.assets.manifest,
:digest => config.assets.digest,
:manifest => config.assets.digest.nil?)
compiler.compile
end


Expand All @@ -78,7 +73,6 @@ def compile_assets
self.class.boot_rails
return false unless @@rails_booted
begin
clean
precompile
true
rescue => e
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/version.rb
@@ -1,5 +1,5 @@
module Guard
module RailsAssetsVersion
VERSION = "0.0.9"
VERSION = "0.1.0"
end
end

0 comments on commit d4d929d

Please sign in to comment.