Class: Marksman::Watcher
- Inherits:
-
Object
- Object
- Marksman::Watcher
- Defined in:
- lib/marksman/watcher.rb
Instance Method Summary collapse
-
#initialize(file, output_directory, theme_name = nil) ⇒ Watcher
constructor
A new instance of Watcher.
- #listen ⇒ Object
- #start_theme_listener(theme) ⇒ Object
- #stop ⇒ Object
- #update(start_listener = false) ⇒ Object
- #watch ⇒ Object
Constructor Details
#initialize(file, output_directory, theme_name = nil) ⇒ Watcher
Returns a new instance of Watcher.
6 7 8 9 10 |
# File 'lib/marksman/watcher.rb', line 6 def initialize(file, output_directory, theme_name = nil) @file = Pathname.new file @output_directory = output_directory @theme_name = theme_name end |
Instance Method Details
#listen ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/marksman/watcher.rb', line 23 def listen puts 'Listening to changes...' @markdown_listener = Listen.to(Pathname.new(@file).dirname) do |modified, added, removed| if modified.include? @file.realpath.to_s update end end @markdown_listener.start sleep end |
#start_theme_listener(theme) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/marksman/watcher.rb', line 34 def start_theme_listener(theme) @theme_listener = Listen.to(theme.path) do |modified, added, removed| update end @theme_listener.start end |
#stop ⇒ Object
41 42 43 44 |
# File 'lib/marksman/watcher.rb', line 41 def stop @markdown_listener.stop @theme_listener.stop if @theme_listener end |
#update(start_listener = false) ⇒ Object
17 18 19 20 21 |
# File 'lib/marksman/watcher.rb', line 17 def update(start_listener = false) puts 'Updating files...' presentation = Marksman::Writer.new(@file, @output_directory, @theme_name).generate start_theme_listener(presentation.theme) unless @theme_listener end |
#watch ⇒ Object
12 13 14 15 |
# File 'lib/marksman/watcher.rb', line 12 def watch update(true) listen end |