[BioRuby-cvs] bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates _classes.rhtml, NONE, 1.1 _methods.rhtml, NONE, 1.1 _modules.rhtml, NONE, 1.1 _result.rhtml, NONE, 1.1 _variables.rhtml, NONE, 1.1 bioruby.css, NONE, 1.1 bioruby.png, NONE, 1.1 bioruby.rhtml, NONE, 1.1 bioruby_controller.rb, NONE, 1.1 bioruby_helper.rb, NONE, 1.1 commands.rhtml, NONE, 1.1 history.rhtml, NONE, 1.1 index.rhtml, NONE, 1.1 shell_helper.rb, NONE, 1.1

Katayama Toshiaki k at dev.open-bio.org
Sun Dec 24 08:27:17 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio/shell/rails/vendor/plugins/generators/bioruby/templates
In directory dev.open-bio.org:/tmp/cvs-serv9279/templates

Added Files:
	_classes.rhtml _methods.rhtml _modules.rhtml _result.rhtml 
	_variables.rhtml bioruby.css bioruby.png bioruby.rhtml 
	bioruby_controller.rb bioruby_helper.rb commands.rhtml 
	history.rhtml index.rhtml shell_helper.rb 
Log Message:
* Rails generator for BioRuby shell on Rails


--- NEW FILE: shell_helper.rb ---
module ShellHelper

  include Bio::Shell

  def evaluate_script(script)
    @local_variables = eval("local_variables", Bio::Shell.cache[:binding]) - ["_erbout"]

    # write out to history
    begin
      Bio::Shell.cache[:histfile].puts "#{Time.now}\t#{script.strip.inspect}"
      eval(script, Bio::Shell.cache[:binding])
    rescue
      $!
    end
  end

  def method_link()
  end

  def reference_link(class_name)
    case class_name
    when /Bio::(.+)/
      "http://bioruby.org/rdoc/classes/Bio/#{$1.split('::').join('/')}.html"
    when /Chem::(.+)/
      "http://chemruby.org/rdoc/classes/Chem/#{$1.split('::').join('/')}.html"
    else
      "http://www.ruby-doc.org/core/classes/#{class_name.split('::').join('/')}.html"
    end
  end

end

--- NEW FILE: _classes.rhtml ---
[ <%= @class %> ]
<%= @classes.map{ |x| reference_link(x) }.join(" > ") %>

--- NEW FILE: commands.rhtml ---
<h2>BioRuby shell commands</h2>
<ul>
  <% @bioruby_commands.each do |cmd| %>
  <li><%= cmd %></li>
  <% end %>
</ul>


--- NEW FILE: bioruby.rhtml ---
<html>
<head>
<title>BioRuby shell on Rails</title>
<%= stylesheet_link_tag "bioruby.css" %>
<%= javascript_include_tag :defaults %>
</head>
<body>

<div id="side">
 <img src="/images/bioruby.png"><br>

 <div class="title">Project</div>
  <ul>
   <li><%= project_workdir %>
  </ul>

 <div class="title">Functions</div>
 <ul>
   <li><%= link_to "Console", :action => "index" %></li>
   <li><%= link_to "History", :action => "history" %></li>
   <li><%= link_to "Commands", :action => "commands" %></li>
 </ul>

 <div class="title">Local variables</div>
 <%= render :partial => "variables" %>
</div>


<div id="main">

<h1>BioRuby shell on Rails</h1>
<%= yield %>

</div>

</body>

--- NEW FILE: _modules.rhtml ---
[ <%= @class %> ]
<%= @modules.map {|x| reference_link(x) }.join(" | ") %>

--- NEW FILE: _variables.rhtml ---
<div id="variables">
<ul>
<% local_variables.each do |var| %>
<li><%= link_to_remote var, :update => "index", :url => {:action => "evaluate", :script => var} %></li>
<% end %>
</ul>
</div>
--- NEW FILE: bioruby.css ---
/* body */

body {
	color: #6e8377;
	background-color: #ffffff;
	font-family: verdana, arial, helvetica, sans-serif;
}

/* main */

div#main {
	width: 700px;
	background-color: #ffffff;
	padding-top: 0px;
	padding-left: 10px;
}

pre {
	color: #6e8377;
	background-color: #eaedeb;
	border-color: #6e8377;
	border-style: dashed;
	border-width: 1px;
	padding: 5px;
	overflow: auto;
}

div.evaluate div.input pre.script {
	background-color: #ffffeb;
	border-style: solid;
}

div.evaluate div.output div.methods {
	padding: 5px;
	background-color: #ffffdd;
	border: 1px solid #ffcc00;
}

div.evaluate div.output div.classes {
	padding: 5px;
	background-color: #ccffcc;
	border: 1px solid #00ff00;
}

