Skip to content

Instantly share code, notes, and snippets.

@dportalesr dportalesr/Gemfile
Created Oct 23, 2018

Embed
What would you like to do?
require 'rubygems'
require 'bundler'
Bundler.require
unless production?
require 'sinatra/reloader'
# ..other non-production requires..
# Avoid this one since it'll cause recursive
# reloads when using other `also_reload` calls
# also_reload 'app.rb'
# Fine (unless those files are also_reload-free)
also_reload 'app/**/*.rb'
end
# ...
unless ENV['RACK_ENV'] == 'production'
require 'rack-livereload'
use Rack::LiveReload
end
# your main app file
require_relative 'app'
run Sinatra::Application
group :development, :test do
gem "guard-livereload", require: false
gem "rack-livereload"
end
# Run `guard init livereload` to generate this file
# This is the minimal recommended setup
guard 'livereload' do
watch(%r{^app\.rb})
watch(%r{views/.+\.(erb|haml|slim)$})
watch(%r{public/.+\.(css|js|html)})
end
# Don't forget to rename this file to `Guardfile`
# This Guardfile works with sinatra-asset-pipeline
# taking source and compiled extensions into account
guard 'livereload' do
# source-compiled extensions
extensions = {
css: %i(scss sass),
js: nil,
html: nil,
png: nil,
gif: nil,
jpg: nil,
jpeg: nil,
}.freeze
# Files from asset pipeline
extensions.each do |compiled_ext, source_exts|
exts = Array(source_exts) + [compiled_ext]
exts.each do |source_ext|
watch(%r{
(?:assets/\w+/(?<path>[^.]+) # path+base part
(?<ext>\.#{source_ext})) # source extension part
(?:\.\w+|$) # compiled extension part or nothing
# so it matches both .sass & .sass.css files
}x) do |m|
# We need to remap to send to the browser (livereloading)
# the compiled version of the asset instead of the modified
# one, that is, the source file.
path = m[1]
"/assets/#{path}.#{compiled_ext}"
end
end
end
# Will trigger full page reload
compiled_exts = extensions.keys
watch(%r{public/.+\.(#{compiled_exts * '|'})}) # Static files in public/
watch(%r{views\/.+\.(erb|haml|slim)$}) # View templates
watch(%r{app\/(helpers|models)\/(.+)\.rb$}) # app subfolders
watch(%r{^app\.rb})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.