2011-11-23 21:30:09 +00:00
|
|
|
module AsciicastsHelper
|
2011-11-27 12:54:10 +00:00
|
|
|
|
2012-03-04 14:18:09 +00:00
|
|
|
def asciicast_title(asciicast)
|
|
|
|
if asciicast.title.present?
|
|
|
|
asciicast.title
|
|
|
|
elsif asciicast.command.present?
|
|
|
|
"$ #{asciicast.command}"
|
|
|
|
else
|
|
|
|
"##{asciicast.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-03-10 13:56:25 +00:00
|
|
|
def profile_link(asciicast, options = {})
|
2012-03-04 19:59:53 +00:00
|
|
|
if asciicast.user
|
2012-03-10 13:56:25 +00:00
|
|
|
if options[:avatar]
|
|
|
|
img = avatar_img(asciicast.user) + " "
|
|
|
|
else
|
|
|
|
img = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
link_to img + "~#{asciicast.user.nickname}", profile_path(asciicast.user)
|
2012-04-03 17:06:05 +00:00
|
|
|
else
|
|
|
|
if asciicast.username.present?
|
|
|
|
"~#{asciicast.username}"
|
|
|
|
else
|
|
|
|
"anonymous"
|
|
|
|
end
|
2012-03-04 19:59:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def asciicast_time(asciicast)
|
|
|
|
time_ago_in_words(asciicast.created_at) + " ago"
|
|
|
|
end
|
|
|
|
|
2012-03-11 09:30:21 +00:00
|
|
|
def player_script(asciicast, options = {})
|
2012-03-16 19:43:32 +00:00
|
|
|
speed = (params[:speed] || 1).to_f
|
|
|
|
benchmark = !!params[:bm]
|
2012-03-11 09:30:21 +00:00
|
|
|
auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false
|
|
|
|
|
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
|
2011-11-27 13:24:12 +00:00
|
|
|
<script>
|
2012-02-07 09:42:57 +00:00
|
|
|
$(function() {
|
|
|
|
window.player = new AsciiIo.PlayerView({
|
|
|
|
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-03-11 09:30:21 +00:00
|
|
|
autoPlay: #{auto_play}
|
2012-02-07 09:42:57 +00:00
|
|
|
});
|
|
|
|
});
|
2011-11-27 13:24:12 +00:00
|
|
|
</script>
|
|
|
|
EOS
|
2011-11-27 12:54:10 +00:00
|
|
|
end
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|