In [74]:
from IPython.core.display import HTML, Javascript
from IPython.core import display
Installed coffee script using npm
Following is the directory structure that we are going to follow for this tutorial.
In [6]:
!ls *b
In [2]:
!coffee -v
In [1]:
!coffee -h
In [3]:
expr = "square = (x) -> x*x"
In [4]:
!coffee -c -e "$expr"
In [5]:
!coffee -b -c -e "$expr"
In [2]:
src = "tutorial/src"
lib = "tutorial/jslib"
In [51]:
%%writefile "$src/cs0.coffee"
square = (x) -> x * x
In [52]:
!coffee --no-header -b -p -c "$src/cs0.coffee"
In [53]:
!coffee -o "$lib" -c "$src/cs0.coffee"
In [3]:
!cat "$lib/cs0.js"
In [57]:
!ls * -R
In [81]:
%%writefile "$src/cs1.coffee"
fill = (container, liquid="water") -> "Filling the #{container} with #{liquid}"
In [87]:
!coffee -b -o "$lib" -c "$src/cs1.coffee"
#!cat "$lib/cs1.js"
Failed experiment
First load the java script file and then add the javascript cell magic.
In [134]:
%%javascript
//# %load "tutorial/lib/cs1.js"
// Generated by CoffeeScript 1.12.3
var fill;
fill = function(container, liquid) {
if (liquid == null) {
liquid = "water";
}
return "Filling the " + container + " with " + liquid;
};
alert(fill("Cups"));
What I have observed is that the load magic command substitutes the variable expansion!!
Is there a way to not let this happen?
In [128]:
%%writefile "$src/cs2.coffee"
song = ['do', 're', 'mi', 'fa', 'so']
singers = { Jagger: "Rock", Elvis: "Roll"}
bitlist = [
1, 0, 1
0, 0, 1
1, 1, 0
]
kids =
brother: name: "max", age: 11
sister:
name: "Ida"
age: 9
In [129]:
!coffee -b --no-header -o "$lib" -c "$src/cs2.coffee"
!cat "$lib/cs2.js"
In [120]:
%%writefile "$src/cs3.coffee"
$('.account').attr class: 'active'
In [122]:
!coffee -b --no-header -o "$lib" -c "$src/cs3.coffee"
!cat "$lib/cs3.js"
In [132]:
%%writefile "$src/cs4.coffee"
name = "Jim Carrey"
mask = "The Mask"
weapon = "Laughter"
superhero = {name, mask, weapon}
output = "#{turtle.name} wears an #{turtle.mask} as a mask. Watch out for his #{turtle.weapon}!"
In [133]:
!coffee -b -o "$lib" -c "$src/cs4.coffee"
!cat "$lib/cs4.js"
In [136]:
%%writefile "$src/cs5.coffee"
outer = 1
changeNumbers = ->
inner = -1
outer = 10
inner = changeNumbers()
In [138]:
!coffee -b -o "$lib" -c "$src/cs5.coffee"
!cat "$lib/cs5.js"
In [ ]:
#%%javascript
%load "$lib/cs1.js"
Why is the following command hanging the kernel?
!coffee -wbcp "$srcLoc"
!cat "$lib/cs1.js" | pygmentize
html = !pygmentize -f html -l js "$lib/cs1.js" HTML("\n".join(html))