2011-11-23 21:30:09 +00:00
|
|
|
module AsciicastsHelper
|
2011-11-27 12:54:10 +00:00
|
|
|
|
2012-11-19 21:01:44 +00:00
|
|
|
def player(asciicast, options = {})
|
2012-08-01 20:53:10 +00:00
|
|
|
if params[:fallback]
|
2013-09-23 17:05:36 +00:00
|
|
|
player_class = "Asciinema.FallbackPlayer"
|
2012-08-01 20:53:10 +00:00
|
|
|
else
|
2013-09-23 17:05:36 +00:00
|
|
|
player_class = "window.Worker ? Asciinema.Player : Asciinema.FallbackPlayer"
|
2012-08-01 20:53:10 +00:00
|
|
|
end
|
|
|
|
|
2012-03-15 08:53:26 +00:00
|
|
|
if custom_renderer = params[:renderer]
|
2013-09-23 17:05:36 +00:00
|
|
|
renderer_class = "Asciinema.Renderer.#{custom_renderer.capitalize}"
|
2012-03-15 08:53:26 +00:00
|
|
|
else
|
2013-09-23 17:05:36 +00:00
|
|
|
renderer_class = "Asciinema.Renderer.Pre"
|
2012-03-15 08:53:26 +00:00
|
|
|
end
|
|
|
|
|
2012-11-19 21:01:44 +00:00
|
|
|
render :partial => 'asciicasts/player', :locals => {
|
2013-09-20 21:21:25 +00:00
|
|
|
asciicast: serialized_asciicast(asciicast),
|
2012-11-19 21:01:44 +00:00
|
|
|
player_class: player_class,
|
|
|
|
speed: (options[:speed] || params[:speed] || 1).to_f,
|
|
|
|
benchmark: !!params[:bm],
|
2013-06-12 21:50:31 +00:00
|
|
|
container_width: params[:container_width],
|
2012-11-19 21:01:44 +00:00
|
|
|
renderer_class: renderer_class,
|
|
|
|
auto_play: options.key?(:auto_play) ? !!options[:auto_play] : false,
|
2013-09-20 21:21:25 +00:00
|
|
|
hud: options.key?(:hud) ? !!options[:hud] : true
|
2012-11-19 21:01:44 +00:00
|
|
|
}
|
2011-11-27 12:54:10 +00:00
|
|
|
end
|
2012-11-19 21:27:52 +00:00
|
|
|
|
|
|
|
def link_to_delete_asciicast(name, asciicast)
|
2013-08-25 14:34:02 +00:00
|
|
|
link_to name, asciicast_path(asciicast), :method => :delete,
|
|
|
|
:data => { :confirm => 'Really delete this asciicast?' }
|
2012-11-19 21:27:52 +00:00
|
|
|
end
|
|
|
|
|
2013-09-20 21:21:25 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def serialized_asciicast(asciicast)
|
|
|
|
AsciicastSerializer.new(asciicast).to_json
|
|
|
|
end
|
|
|
|
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|