Class: Guard::Tilt

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/tilt.rb

Defined Under Namespace

Classes: DEFAULT_CONTEXT, OutputPath

Constant Summary collapse

DEFAULT_LOCALS =
Hash.new({})

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(watchers = [], options = {}) ⇒ Tilt

Returns a new instance of Tilt.



15
16
17
18
19
20
# File 'lib/guard/tilt.rb', line 15

def initialize(watchers = [], options = {})
  @context  = options.delete(:context) || DEFAULT_CONTEXT
  @locals   = options.delete(:locals)  || DEFAULT_LOCALS

  super watchers, options
end

Class Method Details

.output_path=(klass) ⇒ Object



11
# File 'lib/guard/tilt.rb', line 11

def self.output_path=(klass) @@path = klass; end

.rootObject



13
# File 'lib/guard/tilt.rb', line 13

def self.root; @@root; end

.root=(root) ⇒ Object



12
# File 'lib/guard/tilt.rb', line 12

def self.root=(root) @@root = root; end

Instance Method Details

#reloadObject



27
28
29
30
31
32
# File 'lib/guard/tilt.rb', line 27

def reload
  if @locals.respond_to? :reload
    log 'Reloading locals'
    @locals.reload
  end
end

#run_allObject



47
48
49
50
# File 'lib/guard/tilt.rb', line 47

def run_all
  paths = Watcher.match_files self, Dir[ File.join('**', '*') ]
  run_on_change paths
end

#run_on_change(paths) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/guard/tilt.rb', line 34

def run_on_change(paths)
  paths.each do |pathname|
    full_pathname = File.expand_path pathname, @@root

    next unless template = template_for(full_pathname)
    next unless content = render_template(template, pathname)

    path = @@path.new full_pathname
    next unless write_content(content, path)

    log "Rendered #{ pathname } to #{ path.to_s @@root }"
  end
end

#startObject



21
22
23
# File 'lib/guard/tilt.rb', line 21

def start
  log 'Waiting for changes'
end

#stopObject



24
25
# File 'lib/guard/tilt.rb', line 24

def stop
end