Skip to content
Browse files

Added Executable Haskell support

  • Loading branch information...
1 parent 00773cd commit 3cebbec547897756077017f687eb60967e98606b @chriseidhof committed Sep 29, 2012
Showing with 50 additions and 0 deletions.
  1. +7 −0 example/two/slidesA.md
  2. +18 −0 lib/ghci-wrapper.rb
  3. +12 −0 lib/showoff.rb
  4. +13 −0 public/js/showoff.js
View
7 example/two/slidesA.md
@@ -39,6 +39,13 @@
!SLIDE execute
+# Executable Haskell #
+
+ @@@ haskell
+ 10 * 10
+
+!SLIDE execute
+
# Executable Ruby #
@@@ ruby
View
18 lib/ghci-wrapper.rb
@@ -0,0 +1,18 @@
+class GHCi
+ def initialize
+ @interpreter = IO.popen('ghci', 'r+')
+ 4.times { puts @interpreter.gets }
+ end
+ def evaluate(str)
+ @interpreter.puts str
+ line = @interpreter.gets
+ line.slice!(/.*> /)
+ line.strip
+ end
+end
+
+interpreter = GHCi.new
+puts '----'
+puts interpreter.evaluate ":t \"Chris\""
+puts '----'
+puts interpreter.evaluate "sum [1..(10::Int)]"
View
12 lib/showoff.rb
@@ -8,6 +8,7 @@
here = File.expand_path(File.dirname(__FILE__))
require "#{here}/showoff_utils"
require "#{here}/commandline_parser"
+require "#{here}/ghci-wrapper"
begin
require 'RMagick'
@@ -575,12 +576,23 @@ def eval_ruby code
e.message
end
+ def eval_haskell code
+ $ghci ||= GHCi.new
+ $ghci.evaluate(code)
+ end
+
get '/eval_ruby' do
return eval_ruby(params[:code]) if ENV['SHOWOFF_EVAL_RUBY']
return "Ruby Evaluation is off. To turn it on set ENV['SHOWOFF_EVAL_RUBY']"
end
+ get '/eval_haskell' do
+ return eval_haskell(params[:code]) if ENV['SHOWOFF_EVAL_RUBY']
+
+ return "Ruby Evaluation is off. To turn it on set ENV['SHOWOFF_EVAL_RUBY']"
+ end
+
get %r{(?:image|file)/(.*)} do
path = params[:captures].first
full_path = File.join(settings.pres_dir, path)
View
13 public/js/showoff.js
@@ -352,6 +352,10 @@ function executeAnyCode()
if ($coffeeCode.length > 0) {
executeCoffee.call($coffeeCode);
}
+ var $haskellCode = $('.execute .sh_haskell code:visible')
+ if ($haskellCode.length > 0) {
+ executeHaskell.call($haskellCode);
+ }
}
function debug(data)
@@ -550,6 +554,15 @@ function executeRuby () {
});
}
$('.execute .sh_ruby code').live("click", executeRuby);
+function executeHaskell () {
+ var codeDiv = $(this);
+ codeDiv.addClass("executing");
+ $.get('/eval_haskell', {code: codeDiv.text()}, function(result) {
+ if (result != null) print(result);
+ codeDiv.removeClass("executing");
+ });
+}
+$('.execute .sh_haskell code').live("click", executeHaskell);
function executeCoffee() {
result = null;

0 comments on commit 3cebbec

Please sign in to comment.
Something went wrong with that request. Please try again.