class Crabfarm::Live::Viewer
Constants
- INJECTION_TM
Attributes
driver[R]
Public Class Methods
new(_driver)
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 13 def initialize(_driver) @driver = _driver @injected = false end
Public Instance Methods
reset()
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 23 def reset driver.get 'https://www.crabtrap.io/instructions.html' @injected = false end
show_content(_content)
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 33 def show_content(_content) temp_file = Tempfile.new 'cb_live' temp_file.write _content temp_file.close begin show_file temp_file.path # block requests? not sure ensure temp_file.unlink end end
show_file(_path)
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 28 def show_file(_path) driver.get "file://#{_path}" @injected = false end
show_message(_status, _title, _subtitle, _content=nil, _content_type=:text)
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 45 def show_message(_status, _title, _subtitle, _content=nil, _content_type=:text) inject_web_tools Utils::Console.trap_errors 'loading web dialog' do driver.execute_script( "window.crabfarm.showDialog.apply(null, arguments);", _status.to_s, _title, _subtitle, _content, _content_type.to_s ); end end
show_selector_gadget()
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 59 def show_selector_gadget inject_web_tools Utils::Console.trap_errors 'loading selector gadget' do driver.execute_script( 'window.crabfarm.showSelectorGadget();' ) end end
welcome()
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 18 def welcome driver.get 'https://www.crabtrap.io/welcome.html' @injected = false end
Private Instance Methods
inject_web_tools()
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 70 def inject_web_tools return if @injected Utils::Console.trap_errors 'injecting web tools' do Utils::Webdriver.inject_style driver, 'https://www.crabtrap.io/selectorgadget_combined.css' Utils::Webdriver.inject_style driver, 'https://www.crabtrap.io/tools.css' Utils::Webdriver.inject_script driver, 'https://www.crabtrap.io/selectorgadget_combined.js' Utils::Webdriver.inject_script driver, 'https://www.crabtrap.io/tools.js' Timeout::timeout(INJECTION_TM) { wait_for_injection } end @injected = true end
wait_for_injection()
click to toggle source
# File lib/crabfarm/live/viewer.rb, line 84 def wait_for_injection while driver.execute_script "return (typeof window.crabfarm === 'undefined');" sleep 1.0 end end