Class: Guard::Slim

Inherits:
Guard
  • Object
show all
Defined in:
lib/guard/slim.rb,
lib/guard/slim/version.rb

Constant Summary collapse

ALL =
File.join '**', '*'
Template =
::Slim::Template
VERSION =
'0.0.1'

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Slim.



11
12
13
14
15
16
17
18
# File 'lib/guard/slim.rb', line 11

def initialize(watchers = [], options = {})
  @output_root = options.delete(:output_root) || Dir.getwd
  @input_root  = options.delete(:input_root) || Dir.getwd
  @context     = options.delete(:context) || Object.new
  @slim        = options.delete(:slim) || {}

  super watchers, options
end

Instance Method Details

#run_allObject



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

def run_all
  run_on_change all_paths
end

#run_on_change(paths) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/guard/slim.rb', line 27

def run_on_change(paths)
  paths.each do |path|
    content = render File.read(path)
    open(build_path(path), 'w') do |file|
      @slim[:pretty] ?
        file.puts(content) :
        file.write(content)
    end
    UI.info "Guard-Slim: Rendered #{ path } to #{ build_path path }"
  end
end

#startObject



20
21
22
# File 'lib/guard/slim.rb', line 20

def start
  UI.info 'Guard-Slim: Waiting for changes...'
end