Class: WebConsole::View

Inherits:
Window
  • Object
show all
Defined in:
lib/webconsole/lib/view.rb,
lib/webconsole/lib/view/erb.rb,
lib/webconsole/lib/view/resources.rb,
lib/webconsole/lib/view/javascript.rb

Direct Known Subclasses

Dependencies::View, REPL::View

Constant Summary collapse

CSS_EXTENSION =
".css"
CSS_PATH_COMPONENT =
"css/"
JS_EXTENSION =
".js"
JS_PATH_COMPONENT =
"js/"

Constants inherited from Window

Window::CLOSEWINDOW_SCRIPT, Window::DOJAVASCRIPT_SCRIPT, Window::LOADHTMLWITHBASEURL_SCRIPT, Window::LOADHTML_SCRIPT, Window::READ_FROM_STANDARD_INPUT_SCRIPT

Instance Attribute Summary collapse

Attributes inherited from Window

#base_url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Window

#base_url_path=, #close, #do_javascript, #load_html, #read_from_standard_input, #split_id, #split_id_last, #window_id

Constructor Details

#initialize(window_id = nil, view_id = nil) ⇒ View

Properties



10
11
12
13
# File 'lib/webconsole/lib/view.rb', line 10

def initialize(window_id = nil, view_id = nil)
  super(window_id)
  @view_id = view_id
end

Instance Attribute Details

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/webconsole/lib/view/resources.rb', line 8

def title
  @title
end

Class Method Details

.javascript_function(function, arguments = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/webconsole/lib/view/javascript.rb', line 9

def self.javascript_function(function, arguments = nil)
  function = function.dup
  function << '('

  if arguments
    arguments.each { |argument|
      if argument
        function << argument.javascript_argument          
      else
        function << "null"
      end
      function << ', '
    }
    function = function[0...-2]
  end

  function << ');'
end

Instance Method Details

#do_javascript_function(function, arguments = nil) ⇒ Object



4
5
6
7
# File 'lib/webconsole/lib/view/javascript.rb', line 4

def do_javascript_function(function, arguments = nil)
  javascript = self.class.javascript_function(function, arguments)
  do_javascript(javascript)
end

#javascript_include_tag(url) ⇒ Object



28
29
30
# File 'lib/webconsole/lib/view/resources.rb', line 28

def javascript_include_tag(url)
  "<script type=\"text/javascript\" src=\"#{url}\"></script>"
end

#load_erb(erb) ⇒ Object



11
12
13
14
15
# File 'lib/webconsole/lib/view/erb.rb', line 11

def load_erb(erb)
  template = ERB.new(erb, nil, '-')
  html = template.result(binding)
  load_html(html)
end

#load_erb_from_path(path) ⇒ Object



6
7
8
9
# File 'lib/webconsole/lib/view/erb.rb', line 6

def load_erb_from_path(path)
  erb = File.new(path).read
  load_erb(erb)
end

#shared_javascript_include_tag(resource) ⇒ Object



23
24
25
26
# File 'lib/webconsole/lib/view/resources.rb', line 23

def shared_javascript_include_tag(resource)
  uri = URI.join(shared_resources_url, JS_PATH_COMPONENT, resource + JS_EXTENSION)
  javascript_include_tag(uri.to_s)
end


12
13
14
15
# File 'lib/webconsole/lib/view/resources.rb', line 12

def shared_stylesheet_link_tag(resource)
  uri = URI.join(shared_resources_url, CSS_PATH_COMPONENT, resource + CSS_EXTENSION)
  stylesheet_link_tag(uri.to_s)
end


17
18
19
# File 'lib/webconsole/lib/view/resources.rb', line 17

def stylesheet_link_tag(url)
  "<link rel=\"stylesheet\" href=\"#{url}\" />"
end

#view_idObject



15
16
17
# File 'lib/webconsole/lib/view.rb', line 15

def view_id
  @view_id ||= ENV.has_key?(SPLIT_ID_KEY) ? ENV[SPLIT_ID_KEY] : split_id
end