Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #110 from andersjanmyr/coffeescript

Added support for coffeescript.
  • Loading branch information...
commit 25917f8bcb7c7aeb9f6486fc4af22395b1363ab5 2 parents 2378db6 + 727498d
@schacon authored
View
6 README.rdoc
@@ -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
View
10 example/two/slidesA.md
@@ -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 #
View
8 public/js/coffee-script.js
8 additions, 0 deletions not shown
View
1  public/js/sh_lang/sh_coffeescript.min.js
@@ -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
15 public/js/showoff.js
@@ -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
1  views/index.erb
@@ -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" />
Please sign in to comment.
Something went wrong with that request. Please try again.