done with compiling using CLI
This commit is contained in:
parent
db77c93bad
commit
2983323f7a
@ -5,29 +5,42 @@ module Guard
|
|||||||
class RailsAssets < Guard
|
class RailsAssets < Guard
|
||||||
def initialize(watchers=[], options={})
|
def initialize(watchers=[], options={})
|
||||||
super
|
super
|
||||||
|
@options = options || {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
# Started
|
compile_assets if run_for? :start
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload
|
def reload
|
||||||
# Ctrl-Z
|
compile_assets if run_for? :reload
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_all
|
def run_all
|
||||||
# Ctr-\ - restarting stuff
|
compile_assets if run_for? :all
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_on_change(paths)
|
def run_on_change(paths=[])
|
||||||
|
compile_assets if run_for? :change
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile_assets
|
def compile_assets
|
||||||
# clean
|
result = system "rm -rf public/assets && bundle exec rake assets:precompile"
|
||||||
# prefix or path
|
if result
|
||||||
# compile
|
tree = `tree public/assets`
|
||||||
Notifier::notify '1 directory, 2 files', :title => 'Assets compiled'
|
summary = tree.split("\n").last
|
||||||
|
Notifier::notify summary, :title => 'Assets compiled'
|
||||||
|
else
|
||||||
|
Notifier::notify 'see the details in the terminal', :title => "Can't compile assets", :image => :failed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def run_for? command
|
||||||
|
run_on = @options[:run_on]
|
||||||
|
run_on = [:start, :all, :change] if not run_on or run_on.empty?
|
||||||
|
run_on.include?(command)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,20 +28,24 @@ describe Guard::RailsAssets do
|
|||||||
|
|
||||||
describe 'asset compilation using CLI' do
|
describe 'asset compilation using CLI' do
|
||||||
def stub_system_with result
|
def stub_system_with result
|
||||||
Kernel.stub(:system).with("rm -rf public/assets && bundle exec rake assets:precompile").and_return result
|
subject.should_receive(:system).with("rm -rf public/assets && bundle exec rake assets:precompile").and_return result
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should notify on success' do
|
it 'should notify on success' do
|
||||||
stub_system_with true
|
stub_system_with true
|
||||||
Kernel.should_receive(:~).with('tree public/assets').and_return "a\nb\n1 directory, 2 files"
|
subject.should_receive(:`).with('tree public/assets').and_return "a\nb\n1 directory, 2 files"
|
||||||
Guard::Notifier.should_receive(:notify).with('1 directory, 2 files', :title => 'Assets compiled')
|
Guard::Notifier.should_receive(:notify).with('1 directory, 2 files', :title => 'Assets compiled')
|
||||||
subject.compile_assets
|
subject.compile_assets
|
||||||
end
|
end
|
||||||
it 'should notify on failure' do
|
it 'should notify on failure' do
|
||||||
stub_system_with false
|
stub_system_with false
|
||||||
Kernel.should_not_receive(:~)
|
Kernel.should_not_receive(:`)
|
||||||
Guard::Notifier.should_receive(:notify).with('see the details in the terminal', :title => "Can't compile assets", :image => :failed)
|
Guard::Notifier.should_receive(:notify).with('see the details in the terminal', :title => "Can't compile assets", :image => :failed)
|
||||||
subject.compile_assets
|
subject.compile_assets
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'custom assets prefix' do
|
||||||
|
it 'should use given prefix'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,31 @@
|
|||||||
shared_examples_for "guard command" do |options|
|
shared_examples_for "guard command" do |info|
|
||||||
|
|
||||||
it "should execute #{options[:command]} when said so"
|
def set_run_on_option info
|
||||||
it "should not execute #{options[:command]} when disabled"
|
# run_on_change -> change
|
||||||
|
# run_all -> all
|
||||||
|
run_option = info[:command].to_s.match(/(.*_)?(\w+)/)[2].to_sym
|
||||||
|
options[:run_on] = [run_option]
|
||||||
|
end
|
||||||
|
|
||||||
it "should #{options[:run] ? '' : 'not '}execute #{options[:command]} by default"
|
it "should execute #{info[:command]} when said so" do
|
||||||
it "should execute built-in helper"
|
set_run_on_option info
|
||||||
|
subject.should_receive(:compile_assets)
|
||||||
|
subject.send(info[:command])
|
||||||
|
end
|
||||||
|
it "should not execute #{info[:command]} when disabled" do
|
||||||
|
options[:run_on] = [:something_other]
|
||||||
|
subject.should_not_receive(:compile_assets)
|
||||||
|
subject.send(info[:command])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should #{info[:run] ? '' : 'not '}execute #{info[:command]} by default" do
|
||||||
|
options[:run_on] = nil
|
||||||
|
if info[:run]
|
||||||
|
subject.should_receive(:compile_assets)
|
||||||
|
else
|
||||||
|
subject.should_not_receive(:compile_assets)
|
||||||
|
end
|
||||||
|
subject.send(info[:command])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user