Class: Webr::App

Inherits:
Optitron::CLI
  • Object
show all
Includes:
ERB::Util
Defined in:
app/webr.rb

Instance Method Summary collapse

Instance Method Details

#browser(file_name) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'app/webr.rb', line 10

def browser(file_name)
  raise "No such file: #{file_name}" unless File.exist?(file_name)
  file = File.expand_path(file_name)
  root = File.expand_path(File.dirname(file))

  browser = Webr::Browser.new
  browser.open(file_name)
  browser.start
end

#jasmine(file_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/webr.rb', line 22

def jasmine(file_name)
  raise "No such file: #{file_name}" unless File.exist?(file_name)
  files = []
  if File.directory?(file_name)
    root = File.expand_path(file_name)
    files += Dir["#{root}/*_spec.js"]
  else
    files << File.expand_path(file_name)
    root = File.dirname(File.expand_path(file_name))
  end

  format = params["format"]

  begin
    browser = Webr::Jasmine::Browser.new(format)
    browser.root = root
    files.each do |file|
      browser.scripts << file
    end
    browser.start
  rescue Exception => e
    if format == 'html'
      puts "<pre>"
      puts h(e.message)
      puts h(e.backtrace.join("\n"))
      puts "</pre>"
    else
      raise
    end
  end
end