You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
asciinema.org/app/helpers/asciicasts_helper.rb

43 lines
1.1 KiB
Ruby

module AsciicastsHelper
def player_script(asciicast, options = {})
speed = (options[:speed] || 1).to_f
benchmark = !!params[:bm]
auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false
hud = options.key?(:hud) ? !!options[:hud] : true
if params[:fallback]
klass = "AsciiIo.FallbackPlayer"
else
klass = "window.Worker && $.browser.webkit ? " \
"AsciiIo.Player : AsciiIo.FallbackPlayer"
end
if custom_renderer = params[:renderer]
renderer_class = "AsciiIo.Renderer.#{custom_renderer.capitalize}"
else
renderer_class = "AsciiIo.Renderer.Pre"
end
return <<EOS.html_safe
<script>
$(function() {
var playerClass = #{klass};
window.player = new playerClass({
el: $('.player'),
cols: #{asciicast.terminal_columns},
lines: #{asciicast.terminal_lines},
speed: #{speed},
benchmark: #{benchmark},
model: new AsciiIo.Asciicast({ id: #{asciicast.id} }),
rendererClass: #{renderer_class},
autoPlay: #{auto_play},
hud: #{hud},
snapshot: "#{j asciicast.snapshot.to_s}"
});
});
</script>
EOS
end
end