asciinema.org/app/helpers/asciicasts_helper.rb

64 lines
1.5 KiB
Ruby
Raw Normal View History

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 = {})
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)
else
if asciicast.username.present?
"~#{asciicast.username}"
else
"anonymous"
end
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
<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
});
});
</script>
EOS
2011-11-27 12:54:10 +00:00
end
2011-11-23 21:30:09 +00:00
end