div.evaluate div.output div.modules {
	padding: 5px;
	background-color: #ffcccc;
	border: 1px solid #ff0000;
}

div.evaluate div.output pre.result {
	border-style: dashed;
}

div.evaluate div.output pre.output {
	border-style: dashed;
}

div.evaluate hr.evaluate {
	border-style: dotted none none none;
	border-top-width: 1px;
	border-color: #6e8377;
	height: 1px;
}

/* side */

div#side {
	width: 150px;
	background-color: #ffffff;
	position: absolute;
	top: 10px;
	left: 10px;
}

div#side div.title {
	border-width: 0px 0px 1px 0px;
}

div#side img {
	padding: 5px;
}

/* history */

div#history { 
}

div#history div.histtime {
	background-color: #eaedeb;
	padding: 5px;
}

div#history div.histline {
	background-color: #ffffeb;
	padding: 5px;
	font-family: monospace;
	white-space: pre;
}

/* image */

img {
	/* centering */
	display: block;
	margin-left: auto;
	margin-right: auto;
}

/* em */

em {
	color: #6e8377;
	font-style: normal;
}

/* link */

a {
	text-decoration: none;
}

a:link {
	color: #669933;
}

a:visited {
	color: #669933;
}

a:hover {
	text-decoration: underline;
}

/* header */

h1 {
	font-size: 200%;
	color: #ffffff;
	background-color: #6e8377;
	line-height: 64px;
	text-align: right;
	padding-right: 20px;
}

h2 {
	font-size: 160%;
	color: #6e8377;
	border-color: #b9c3be;
	border-style: dashed;
	border-width: 0px 0px 1px 0px;
}

h3 {
	font-size: 140%;
	color: #6e8377;
	border-color: #b9c3be;
	border-style: dotted;
	border-width: 0px 0px 1px 0px;
}

h4 {
	font-size: 130%;
	color: #6e8377;
	border-color: #b9c3be;
	border-style: solid;
	border-width: 0px 0px 1px 0px;
}

h5 {
	font-size: 120%;
	color: #6e8377;
}

h6 {
	font-size: 110%;
	color: #6e8377;
}

/* list */

dt {
	color: #6e8377;
	border-color: #b9c3be;
	border-style: dashed;
	border-width: 1px;
	padding: 5px;
}

ul {
	color: #6e8377;
}

/* table */

th {
	vertical-align: top;
}

td {
	vertical-align: top;
}

/* textarea */

textarea {
	overflow: auto;
}

/* blockquote */

blockquote {
	color: #6e8377;
	background-color: #eaedeb;
	border-color: #6e8377;
	border-style: dashed;
	border-width: 1px;
}

/* media */

@media print {
	div#main	{ margin-left: 0px; }
	div#side	{ display: none; }
}

@media screen {
	div#main	{ margin-left: 150px; }
	div#side	{ display: block; }
}


--- NEW FILE: bioruby_helper.rb ---
module BiorubyHelper

  HIDE_VARIABLES = [
    "_", "irb", "_erbout",
  ]

  include Bio::Shell

  def project_workdir
    Bio::Shell.cache[:workdir]
  end

  def have_results
    Bio::Shell.cache[:results].number > 0
  end

  def local_variables
    eval("local_variables", Bio::Shell.cache[:binding]) - HIDE_VARIABLES
  end

  def reference_link(class_or_module)
    name = class_or_module.to_s
    case name
    when /Bio::(.+)/
      path = $1.split('::').join('/')
      url = "http://bioruby.org/rdoc/classes/Bio/#{path}.html"
    when /Chem::(.+)/
      path = $1.split('::').join('/')
      url = "http://chemruby.org/rdoc/classes/Chem/#{path}.html"
    else
      path = name.split('::').join('/')
      url = "http://www.ruby-doc.org/core/classes/#{path}.html"
    end
    return "<a href='#{url}'>#{name}</a>"
  end

end

--- NEW FILE: _result.rhtml ---
<div id="evaluate" class="evaluate">
<hr class="evaluate">
<div class="input">
Input: [<%= @number %>]
<pre class="script">
<%=h @script %>
</pre>
<div class="output">
Result:
[<%= link_to_remote "methods", :url => {:action => "list_methods", :number => @number} %>]
[<%= link_to_remote "classes", :url => {:action => "list_classes", :number => @number} %>]
[<%= link_to_remote "modules", :url => {:action => "list_modules", :number => @number} %>]
<div id="methods_<%= @number %>" class="methods"></div>
<div id="classes_<%= @number %>" class="classes"></div>
<div id="modules_<%= @number %>" class="modules"></div>
<pre class="result">
<%=h @result %>
</pre>
<% if @output %>
Output:
<pre class="output">
<%=h @output %>
</pre>
<% end %>
</div>
</div>
</div>


