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 < $(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}" }); }); EOS end end