Permalink
Browse files

Added support for coffeescript.

* Language definition is far from perfect. (sh_coffeescript.min.js)
* Added support for executing the code.
* Added example slide.
  • Loading branch information...
1 parent 76c8e30 commit 72d76d249e04c0a4dc07ab0db833877b519bab16 @andersjanmyr andersjanmyr committed Aug 11, 2011
Showing with 35 additions and 0 deletions.
  1. +10 −0 example/two/slidesA.md
  2. +8 −0 public/js/coffee-script.js
  3. +1 −0 public/js/sh_lang/sh_coffeescript.min.js
  4. +15 −0 public/js/showoff.js
  5. +1 −0 views/index.erb
@@ -32,6 +32,16 @@
@@@ ruby
result = [1, 2, 3].map { |n| n*7 }
+!SLIDE execute
+# Executable Coffeescript #
+
+ @@@coffeescript
+ add = (a, b) ->
+ "#{a}+#{b} is #{a+b}"
+
+ result = add 2, 3
+
+
!SLIDE
# Write your own slides #
Oops, something went wrong.
@@ -0,0 +1 @@
+if(!this.sh_languages){this.sh_languages={}}sh_languages.coffeescript=[[[/\b(?:require)\b/g,"sh_preproc",-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/"/g,"sh_string",1],[/'/g,"sh_string",2],[/\/[^\n]*\//g,"sh_regexp",-1],[/(%r)(\{(?:\\\}|#\{[A-Za-z0-9]+\}|[^}])*\})/g,["sh_symbol","sh_regexp"],-1],[/\b(?:and|arguments|break|by|catch|continue|class|delete|do|else|extends|false|finally|for|if|in|instanceof|is|isnt|loop|new|no|not|null|of|off|on|or|own|prototype|return|switch|super|then|this|throw|true|try|typeof|undefined|unless|until|when|while|yes)\b/g,"sh_keyword",-1],[/(?:\$[#]?|@@|@)(?:[A-Za-z0-9_]+|'|\"|\/)/g,"sh_type",-1],[/[A-Za-z0-9]+(?:\?|!)/g,"sh_normal",-1],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/(#)(\{)/g,["sh_symbol","sh_cbracket"],-1],[/#/g,"sh_comment",3],[/\/(?:\\.|[^*\\\/])(?:\\.|[^\\\/])*\/[gim]*/g,"sh_regexp",-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/"/g,"sh_string",4],[/'/g,"sh_string",5],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/\{|\}/g,"sh_cbracket",-1],[/(?:[A-Za-z]|_)[A-Za-z0-9_]*(?=[ \t]*\()/g,"sh_function",-1]],[[/$/g,null,-2],[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/$/g,null,-2],[/\\(?:\\|')/g,null,-1],[/'/g,"sh_string",-2]],[[/$/g,null,-2]],[[/"/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]],[[/'/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]]];
View
@@ -345,6 +345,10 @@ function keyDown(event)
if ($rubyCode.length > 0) {
executeRuby.call($rubyCode);
}
+ var $coffeeCode = $('.execute .sh_coffeescript code:visible')
+ if ($coffeeCode.length > 0) {
+ executeCoffee.call($coffeeCode);
+ }
}
}
@@ -508,6 +512,17 @@ function executeRuby () {
}
$('.execute .sh_ruby code').live("click", executeRuby);
+function executeCoffee() {
+ result = null;
+ var codeDiv = $(this);
+ codeDiv.addClass("executing");
+ // Coffeescript encapsulates everything, so result must be attached to window.
+ var code = codeDiv.text() + ';window.result=result;'
+ eval(CoffeeScript.compile(code));
+ setTimeout(function() { codeDiv.removeClass("executing");}, 250 );
+ if (result != null) print(result);
+}
+$('.execute .sh_coffeescript code').live("click", executeCoffee);
/********************
PreShow Code
View
@@ -24,6 +24,7 @@
<script type="text/javascript" src="<%= @asset_path %>js/sh_main.min.js"></script>
<script type="text/javascript" src="<%= @asset_path %>js/core.js"></script>
<script type="text/javascript" src="<%= @asset_path %>js/showoffcore.js"></script>
+ <script type="text/javascript" src="<%= @asset_path %>js/coffee-script.js"></script>
<link type="text/css" href="<%= @asset_path %>css/fg.menu.css" media="screen" rel="stylesheet" />
<link type="text/css" href="<%= @asset_path %>css/theme/ui.all.css" media="screen" rel="stylesheet" />

0 comments on commit 72d76d2

Please sign in to comment.