asciinema.org/app/helpers/asciicasts_helper.rb

42 lines
1.2 KiB
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(asciicast, options = {})
if params[:fallback]
player_class = "Asciinema.FallbackPlayer"
else
2013-10-20 15:29:19 +00:00
player_class =
"window.Worker ? Asciinema.Player : Asciinema.FallbackPlayer"
end
2012-03-15 08:53:26 +00:00
if custom_renderer = params[:renderer]
renderer_class = "Asciinema.Renderer.#{custom_renderer.capitalize}"
2012-03-15 08:53:26 +00:00
else
renderer_class = "Asciinema.Renderer.Pre"
2012-03-15 08:53:26 +00:00
end
render :partial => 'asciicasts/player', :locals => {
asciicast: serialized_asciicast(asciicast),
player_class: player_class,
speed: (options[:speed] || params[:speed] || 1).to_f,
benchmark: !!params[:bm],
container_width: params[:container_width],
renderer_class: renderer_class,
auto_play: options.key?(:auto_play) ? !!options[:auto_play] : false,
hud: options.key?(:hud) ? !!options[:hud] : true,
size: params[:size] || 'small'
}
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
private
def serialized_asciicast(asciicast)
AsciicastSerializer.new(asciicast).to_json
end
2011-11-23 21:30:09 +00:00
end