Sha256: 4335c6f7db848da4e398bd4b3eaed3c388ad9050e70f4f83ecd29d0fa333fca0

Contents?: true

Size: 1.93 KB

Versions: 15

Compression:

Stored size: 1.93 KB

Contents

module WebConsole::REPL
  class View < WebConsole::View

    BASE_DIRECTORY = File.join(File.dirname(__FILE__), "..")
    VIEWS_DIRECTORY = File.join(BASE_DIRECTORY, "view")
    VIEW_TEMPLATE = File.join(VIEWS_DIRECTORY, 'view.html.erb')
    def initialize
      super
      self.base_url_path = File.expand_path(BASE_DIRECTORY)
      load_erb_from_path(VIEW_TEMPLATE)
    end

    ADD_INPUT_JAVASCRIPT_FUNCTION = "WcREPL.addInput"
    def add_input(input)
      do_javascript_function(ADD_INPUT_JAVASCRIPT_FUNCTION, [input])      
    end
    
    ADD_OUTPUT_JAVASCRIPT_FUNCTION = "WcREPL.addOutput"
    def add_output(output)
      do_javascript_function(ADD_OUTPUT_JAVASCRIPT_FUNCTION, [output])      
    end

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

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

    def repl_handlebars_template_tags
      return %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

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

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

    require 'open-uri'
    def repl_url_for_path(path)
      uri = URI::encode(path)
      return "file://" + uri
    end

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

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
webconsole-0.1.18 lib/webconsole/repl/lib/view.rb
webconsole-0.1.17 lib/webconsole/repl/lib/view.rb
webconsole-0.1.16 lib/webconsole/repl/lib/view.rb
webconsole-0.1.15 lib/webconsole/repl/lib/view.rb
webconsole-0.1.14 lib/webconsole/repl/lib/view.rb
webconsole-0.1.13 lib/webconsole/repl/lib/view.rb
webconsole-0.1.12 lib/webconsole/repl/lib/view.rb
webconsole-0.1.11 lib/webconsole/repl/lib/view.rb
webconsole-0.1.10 lib/webconsole/repl/lib/view.rb
webconsole-0.1.5 lib/webconsole/repl/lib/view.rb
webconsole-0.1.4 lib/webconsole/repl/lib/view.rb
webconsole-0.1.3 lib/webconsole/repl/lib/view.rb
webconsole-0.1.2 lib/webconsole/repl/lib/view.rb
webconsole-0.1.1 lib/webconsole/repl/lib/view.rb
webconsole-0.1.0 lib/webconsole/repl/lib/view.rb