Module: Marv::Project::Guard

Defined in:
lib/marv/project/guard.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.builderObject

Returns the value of attribute builder.



17
18
19
# File 'lib/marv/project/guard.rb', line 17

def builder
  @builder
end

.projectObject

Returns the value of attribute project.



17
18
19
# File 'lib/marv/project/guard.rb', line 17

def project
  @project
end

.taskObject

Returns the value of attribute task.



17
18
19
# File 'lib/marv/project/guard.rb', line 17

def task
  @task
end

Class Method Details

.add_guard(&block) ⇒ Object

Add guard



21
22
23
24
# File 'lib/marv/project/guard.rb', line 21

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

.project_contentsObject

Guard contents



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/marv/project/guard.rb', line 47

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

  contents = %Q{
    guard 'config'#{@options_hash} do
      watch("#{config_file}")
    end
    guard 'functions' do
      watch(%r{#{source_path}/*})
    end
    guard 'templates' do
      watch(%r{#{source_path}/templates/*})
    end
    guard 'assets' do
      watch(%r{#{assets_path}/javascripts/*})
      watch(%r{#{assets_path}/stylesheets/*})
      watch(%r{#{assets_path}/images/*})
    end
  }

  # Enable livereload
  if @options[:livereload]
    contents << %Q{
      guard 'livereload' do
        watch(%r{#{source_path}/*})
      end
    }
  end

  return contents
end

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

Start project watcher



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/marv/project/guard.rb', line 27

def self.start(project, builder, options={}, livereload={})
  @project = project
  @task = project.task
  @builder = builder
  @options = project.config

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

  (@additional_guards || []).each do |block|
    result = block.call(@options, livereload)
    self.project_contents << result unless result.nil?
  end
  # Start guard watching
  ::Guard.start({ :guardfile_contents => self.project_contents })
end