Class: WebConsole::View
- Inherits:
-
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
Constant Summary
collapse
- CSS_EXTENSION =
".css"
- CSS_PATH_COMPONENT =
"css/"
- JS_EXTENSION =
".js"
- JS_PATH_COMPONENT =
"js/"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ View
Returns a new instance of View.
9
10
11
|
# File 'lib/webconsole/lib/view.rb', line 9
def initialize
@window = WebConsole::Window.new
end
|
Instance Attribute Details
#title ⇒ Object
Returns the value of attribute title.
8
9
10
|
# File 'lib/webconsole/lib/view/resources.rb', line 8
def title
@title
end
|
#window ⇒ Object
Returns the value of attribute window.
8
9
10
|
# File 'lib/webconsole/lib/view.rb', line 8
def window
@window
end
|
Class Method Details
.javascript_function(function, arguments = nil) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/webconsole/lib/view/javascript.rb', line 20
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 << ');'
return function
end
|
Instance Method Details
#base_url=(value) ⇒ Object
13
14
15
|
# File 'lib/webconsole/lib/view.rb', line 13
def base_url=(value)
@window.base_url = value
end
|
#base_url_path=(value) ⇒ Object
17
18
19
|
# File 'lib/webconsole/lib/view.rb', line 17
def base_url_path=(value)
@window.base_url_path = value
end
|
#close ⇒ Object
29
30
31
|
# File 'lib/webconsole/lib/view.rb', line 29
def close
@window.close
end
|
#do_javascript(javascript) ⇒ Object
25
26
27
|
# File 'lib/webconsole/lib/view.rb', line 25
def do_javascript(javascript)
return @window.do_javascript(javascript)
end
|
#do_javascript_function(function, arguments = nil) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/webconsole/lib/view/javascript.rb', line 4
def do_javascript_function(function, arguments = nil)
javascript = self.class.javascript_function(function, arguments)
result = do_javascript(javascript)
result.chomp!
if result.is_integer?
return result.to_i
end
if result.is_float?
return result.to_f
end
return result
end
|
#javascript_include_tag(url) ⇒ Object
28
29
30
|
# File 'lib/webconsole/lib/view/resources.rb', line 28
def javascript_include_tag(url)
return "<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
|
#load_html(html) ⇒ Object
21
22
23
|
# File 'lib/webconsole/lib/view.rb', line 21
def load_html(html)
@window.load_html(html)
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)
return javascript_include_tag(uri.to_s)
end
|
#shared_stylesheet_link_tag(resource) ⇒ Object
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)
return stylesheet_link_tag(uri.to_s)
end
|
#stylesheet_link_tag(url) ⇒ Object
17
18
19
|
# File 'lib/webconsole/lib/view/resources.rb', line 17
def stylesheet_link_tag(url)
return "<link rel=\"stylesheet\" href=\"#{url}\" />"
end
|