update for Rails 3.1.1
This commit is contained in:
parent
b02458e22a
commit
e758a18f70
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
pkg/*
|
pkg/*
|
||||||
*.gem
|
*.gem
|
||||||
*.rbc
|
*.rbc
|
||||||
|
@ -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.0'
|
s.add_dependency 'rails', '>= 3.1.1.rc2'
|
||||||
s.add_development_dependency 'rspec'
|
s.add_development_dependency 'rspec'
|
||||||
|
|
||||||
s.files = `git ls-files`.split("\n")
|
s.files = `git ls-files`.split("\n")
|
||||||
|
@ -2,6 +2,8 @@ require 'rake/dsl_definition'
|
|||||||
module Guard
|
module Guard
|
||||||
|
|
||||||
class RailsAssets::RailsRunner
|
class RailsAssets::RailsRunner
|
||||||
|
include Rake::DSL
|
||||||
|
|
||||||
@@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
|
||||||
|
|
||||||
@ -13,14 +15,6 @@ module Guard
|
|||||||
# TODO: Hack due to Rails 3.1 issue: https://github.com/rails/rails/issues/2663#issuecomment-1990121
|
# TODO: Hack due to Rails 3.1 issue: https://github.com/rails/rails/issues/2663#issuecomment-1990121
|
||||||
ENV["RAILS_GROUPS"] ||= "assets"
|
ENV["RAILS_GROUPS"] ||= "assets"
|
||||||
ENV["RAILS_ENV"] ||= @@rails_env
|
ENV["RAILS_ENV"] ||= @@rails_env
|
||||||
|
|
||||||
# TODO: Now another hack: Rails replaces Rails.application.assets with Rails.applciation.assets.index
|
|
||||||
# (this happens when config.action_controller.perform_caching is true)
|
|
||||||
# It caches all the assets, so that the Rake task can't be run multiple times
|
|
||||||
require 'sprockets/environment'
|
|
||||||
Sprockets::Environment.class_eval do
|
|
||||||
def index; self; end # instead of Index.new(self)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Methods to run the asset pipeline
|
# Methods to run the asset pipeline
|
||||||
@ -28,6 +22,8 @@ module Guard
|
|||||||
def self.boot_rails
|
def self.boot_rails
|
||||||
return if @@rails_booted
|
return if @@rails_booted
|
||||||
puts "Booting Rails for #{@@rails_env} environment."
|
puts "Booting Rails for #{@@rails_env} environment."
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
apply_hacks
|
apply_hacks
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require "#{Dir.pwd}/config/environment.rb"
|
require "#{Dir.pwd}/config/environment.rb"
|
||||||
@ -39,6 +35,42 @@ module Guard
|
|||||||
end
|
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
|
||||||
|
config.assets.compile = true
|
||||||
|
|
||||||
|
env = ::Rails.application.assets
|
||||||
|
|
||||||
|
# Always compile files and avoid use of existing precompiled assets
|
||||||
|
config.assets.compile = true
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Runs the asset pipeline compiler.
|
# Runs the asset pipeline compiler.
|
||||||
#
|
#
|
||||||
# @return [ Boolean ] Whether the compilation was successful or not
|
# @return [ Boolean ] Whether the compilation was successful or not
|
||||||
@ -46,13 +78,14 @@ module Guard
|
|||||||
self.class.boot_rails
|
self.class.boot_rails
|
||||||
return false unless @@rails_booted
|
return false unless @@rails_booted
|
||||||
begin
|
begin
|
||||||
Rake::Task['assets:clean'].execute
|
clean
|
||||||
::Rails.application.assets.instance_eval { expire_index! }
|
precompile
|
||||||
Rake::Task['assets:precompile'].execute
|
|
||||||
true
|
true
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "An error occurred compiling assets: #{e}"
|
puts "An error occurred compiling assets: #{e}"
|
||||||
false
|
false
|
||||||
|
ensure
|
||||||
|
::Rails.application.assets.instance_eval { expire_index! }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
module Guard
|
module Guard
|
||||||
module RailsAssetsVersion
|
module RailsAssetsVersion
|
||||||
VERSION = "0.0.8"
|
VERSION = "0.0.9"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user