Class: LiveReload::Project
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(directory, explicit_config = nil) ⇒ Project
constructor
A new instance of Project.
- #print_config ⇒ Object
- #read_config ⇒ Object
- #restart_watching ⇒ Object
- #when_changes_detected(&block) ⇒ Object
Constructor Details
#initialize(directory, explicit_config = nil) ⇒ Project
Returns a new instance of Project.
137 138 139 140 141 |
# File 'lib/livereload.rb', line 137 def initialize directory, explicit_config=nil @directory = directory @explicit_config = explicit_config read_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
135 136 137 |
# File 'lib/livereload.rb', line 135 def config @config end |
Instance Method Details
#print_config ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/livereload.rb', line 154 def print_config puts "Watching: #{@directory}" puts " - extensions: " + @config.exts.collect {|e| ".#{e}"}.join(" ") if !@config.apply_js_live && !@config.apply_css_live puts " - live refreshing disabled for .css & .js: will reload the whole page on every change" elsif !@config.apply_js_live puts " - live refreshing disabled for .js: will reload the whole page when .js is changed" elsif !@config.apply_css_live puts " - live refreshing disabled for .css: will reload the whole page when .css is changed" end if @config.exclusions.size > 0 puts " - excluding changes in: " + @config.exclusions.join(" ") end if @config.grace_period > 0 puts " - with a grace period of #{sprintf('%0.2f', @config.grace_period)} sec after each change" end end |
#read_config ⇒ Object
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/livereload.rb', line 143 def read_config project_config_file = File.join(@directory, '.livereload') unless File.file? project_config_file File.open(project_config_file, 'w') do |file| file.write PROJECT_CONFIG_FILE_TEMPLATE end end project_config = Config.load_from project_config_file @config = Config.merge(DEFAULT_CONFIG, USER_CONFIG, project_config, @explicit_config) end |
#restart_watching ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/livereload.rb', line 176 def restart_watching if @dw @dw.stop end @dw = EMDirWatcher.watch @directory, :include_only => (['/.livereload'] + @config.exts.collect { |ext| ["*.#{ext}", ".*.#{ext}"]}).flatten, :exclude => @config.exclusions, :grace_period => @config.grace_period do |paths| begin paths.each do |path| if File.basename(path) == '.livereload' @when_changes_detected.call [:config_changed, path] else @when_changes_detected.call [:modified, File.join(@directory, path)] end end rescue puts $! puts $!.backtrace end end end |
#when_changes_detected(&block) ⇒ Object
172 173 174 |
# File 'lib/livereload.rb', line 172 def when_changes_detected &block @when_changes_detected = block end |