From bcf712828ec0d6c1d3018ef1530f9c20828134f3 Mon Sep 17 00:00:00 2001 From: Tanguy PATTE Date: Fri, 20 Nov 2015 13:54:23 +0100 Subject: [PATCH] add guard livereload --- Gemfile | 1 + Gemfile.lock | 12 ++++++++++++ Guardfile | 42 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 50b09c1d1..4b447edb4 100644 --- a/Gemfile +++ b/Gemfile @@ -76,6 +76,7 @@ group :test do gem 'timecop' gem 'guard' gem 'guard-rspec', require: false + gem 'guard-livereload', '~> 2.4', require: false end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index f6a075e21..f350af0f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -109,7 +109,11 @@ GEM activemodel (>= 3.0) activesupport (>= 3.0) request_store (~> 1.0) + em-websocket (0.5.1) + eventmachine (>= 0.12.9) + http_parser.rb (~> 0.6.0) erubis (2.7.0) + eventmachine (1.0.8) execjs (2.5.2) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -130,6 +134,12 @@ GEM pry (>= 0.9.12) shellany (~> 0.0) thor (>= 0.18.1) + guard-compat (1.2.1) + guard-livereload (2.5.1) + em-websocket (~> 0.5) + guard (~> 2.8) + guard-compat (~> 1.0) + multi_json (~> 1.8) guard-rspec (4.3.1) guard (~> 2.1) rspec (>= 2.14, < 4.0) @@ -149,6 +159,7 @@ GEM ruby_parser (~> 3.5) http-cookie (1.0.2) domain_name (~> 0.5) + http_parser.rb (0.6.0) httpclient (2.6.0.1) i18n (0.7.0) jbuilder (2.3.1) @@ -417,6 +428,7 @@ DEPENDENCIES factory_girl font-awesome-rails guard + guard-livereload (~> 2.4) guard-rspec haml-rails hashie diff --git a/Guardfile b/Guardfile index cea66ec48..2c60c7b22 100644 --- a/Guardfile +++ b/Guardfile @@ -23,6 +23,47 @@ # installed the spring binstubs per the docs) # * zeus: 'zeus rspec' (requires the server to be started separetly) # * 'just' rspec: 'rspec' + + +guard 'livereload' do + extensions = { + css: :css, + scss: :css, + sass: :css, + js: :js, + coffee: :js, + html: :html, + png: :png, + gif: :gif, + jpg: :jpg, + jpeg: :jpeg, + # less: :less, # uncomment if you want LESS stylesheets done in browser + } + + rails_view_exts = %w(erb haml slim) + + # file types LiveReload may optimize refresh for + compiled_exts = extensions.values.uniq + watch(%r{public/.+\.(#{compiled_exts * '|'})}) + + extensions.each do |ext, type| + watch(%r{ + (?:app|vendor) + (?:/assets/\w+/(?[^.]+) # path+base without extension + (?\.#{ext})) # matching extension (must be first encountered) + (?:\.\w+|$) # other extensions + }x) do |m| + path = m[1] + "/assets/#{path}.#{type}" + end + end + + # file needing a full reload of the page anyway + watch(%r{app/views/.+\.(#{rails_view_exts * '|'})$}) + watch(%r{app/helpers/.+\.rb}) + watch(%r{config/locales/.+\.yml}) +end + guard :rspec, cmd: 'bin/rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } @@ -44,4 +85,3 @@ guard :rspec, cmd: 'bin/rspec' do watch(%r{^spec/acceptance/(.+)\.feature$}) watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } end -