module Dyndoc::Browser
Public Class Methods
cfg()
click to toggle source
# File lib/dyndoc-html-servers.rb, line 33 def Browser.cfg unless @@cfg @@cfg=(File.exist? @@browser_cfg_file) ? ::YAML::load_file(@@browser_cfg_file) : {} end @@cfg end
get()
click to toggle source
# File lib/dyndoc-html-servers.rb, line 29 def Browser.get Browser.cfg["browser"] || @@default_browser end
load(url)
click to toggle source
# File lib/dyndoc-html-servers.rb, line 148 def Browser.load(url) if RUBY_PLATFORM =~ /darwin/ mode=Browser.get.to_sym if mode==:safari code='tell application "'+Browser.name+'" to set URL of current tab of front window to "'+url+'"' elsif mode == :firefox code='tell application "Firefox" to open location "'+url+'"' elsif mode == :chrome code=%Q{ tell application "Google Chrome" set frontIndex to active tab index of front window set URL of tab frontIndex of front window to "#{url}" end tell } end File.open(@@browser_load_osa,"w") do |f| f << code end `osascript #{@@browser_load_osa}` elsif RUBY_PLATFORM =~ /linux/ system("xdg-open #{url} &") end end
name()
click to toggle source
# File lib/dyndoc-html-servers.rb, line 46 def Browser.name mode=Browser.get.to_sym if RUBY_PLATFORM =~ /darwin/ case mode when :chrome "Google Chrome" when :canary "Google Chrome Canary" when :firefox "Firefox" when :firefox_nightly "FirefoxNightly" when :firefox_developer "FirefoxDeveloperEdition" when :safari "Safari" end elsif RUBY_PLATFORM =~ /linux/ mode.to_s end end
reload()
click to toggle source
# File lib/dyndoc-html-servers.rb, line 138 def Browser.reload if RUBY_PLATFORM =~ /darwin/ Browser.set_browser_reload unless File.exists? @@browser_reload_osa `osascript #{@@browser_reload_osa}` elsif RUBY_PLATFORM =~ /linux/ and File.exists? "/usr/bin/xdotool" `export DISPLAY=':0.0';/usr/bin/xdotool search --sync --onlyvisible #{Browser.name} key F5 windowactivate` end end
save_cfg()
click to toggle source
# File lib/dyndoc-html-servers.rb, line 40 def Browser.save_cfg File.open(@@browser_cfg_file,"w") do |f| f << Browser.cfg.to_yaml end end
set(browser)
click to toggle source
# File lib/dyndoc-html-servers.rb, line 20 def Browser.set(browser) Browser.cfg["browser"]=browser Browser.save_cfg FileUtils.rm(@@browser_load_osa) if File.exists? @@browser_load_osa FileUtils.rm(@@browser_reload_osa) if File.exists? @@browser_reload_osa Browser.set_browser_reload puts "Current browser is set to "+Browser.get+"!" end
set_browser_reload()
click to toggle source
# File lib/dyndoc-html-servers.rb, line 69 def Browser.set_browser_reload activate=Browser.cfg["activate"] || false mode=Browser.get.to_sym code=case mode when :chrome %Q{ tell application "Google Chrome" #{activate ? 'activate' : ''} "chrome" set winref to a reference to (first window whose title does not start with "Developer Tools - ") set winref's index to 1 reload active tab of winref end tell } when :canary %Q{ tell application "Google Chrome Canary" #{activate ? 'activate' : ''} "chrome canary" set winref to a reference to (first window whose title does not start with "Developer Tools - ") set winref's index to 1 reload active tab of winref end tell } when :firefox %Q{ tell application "Firefox" activate tell application "System Events" to keystroke "r" using command down end tell } when :firefox_nightly %Q{ set a to path to frontmost application as text tell application "FirefoxNightly" activate tell application "System Events" to keystroke "r" using command down end tell #{activate ? '' : 'delay 0.2\nactivate application a'} } when :firefox_developer %Q{ set a to path to frontmost application as text tell application "FirefoxDeveloperEdition" activate tell application "System Events" to keystroke "r" using command down end tell #{activate ? '' : 'delay 0.2\nactivate application a'} } when :safari %Q{ tell application "Safari" #{activate ? 'activate' : ''} tell its first document set its URL to (get its URL) end tell end tell } end File.open(@@browser_reload_osa,"w") do |f| f << code.strip end end