module Forge::Guard

Attributes

builder[RW]
project[RW]
task[RW]

Public Class Methods

add_guard(&block) click to toggle source
# File lib/forge/guard.rb, line 11
def self.add_guard(&block)
  @additional_guards ||= []
  @additional_guards << block
end
start(project, task, options={}, livereload={}) click to toggle source
# File lib/forge/guard.rb, line 16
def self.start(project, task, options={}, livereload={})
  @project = project
  @task = task
  @builder = Builder.new(project)

  options_hash = ""
  options.each do |k,v|
    options_hash << ", :#{k} => '#{v}'"
  end

  assets_path = @project.assets_path.gsub(/#{@project.root}\//, '')
  source_path = @project.source_path.gsub(/#{@project.root}\//, '')
  config_file = @project.config_file.gsub(/#{@project.root}\//, '')

  guardfile_contents = %Q{
    guard 'forgeconfig'#{options_hash} do
      watch("#{config_file}")
    end
    guard 'forgeassets' do
      watch(%r{#{assets_path}/javascripts/*})
      watch(%r{#{assets_path}/stylesheets/*})
      watch(%r{#{assets_path}/images/*})
    end
    guard 'forgetemplates' do
      watch(%r{#{source_path}/templates/*})
      watch(%r{#{source_path}/partials/*})
    end
    guard 'forgefunctions' do
      watch(%r{#{source_path}/functions/*})
      watch(%r{#{source_path}/includes/*})
    end
  }

  if @project.config[:livereload]
    guardfile_contents << %Q{
      guard 'livereload' do
        watch(%r{#{source_path}/*})
      end
    }
  end

  (@additional_guards || []).each do |block|
    result = block.call(options, livereload)
    guardfile_contents << result unless result.nil?
  end

  ::Guard.start({ :guardfile_contents => guardfile_contents })
end