Permalink
Browse files

Merge pull request #110 from andersjanmyr/coffeescript

Added support for coffeescript.
  • Loading branch information...
2 parents 2378db6 + 727498d commit 25917f8bcb7c7aeb9f6486fc4af22395b1363ab5 @schacon committed Sep 10, 2011
Showing with 38 additions and 3 deletions.
  1. +3 −3 README.rdoc
  2. +10 −0 example/two/slidesA.md
  3. +8 −0 public/js/coffee-script.js
  4. +1 −0 public/js/sh_lang/sh_coffeescript.min.js
  5. +15 −0 public/js/showoff.js
  6. +1 −0 views/index.erb
View
@@ -18,7 +18,7 @@ It can:
* bullets with incremental advancing
* re-enact command line interactions
* call up a menu of sections/slides at any time to jump around
-* execute javascript or ruby live and display results
+* execute Javascript, Coffeescript or Ruby live and display results
* do simple transitions (instant, fade, slide in)
* show a pre-show slideshow while you wait to start
@@ -128,7 +128,7 @@ Some useful styles for each slide are:
* incremental - can be used with 'bullets' and 'commandline' styles, will incrementally update elements on arrow key rather than switch slides
* small - make all slide text 80%
* smaller - make all slide text 70%
-* execute - on js highlighted code slides, you can click on the code to execute it and display the results on the slide
+* execute - on Javascript, Coffeescript and Ruby highlighted code slides, you can click on the code to execute it and display the results on the slide
Check out the example directory included to see examples of most of these.
@@ -297,7 +297,7 @@ and colorful.
= Custom Ruby Files
If you want to have executable Ruby code on your slides you must set the
-envrionment variable ENV['SHOWOFF_EVAL_RUBY']. This can be done with
+environment variable ENV['SHOWOFF_EVAL_RUBY']. This can be done with
export SHOWOFF_EVAL_RUBY=1
@@ -44,6 +44,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
@@ -346,6 +346,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);
+ }
}
}
@@ -509,6 +513,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 25917f8

Please sign in to comment.