Module: CSS::Watcher
- Defined in:
- lib/css/watcher.rb
Overview
Watcher
The stylesheet watcher is in charge of monitoring modifications made to a specific stylesheet, then refreshing browsers appropriately while keeping your text editor in focus.
Defined Under Namespace
Classes: Error, NoWatchURLError
Constant Summary collapse
- @@last_checked =
When the stylesheet was last checked for modifications.
0
Class Method Summary collapse
-
.get_url_from_stylesheet(file) ⇒ Object
Parse url from file.
-
.refresh_browsers_to_url(browsers, url) ⇒ Object
Refresh all browsers to the specified url.
-
.stylesheet_has_changed?(file) ⇒ Boolean
Check if a stylesheet has been modified within the last interval checked.
Class Method Details
.get_url_from_stylesheet(file) ⇒ Object
Parse url from file. This should be in the format of /* watch: example.com/path/ */ which is then used as the page to refresh to.
28 29 30 31 32 |
# File 'lib/css/watcher.rb', line 28 def get_url_from_stylesheet file url = $1.strip if File.read(file).match /watch: +((https?|file):\/\/.*?)\*\//i raise NoWatchURLError, "No '/* watch: url */' found in #{file}" if url.nil? url end |
.refresh_browsers_to_url(browsers, url) ⇒ Object
Refresh all browsers to the specified url.
37 38 39 40 41 |
# File 'lib/css/watcher.rb', line 37 def refresh_browsers_to_url browsers, url browsers.each do |browser| system 'open -a %s %s --background' % [browser, url] end end |
.stylesheet_has_changed?(file) ⇒ Boolean
Check if a stylesheet has been modified within the last interval checked.
47 48 49 50 51 |
# File 'lib/css/watcher.rb', line 47 def stylesheet_has_changed? file status = File.new(file).mtime.to_i > @@last_checked @@last_checked = Time.now.to_i status end |