--- NEW FILE: _methods.rhtml ---
[ <%= @class %> ]
<% @methods.sort.each do |x| %>
<%= x %>
<% end %>
--- NEW FILE: index.rhtml ---
<div id="console">
<%= form_remote_tag(:url => {:action => "evaluate"}, :position => "top") %>
<b>BioRuby script</b>
<input type="submit" value="Evaluate">
<input type="reset" value="Clear">
&nbsp;&nbsp;
Show [
<%= link_to_remote "All",      :url => {:action => "results", :limit => 0} %> |
<%= link_to_remote "Last 5",   :url => {:action => "results", :limit => 5} %> |
<%= link_to_remote "Previous", :url => {:action => "results", :limit => 1} %>
] or [
<%= link_to "Clear", :action => "index" %>
] results<br>
<textarea id="script" name="script" rows=10 cols=80></textarea><br>
<%= end_form_tag %>
</div>

--- NEW FILE: history.rhtml ---
<div id="history">
<h2>Command history</h2>
<% @history.each do |line| %>
<%   if line[/^# /] %>
<div class="histtime"><%= line %></div>
<%   else %>
<div class="histline"><%= line %></div>
<%   end %>
<% end %>
</div>

--- NEW FILE: bioruby_controller.rb ---
class BiorubyController < ApplicationController

  HIDE_METHODS = Object.methods

  HIDE_MODULES = [
    WEBrick, Base64::Deprecated, Base64, PP::ObjectMixin,
  ]

  def evaluate
    begin
      @script = params[:script].strip

      # write out to history
      Bio::Shell.store_history(@script)

      # evaluate ruby script
      @result = eval(@script, Bio::Shell.cache[:binding])

      # *TODO* need to handle with output of print/puts/p/pp etc. here
      @output = nil
    rescue
      @result = $!
      @output = nil
    end

    @number = Bio::Shell.cache[:results].store(@script, @result, @output)

    render :update do |page|
      page.insert_html :after, "console", :partial => "result"
      page.replace_html "variables", :partial => "variables"
      page.hide "methods_#{@number}"
      page.hide "classes_#{@number}"
      page.hide "modules_#{@number}"
    end
  end

  def list_methods
    number = params[:number].to_i
    script, result, output = Bio::Shell.cache[:results].restore(number)
    @class = result.class
    @methods = result.methods - HIDE_METHODS

    render :update do |page|
      page.replace_html "methods_#{number}", :partial => "methods"
      page.visual_effect :toggle_blind, "methods_#{number}", :duration => 0.5
    end
  end

  def list_classes
    number = params[:number].to_i
    script, result, output = Bio::Shell.cache[:results].restore(number)
    class_name = result.class
    @class = class_name
    @classes = []
    loop do
      @classes.unshift(class_name)
      if class_name == Object
        break
      else
        class_name = class_name.superclass
      end
    end

    render :update do |page|
      page.replace_html "classes_#{number}", :partial => "classes"
      page.visual_effect :toggle_blind, "classes_#{number}", :duration => 0.5
    end
  end

  def list_modules
    number = params[:number].to_i
    script, result, output = Bio::Shell.cache[:results].restore(number)
    @class = result.class
    @modules = result.class.included_modules - HIDE_MODULES

    render :update do |page|
      page.replace_html "modules_#{number}", :partial => "modules"
      page.visual_effect :toggle_blind, "modules_#{number}", :duration => 0.5
    end
  end

  def results
    if Bio::Shell.cache[:results].number > 0
      limit = params[:limit].to_i
      max_num = Bio::Shell.cache[:results].number
      min_num = [ max_num - limit + 1, 1 ].max
      min_num = 1 if limit == 0

      render :update do |page|
        # delete all existing results in the current DOM for clean up
        page.select(".evaluate").each do |element|
          page.remove element
        end

        # add selected results to the current DOM
        min_num.upto(max_num) do |@number|
          @script, @result, @output = Bio::Shell.cache[:results].restore(@number)
          if @script
            page.insert_html :after, "console", :partial => "result"
            page.replace_html "variables", :partial => "variables"
            page.hide "methods_#{@number}"
            page.hide "classes_#{@number}"
            page.hide "modules_#{@number}"
          end
        end
      end
    end
  end

  def commands
    @bioruby_commands = Bio::Shell.private_instance_methods.sort
  end

  def history
    @history = File.readlines(Bio::Shell.history_file)
  end

end


--- NEW FILE: bioruby.png ---
(This appears to be a binary file; contents omitted.)




More information about the bioruby-cvs mailing list