davidmiani / tryruby Goto Github PK
View Code? Open in Web Editor NEWThis project forked from sophrinix/tryruby
Try Ruby is _why's interactive ruby shell that ran on on tryruby.hobix.com
Home Page: tryruby.sophrinix.com
This project forked from sophrinix/tryruby
Try Ruby is _why's interactive ruby shell that ran on on tryruby.hobix.com
Home Page: tryruby.sophrinix.com
TRYRUBY! is now 1.9 ready and hosted using 1.9. Please note this is beta software. Copyright (c) 2009 Andrew McElroy index.html is Copyright (c) 2009 _why test.rb, tryruby_runner.rb Copyright (c) 2009 David Miani Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. What is TryRuby? -------------------------------------------------------------------------------------- Try Ruby is a interactive shell that quickly and whimsically teaches the Ruby programming language. Originally _why's idea, it has been recreated from the ground up by Rubists who have a passion for Ruby and for teaching their fellow (wo)man how to program. Please note that If you feel like you are stuck in the middle of a lesson try typing: next Doing so will skip to to the next part of the less/next lesson UPDATE: EXPECT TO SEE THIS CHANGE IN THE NEXT FEW DAYS. I AM LOOKING INTO A SQLITE STORE OPTION. The sessions are now stored in a tmp folder. For the time being it is within the htdoc path. I know this is bad. I have included an index.html that redirects you back to the home page in the mean time. Ideally, I need to put this some place like /var/logs/tryruby. from there I will see about the viability of making this use the r bridge so you can have ruby to R lessons. :-) Explaination of /irb.cgi ======================== The only part of the TryRuby implementation that wasn't able to be recovered from archive.org is the /irb file (or /irb.cgi currently, you can change the name of the file used in js/irb.js). This script should: - Take one GET param "cmd", which will contain a single line of ruby to run. It can also be "!INIT!IRB", which is called at the start of the session. The current implementation of irb.cgi ignores this. "reset" should also do something special (but doesn't atm). - Return the output, optionally formatted using normal shell escapes (eg "\033[1;33mThis appears orange") The output has four main formats for returning a result, error output, javascript function and line continuation. This is used by the help system so that it can detect when a user has entered the next step for the tutorial. Output results should be formatted with a "=> " at the front of the output. For example: /irb.cgi?cmd=3*4 should output "=> 12". Shell escape codes can be used to give the output different colors, for example "=> \033[1;20m12". This will automatically be removed when used with the help system. Note that you don't and shouldn't terminate these shell escapes with \033[m (like with a normal shell). Standard output should not be prefixed by =>, so /irb.cgi?cmd=puts(44) should output "44\n=> nil". Here 44 is output, and nil is returned. Again shell escapes can be used. Errors should be formated just like standard output, however it should have no return. For example, /irb.cgi?cmd=non_existant_function should output something like "\033[1;33mNameError: undefined local variable or method `non_existant_function' for main:Object". Javascript functions (such as Popup.goto) should use the format "\033[1;JsmJAVASCRIPT CODE\033[m". The javascript cod will then be run. For example, /irb.cgi?cmd=Popup.goto("http://www.google.com") should output \033[1;JSmwindow.irb.options.popup_goto("http://www.google.com")\033[m. Finally, if the command isn't finished (eg "def myfunc"), then ".." should be returned. Eg /irb.cgi?cmd=def%20myfunc should return "..". How this works with the help system: ==================================== The help system works with the file /tutorials/intro.html . There is a <div class="stretcher"> section for each part of the tutorial. Most of it is just the text for that part of the tutorial. However, there is also a <div class="answer|stdout">regex</div> section. If this matches against the output for a command, then the tutorial will go to the next step. When the class is "answer", then it will match against lines beginning with "=>". So <div class="answer">\d+</div> will match any code that returns a number. Other output can be shown as well, eg "someoutput\n=> 42" will match this. The exact regexp is '^\s*=> match_regex_from_help\s*$'. So the line must be an exact match, other than spaces and the initial => When the class is "stdout", the match must work on a complete line. Eg <div class="stdout">hello</div> will match "hello", or "start\n hello\ngoodbye" (leading spaces are ignored, and multiple lines are searched. The exact regex is '^\s*match_regex_from_help$' As a special case, if the tutorial expects that a command isn't finished (such as with def myfunc), then it <div class="stdout">..</div> will be used. This is changed from the original implementation _why used, which was <div class="stdout"></div> as I couldn't get it to work like that. Another special case, if the return should some javascript code, then something like '<div class="stdout">\033\[1;JSm.*popup_goto\(.*\)\033\[m.*</div>' will be used Current Implementation ====================== The current implementation doesn't use persistent processes like irb. What it does is it stores all previous successfully run commands in session['previous_commands'], and runs them all first (disabling stdout). Then it will finally run the command. It uses a primitive method of detecting incomplete statements (with the function unfinished_statement?) and when a incomplete statement is finished (finished_statement?). The current nesting level (eg "class X" then "def myfunc" will having a nesting level of 2) is stored in $session['nesting_level']. All the lines of the current incomplete statement are stored in $session['current_statement']. To work with javascript functions, a special class JavascriptResult was written, with one accessor :js. If the result of an eval returns this object, then the output will be formatted in the javascript method.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.