Module: Forge::Guard

Defined in:
lib/forge/guard.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.builderObject

Returns the value of attribute builder.



8
9
10
# File 'lib/forge/guard.rb', line 8

def builder
  @builder
end

.projectObject

Returns the value of attribute project.



8
9
10
# File 'lib/forge/guard.rb', line 8

def project
  @project
end

.taskObject

Returns the value of attribute task.



8
9
10
# File 'lib/forge/guard.rb', line 8

def task
  @task
end

Class Method Details

.add_guard(&block) ⇒ Object



11
12
13
14
# File 'lib/forge/guard.rb', line 11

def self.add_guard(&block)
  @additional_guards ||= []
  @additional_guards << block
end

.start(project, task, options = {}, livereload = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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