asciinema.org/app/helpers/asciicasts_helper.rb

38 lines
828 B
Ruby
Raw Normal View History

2011-11-23 21:30:09 +00:00
module AsciicastsHelper
2011-11-27 12:54:10 +00:00
def player_data(asciicast)
2012-01-19 21:45:21 +00:00
data = `bzip2 -d -c #{asciicast.stdout.path}`
time = `bzip2 -d -c #{asciicast.stdout_timing.path}`
2011-11-27 12:54:10 +00:00
data_hex_array = data.bytes.map { |b| '\x' + format('%02x', b) }
var_data = "'#{data_hex_array.join}'"
time_lines = time.lines.map do |line|
delay, n = line.split
"[#{delay.to_f}, #{n.to_i}]"
end
var_time = "[#{time_lines.join(',')}]"
<<EOS.html_safe
<script>
var data = #{var_data};
var time = #{j var_time};
var cols = #{asciicast.terminal_columns};
var lines = #{asciicast.terminal_lines};
2012-02-07 09:42:57 +00:00
$(function() {
window.player = new AsciiIo.PlayerView({
el: $('.player'),
cols: cols,
lines: lines,
data: data,
timing: time
});
window.player.play();
});
</script>
EOS
2011-11-27 12:54:10 +00:00
end
2011-11-23 21:30:09 +00:00
end