asciinema.org/app/helpers/asciicasts_helper.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2011-11-23 21:30:09 +00:00
module AsciicastsHelper
2011-11-27 12:54:10 +00:00
2012-11-19 20:30:45 +00:00
def player_script_tag(asciicast, options = {})
2012-07-28 18:33:10 +00:00
speed = (options[:speed] || 1).to_f
2012-03-16 19:43:32 +00:00
benchmark = !!params[:bm]
2012-03-11 09:30:21 +00:00
auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false
2012-07-28 18:59:38 +00:00
hud = options.key?(:hud) ? !!options[:hud] : true
2012-03-11 09:30:21 +00:00
if params[:fallback]
2012-08-02 21:47:06 +00:00
klass = "AsciiIo.FallbackPlayer"
else
2012-08-25 13:15:13 +00:00
klass = "window.Worker && $.browser.webkit ? " \
"AsciiIo.Player : AsciiIo.FallbackPlayer"
end
2012-03-15 08:53:26 +00:00
if custom_renderer = params[:renderer]
renderer_class = "AsciiIo.Renderer.#{custom_renderer.capitalize}"
else
renderer_class = "AsciiIo.Renderer.Pre"
end
2012-03-03 17:38:11 +00:00
return <<EOS.html_safe
<script>
2012-02-07 09:42:57 +00:00
$(function() {
2012-08-02 21:47:06 +00:00
var playerClass = #{klass};
window.player = new playerClass({
2012-02-07 09:42:57 +00:00
el: $('.player'),
2012-03-03 17:38:11 +00:00
cols: #{asciicast.terminal_columns},
lines: #{asciicast.terminal_lines},
2012-03-16 19:43:32 +00:00
speed: #{speed},
benchmark: #{benchmark},
2012-03-11 09:30:21 +00:00
model: new AsciiIo.Asciicast({ id: #{asciicast.id} }),
2012-03-15 08:53:26 +00:00
rendererClass: #{renderer_class},
2012-05-29 20:49:30 +00:00
autoPlay: #{auto_play},
2012-07-28 18:59:38 +00:00
hud: #{hud},
2012-05-29 20:49:30 +00:00
snapshot: "#{j asciicast.snapshot.to_s}"
2012-02-07 09:42:57 +00:00
});
});
</script>
EOS
2011-11-27 12:54:10 +00:00
end
2011-11-23 21:30:09 +00:00
end