We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

charlesroper on 08/12/07


Tagged

css ruby e-texteditor


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

n00ge


Refresh Stylesheets for E Text Editor


Published in: Ruby 


URL: http://www.e-texteditor.com/forum/viewtopic.php?p=6358

The escape_javascript funtion is taken from Rails (http://rails.rubyonrails.com/classes/ActionView/Helpers/JavaScriptHelper.html#M000633). Most of the work on this was done by pnomolos and n00ge on the E Text Editor forums.

  1. #!/usr/bin/env ruby
  2. require 'socket'
  3.  
  4. def escape_javascript(javascript)
  5. (javascript || '').gsub('\\','\0\0').gsub(/
  6. |\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
  7. end
  8.  
  9. refresh = escape_javascript("javascript:void(function(){var i,a,s;a=document.getElementsByTagName('link');for(i=0;i<a.length;i++){s=a[i]; if(!s.href){continue;}var h=s.href.replace(/(&|%5C?)forceReload=\d+/,'');s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf())}})();")
  10.  
  11. jssh_socket = TCPSocket::new("localhost", 9997);
  12. jssh_socket.puts("getWindows()[0].getBrowser().loadURI('#{refresh}')")
  13. jssh_socket.close

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: n00ge on August 12, 2007

Note: The JSSH extension is also needed to run this code. It can be downloaded here: http://code.google.com/p/firewatir/downloads/list

You need to login to post a comment.