Module: Watchit::Injection
Instance Method Summary collapse
-
#auto_refresh_script ⇒ Object
获取自动刷新js脚本代码.
-
#inject(raw_html) ⇒ Object
向给定html文本中注入自动刷新html脚本.
Methods included from FileSystem
Instance Method Details
#auto_refresh_script ⇒ Object
获取自动刷新js脚本代码
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/watchit/injection.rb', line 14 def auto_refresh_script script_file = File.open File.('../auto_refresh.js', __FILE__) # 监视路径的修改时间 mtime = dir_mtime Watchit::Watch_path time_str = mtime.serilize script = script_file.read script = script.sub(/{{MODIFIED_TIME}}/, time_str) .sub(/{{WATCHING_PATH}}/, Watchit::Watch_path)# 设置修改时间 script_file.close return script end |
#inject(raw_html) ⇒ Object
向给定html文本中注入自动刷新html脚本
8 9 10 11 |
# File 'lib/watchit/injection.rb', line 8 def inject(raw_html) insert_index = (/<\/body>/ =~ raw_html) raw_html.insert insert_index, "<script>#{auto_refresh_script}</script>" end |