# A sample Guardfile
# More info at https://github.com/guard/guard#readme

ignore(/\.orig$/)

notification :off

directories %w(config lib src public spec)

watch('config/Guardfile') { STDERR.puts "Config changed. Exiting co guard can be restarted."; exit 0 }

guard 'livereload' do
  watch(%r{app/views/.+\.(erb|haml|slim)$})
  watch(%r{app/helpers/.+\.rb})
  watch(%r{public/.+\.(css|js|html)})
  watch(%r{config/locales/.+\.yml})
  # Rails Assets Pipeline
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end

# Sample guardfile block for Guard::Haml
# You can use some options to change guard-haml configuration
# output: 'public'                   set output directory for compiled files
# input: 'src'                       set input directory with haml files
# run_at_start: true                 compile files when guard starts
# notifications: true                send notifictions to Growl/libnotify/Notifu
# haml_options: { ugly: true }    pass options to the Haml engine

#guard :haml, input: 'src', output: 'public' do
#  watch(%r{^src/.+(\.s?html\.haml)$})
#end

guard :bundler do
  watch('Gemfile')
  # Uncomment next line if your Gemfile contains the `gemspec' command.
  # watch(/^.+\.gemspec/)
end

# Note: The cmd option is now required due to the increasing number of ways
#       rspec may be run, below are examples of the most common uses.
#  * bundler: 'bundle exec rspec'
#  * bundler binstubs: 'bin/rspec'
#  * spring: 'bin/rsspec' (This will use spring if running and you have
#                          installed the spring binstubs per the docs)
#  * zeus: 'zeus rspec' (requires the server to be started separetly)
#  * 'just' rspec: 'rspec'

rspec_options = {
  failed_mode: :report,
  cmd: 'bundle exec rspec -t ~slow',
  run_all: {
    cmd: 'CI=true bundle exec rspec -t slow'
  }
}

guard :rspec, rspec_options do
  watch(/^lib\/web\.rb$/)  { "spec/lib/en_spec.rb" }
  watch(/^public\/en\/(.+)\.html$/)  { "spec/lib/en_spec.rb" }
  watch(/^public\/fr\/(.+)\.html$/)  { "spec/lib/fr_spec.rb" }
  watch(/^config\/locale\/en\.yml$/)  { I18n.reload!; "spec/lib/en_spec.rb" }
  watch(/^config\/locale\/fr\.yml$/)  { I18n.reload!; "spec/lib/fr_spec.rb" }

  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }
end

jekyll_plus_options = {
  # serve: true,
  serve: false,
  silent: true,
  # rack_config: 'config/config.ru',
  extensions: ['php', 'ico','htaccess']
}

guard "jekyll-plus", jekyll_plus_options do
  watch(/^src\/(.*\/)?(\.htaccess|favicon\.ico|500\.php|.*\.haml)$/)
  #watch(/^src/)
  ignore(/^public/)
  ignore(/\.orig$/)
end
