Class: WebConsole::REPL::View

Inherits:
View show all
Defined in:
lib/webconsole/repl/lib/view.rb

Constant Summary collapse

BASE_DIRECTORY =
File.join(File.dirname(__FILE__), "..")
VIEWS_DIRECTORY =
File.join(BASE_DIRECTORY, "view")
VIEW_TEMPLATE =
File.join(VIEWS_DIRECTORY, 'view.html.erb')
ADD_INPUT_JAVASCRIPT_FUNCTION =
"WcREPL.addInput"
ADD_OUTPUT_JAVASCRIPT_FUNCTION =
"WcREPL.addOutput"

Constants inherited from View

View::CSS_EXTENSION, View::CSS_PATH_COMPONENT, View::JS_EXTENSION, View::JS_PATH_COMPONENT

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

Attributes inherited from View

#title

Attributes inherited from Window

#base_url

Instance Method Summary collapse

Methods inherited from View

#do_javascript_function, javascript_function, #javascript_include_tag, #load_erb, #load_erb_from_path, #shared_javascript_include_tag, #shared_stylesheet_link_tag, #stylesheet_link_tag, #view_id

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

#initializeView

Returns a new instance of View.



7
8
9
10
11
# File 'lib/webconsole/repl/lib/view.rb', line 7

def initialize
  super
  self.base_url_path = File.expand_path(BASE_DIRECTORY)
  load_erb_from_path(VIEW_TEMPLATE)
end

Instance Method Details

#add_input(input) ⇒ Object



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

def add_input(input)
  do_javascript_function(ADD_INPUT_JAVASCRIPT_FUNCTION, [input])      
end

#add_output(output) ⇒ Object



19
20
21
# File 'lib/webconsole/repl/lib/view.rb', line 19

def add_output(output)
  do_javascript_function(ADD_OUTPUT_JAVASCRIPT_FUNCTION, [output])      
end

#repl_base_resource_pathObject



63
64
65
# File 'lib/webconsole/repl/lib/view.rb', line 63

def repl_base_resource_path
  File.expand_path(File.join(File.dirname(__FILE__), "../"))
end

#repl_handlebars_template_tagsObject



35
36
37
38
39
40
41
42
43
# File 'lib/webconsole/repl/lib/view.rb', line 35

def repl_handlebars_template_tags
  %Q[
<script id="output-template" type="text/x-handlebars-template">
<pre class="output"><code>{{code}}</code></pre>
  	</script>
  	<script id="input-template" type="text/x-handlebars-template">
<pre><code>{{code}}</code></pre>
  	</script>]
end

#repl_header_tagsObject

Helpers to allow easy loading of REPL resource even from another base URL



25
26
27
28
29
30
31
32
33
# File 'lib/webconsole/repl/lib/view.rb', line 25

def repl_header_tags
  %Q[
#{repl_stylesheet_link_tag}
#{repl_handlebars_template_tags}
#{shared_javascript_include_tag("handlebars")}
  	#{shared_javascript_include_tag("zepto")}
#{repl_javascript_include_tag}
  ]
end

#repl_javascript_include_tagObject



51
52
53
54
55
# File 'lib/webconsole/repl/lib/view.rb', line 51

def repl_javascript_include_tag
  path = File.join(repl_base_resource_path, "js/wcrepl.js")
  url = repl_url_for_path(path)
  javascript_include_tag(url)
end


45
46
47
48
49
# File 'lib/webconsole/repl/lib/view.rb', line 45

def repl_stylesheet_link_tag
  path = File.join(repl_base_resource_path, "css/style.css")
  url = repl_url_for_path(path)
  stylesheet_link_tag(url)
end

#repl_url_for_path(path) ⇒ Object



58
59
60
61
# File 'lib/webconsole/repl/lib/view.rb', line 58

def repl_url_for_path(path)
  uri = URI::encode(path)
  "file://" + uri
end