Class: Texas::Task::Watch

Inherits:
Base
  • Object
show all
Defined in:
lib/texas/task/watch.rb

Class Attribute Summary collapse

Attributes inherited from Base

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#build, #initialize

Constructor Details

This class inherits a constructor from Texas::Task::Base

Class Attribute Details

.run_optionsObject

Returns the value of attribute run_options.



7
8
9
# File 'lib/texas/task/watch.rb', line 7

def run_options
  @run_options
end

Class Method Details

.directories_to_watchObject



18
19
20
21
22
23
24
25
# File 'lib/texas/task/watch.rb', line 18

def self.directories_to_watch
  arr = []
  arr << "tex"      if Dir.exists?("tex")
  arr << "contents" if Dir.exists?("contents")
  arr << "figures"  if Dir.exists?("figures")
  arr << Texas.texas_dir
  arr
end

.rebuildObject



27
28
29
30
31
32
33
34
35
# File 'lib/texas/task/watch.rb', line 27

def self.rebuild
  started_at = Time.now.to_i
  Build::Final.new(run_options).run
  finished_at = Time.now.to_i
  puts (finished_at - started_at).to_s + " seconds to rebuild"
rescue Exception => e
  puts @build.current_template.filename
  puts "[ERROR] while building \n#{e}"
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
# File 'lib/texas/task/watch.rb', line 10

def run
  self.class.run_options = options
  dirs = Task::Watch.directories_to_watch
  Listen.to(*dirs) do |modified, added, removed|
    Task::Watch.rebuild
  end
end