Skip to content

Instantly share code, notes, and snippets.

@chrisross
Last active March 3, 2016 11:57
Show Gist options
  • Save chrisross/5693049 to your computer and use it in GitHub Desktop.
Save chrisross/5693049 to your computer and use it in GitHub Desktop.
This guardfile configuration combined with haml_helpers to enhance haml are a basic means to generate a static website using preprocessor languages CoffeeScript, Haml, and Sass; and the Compass framework; and the uglifier compression tool.
# Config
root = File.expand_path(File.dirname(__FILE__))
input, output = %w{src site}
haml_ext = "\.haml"
all_on_start = true
# Validate
unless File.directory?(File.join(root, input))
abort('No source directory found, cannot continue')
end
# Helpers
%w{haml_helpers}.each do |i|
require File.join(root, input, 'helpers', "#{i}.rb")
end
guard 'sass',
:input => "#{input}/scss",
:output => "#{output}/css",
:all_on_start => true,
:style => :compressed
# guard 'compass' do
# watch %r{^#{input}/scss/[^/]+\.s[ac]ss$}
# end
guard 'haml',
:input => "#{input}/haml",
:output => output,
:run_on_start => all_on_start,
:options => { :escape_attrs => false } do
watch %r{haml/[^/]+(#{haml_ext})$}
watch %r{haml/partials/[^/]+#{haml_ext}$} do
Dir.glob("#{input}/haml/*.haml")
end
end
guard 'livereload' do
watch %r{#{output}/.+\.(css|html|js)$}
end
# guard 'coffeescript',
# :input => "#{input}/coffee",
# :output => "#{output}/js",
# :all_on_start => all_on_start
# guard :shell, :all_on_start => all_on_start do
# watch %r{#{output}/js/([^\/]+)(?<!\.min)\.js$} do |m|
# src_file = File.join(root, m[0])
# dest_file = File.join(root, output, 'js', "#{m[1]}.min.js")
# n "Uglifying #{m[1]}.js", 'SHELL'
# system( "uglifyjs -o '#{dest_file}' '#{src_file}'" )
# # require 'uglifier' unless defined?(Uglifier)
# # File.open(dest_file, 'w') do |f|
# # f.puts Uglifier.compile(File.read(src_file))
# # end
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment