Inspired by Literate CoffeeScript.
$ cat hello.litrb
Here's a simple program
puts "Hello, world"
$ ruby litrb.rb < hello.litrb
Hello, world
<html> | |
<head> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script> | |
</head> | |
<body> | |
<div id='chart'></div> | |
<script src='https://data.itpir.wm.edu//codes/pcwheel.js'></script> | |
</body> |
{"all_activity_children":544,"all_children":788,"children":[{"all_activity_children":216,"all_children":296,"children":[{"all_activity_children":53,"all_children":71,"children":[{"all_activity_children":0,"all_children":0,"children":[],"code":"11000","name":"Education, combinations of purposes","parent":"110","type":"purpose","updated_at":"2013-02-04T19:56:57Z"},{"all_activity_children":19,"all_children":25,"children":[{"all_activity_children":0,"all_children":0,"children":[],"code":"11100","name":"Education, level unspecified, combinations of purposes","parent":"111","type":"purpose","updated_at":"2013-02-04T19:56:57Z"},{"all_activity_children":1,"all_children":1,"children":[{"all_activity_children":0,"all_children":0,"children":[],"code":"11105.01","name":"Education, level unspecified, activity unspecified or does not fit under any other applicable codes","parent":"11105","type":"activity","updated_at":"2013-02-04T19:56:55Z"}],"code":"11105","name":"Education, level unspecified, purpose unspecified or does |
Inspired by Literate CoffeeScript.
$ cat hello.litrb
Here's a simple program
puts "Hello, world"
$ ruby litrb.rb < hello.litrb
Hello, world
{ | |
"doc" : "data:image/gif;base64,R0lGODlhEAAQANUgANvh8gZCm0RrvGCAylhwppOr5rnI7XmT1oCe5jJVmT1otmeK1TVesgg4ia672IOc2ipit4uk3Vd90E52y3eKnGd+syg+bfDy+oml6U1qpwlLsgU2goSEhMbGxgAAAP///////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAACAALAAAAAAQABAAAAaIQJCQQywahUgQ58NsMjkeYaGAQRwWkokA8oSCCk6nhukpexCGxwCwJkQ0nfincwaoAQJAhjKezz0HHwcCDgkRCQYBHX50Cx8VAgQbDBYfioweEh8EiBsbDh8NcYt0Ex+TFxsKTBtOdKthrKN/EBq2AbgNnq5RQ2GjpL1KsbxIHMDIccJQZs3NQQA7", | |
"xls" : "data:image/gif;base64,R0lGODlhEAAQAMQfADRMGDhsIDRiFGuuZVWWRUiLOJXDkEaELDt3HI+8ij19I2SnXTNZFV6OVs3bzP79+trl2nOkb6CynpuvmoaohG+abOTr5FygVTJsDQoKCoSEhP7+/sbGxgAAAP///////yH5BAEAAB8ALAAAAAAQABAAAAWL4CdqZGmK6Kd57MOyWicOw3IRRHEoCPzIg41wKMSwMh3kwLAgbByNywTDqXo4mYXFMDhELgWI8XrtXJ6GiyLA2QiqnGvGmbikAxWIgBXndAoJCAECCQUBEgxwcgdEFIMNAC9lCkREkWR+CBibAgwMAKB9cigrcH1WfqSSq2Wkpq9VMiMdSbS0GUhIIQA7", | |
"ppt" : "data:image/gif;base64,R0lGODlhEAAQANUgAO+TaZQ4LY8zJpE6M/CXXdd/XsdzV8VoTYcsJ9uDYvCkb//8+X0iGv |
nice_money = (amount, options={}) -> | |
# Props to akmiller for original code -- I'm using it all the time though so hosting it here. | |
full_label = options.full_label || false | |
if d3? | |
if 1000 >= amount | |
label = "" | |
money = "#{d3.format("0,r")(d3.round(amount,0))}" | |
else if 1000000 > amount >= 1000 | |
label = (if full_label then "Thousand" else "K" ) | |
money = "#{d3.round((amount/1000),0)}" |
split_to_fit = (string, allowable_width) -> | |
# console.log("splitting '#{string}' to fit #{allowable_width}") | |
splitters = [' ', ',', '-', '.'] # allowable splitters | |
new_strings = [] | |
for w in [allowable_width..0] | |
# console.log("trying width=#{w}, which returns '#{string[w]}'") | |
if string[w] in splitters | |
# console.log("found a splitter at #{w} in #{string}") | |
if string[w] is ' ' | |
end_of_word = w-1 |
(function() { | |
Batman.extend(Batman.DOM, { | |
querySelectorAll: function(node, selector) { | |
return jQuery(selector, node); | |
}, | |
querySelector: function(node, selector) { | |
return jQuery(selector, node)[0]; | |
}, | |
setInnerHTML: function(node, html) { | |
return jQuery(node).html(html); |
Submarine = -> | |
# "private", within function scope but not attached to the new instance | |
secretWeapon = "missiles" | |
fireSecretWeapon = -> console.log "fire ze " + secretWeapon | |
# "public", attached to the new instance | |
@reveal = -> secretWeapon | |
@setWeapon = (weapon) -> | |
secretWeapon = weapon | |
@fire = -> fireSecretWeapon() | |
@ |
class Tophat | |
dimensions: {height: 50, circumference: 20} | |
color: "black" | |
tpains_hat = new Tophat | |
tpains_hat.dimensions.height = 120 | |
tpains_hat.color = "#f59145" | |
lincolns_hat = new Tophat | |
console.log lincolns_hat.color # => "black" |