Class: Waitress::LESSWatcher
- Inherits:
-
Object
- Object
- Waitress::LESSWatcher
- Defined in:
- lib/waitress/util/less_watcher.rb
Constant Summary collapse
- @@details =
{}
- @@mtimes =
{}
- @@watchtime =
30
Class Method Summary collapse
- .check ⇒ Object
- .mtime(file) ⇒ Object
-
.mtime_including_imports(file) ⇒ Object
Stolen from Guard.
- .set_time(time) ⇒ Object
Instance Method Summary collapse
-
#initialize(files, &action) ⇒ LESSWatcher
constructor
A new instance of LESSWatcher.
Constructor Details
#initialize(files, &action) ⇒ LESSWatcher
Returns a new instance of LESSWatcher.
23 24 25 |
# File 'lib/waitress/util/less_watcher.rb', line 23 def initialize files, &action files.each { |x| @@details[x] = action } end |
Class Method Details
.check ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/waitress/util/less_watcher.rb', line 27 def self.check @@details.each do |file, action| m = mtime_including_imports(file) if (@@mtimes[file].nil?) || (m > @@mtimes[file]) @@mtimes[file] = m action.call file end end end |
.mtime(file) ⇒ Object
18 19 20 21 |
# File 'lib/waitress/util/less_watcher.rb', line 18 def self.mtime(file) return 0 unless File.file?(file) File.mtime(file).to_i end |
.mtime_including_imports(file) ⇒ Object
Stolen from Guard
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/waitress/util/less_watcher.rb', line 38 def self.mtime_including_imports(file) mtimes = [mtime(file)] File.readlines(file).each do |line| next unless line =~ /^\s*@import ['"]([^'"]+)/ imported = File.join(File.dirname(file), Regexp.last_match[1]) mod_time = if imported =~ /\.le?ss$/ mtime(imported) else [mtime("#{imported}.less"), mtime("#{imported}.lss")].max end mtimes << mod_time end mtimes.max end |
.set_time(time) ⇒ Object
14 15 16 |
# File 'lib/waitress/util/less_watcher.rb', line 14 def self.set_time time @@watchtime = time end |