2011-11-23 21:30:09 +00:00
|
|
|
module AsciicastsHelper
|
2011-11-27 12:54:10 +00:00
|
|
|
|
2015-10-08 09:55:14 +00:00
|
|
|
def player(asciicast, options = PlaybackOptions.new, skip_titlebar = false)
|
2015-12-22 17:40:20 +00:00
|
|
|
render 'asciicasts/player',
|
2016-01-19 10:27:38 +00:00
|
|
|
asciicast: AsciicastSerializer.new(asciicast, v0: options.v0),
|
2015-12-22 17:40:20 +00:00
|
|
|
options: options,
|
|
|
|
skip_titlebar: skip_titlebar
|
2011-11-27 12:54:10 +00:00
|
|
|
end
|
2012-11-19 21:27:52 +00:00
|
|
|
|
2016-02-06 11:26:05 +00:00
|
|
|
def player_tag(asciicast, options, skip_titlebar)
|
|
|
|
opts = {
|
|
|
|
src: asciicast.url,
|
|
|
|
cols: asciicast.width,
|
|
|
|
rows: asciicast.height,
|
|
|
|
poster: 'data:application/json;base64,' + Base64.encode64(asciicast.snapshot.to_json),
|
|
|
|
speed: options.speed,
|
|
|
|
autoplay: options.autoplay,
|
|
|
|
loop: options.loop,
|
|
|
|
'start-at' => options.t,
|
|
|
|
'font-size' => options.size,
|
|
|
|
theme: options.theme,
|
|
|
|
}
|
|
|
|
|
|
|
|
unless skip_titlebar
|
|
|
|
opts.merge!(
|
|
|
|
title: asciicast.title,
|
|
|
|
author: asciicast.author_display_name,
|
|
|
|
'author-url' => asciicast.author_url,
|
|
|
|
'author-img-url' => asciicast.author_avatar_url,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
content_tag('asciinema-player', '', opts)
|
|
|
|
end
|
|
|
|
|
2015-03-27 11:35:34 +00:00
|
|
|
def screenshot_javascript_tag
|
|
|
|
js = assets.find_asset('embed.js').to_s
|
|
|
|
content_tag(:script, js.html_safe)
|
|
|
|
end
|
|
|
|
|
|
|
|
def screenshot_stylesheet_tag
|
|
|
|
css = translate_asset_paths(assets.find_asset('screenshot.css').to_s)
|
|
|
|
content_tag(:style, css.html_safe)
|
|
|
|
end
|
|
|
|
|
2015-07-18 11:13:32 +00:00
|
|
|
def embed_script(asciicast)
|
|
|
|
src = asciicast_url(asciicast, format: :js)
|
2015-07-18 11:15:33 +00:00
|
|
|
id = "asciicast-#{asciicast.to_param}"
|
2015-07-18 11:22:14 +00:00
|
|
|
%(<script type="text/javascript" src="#{src}" id="#{id}" async></script>)
|
2015-07-18 11:13:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def embed_html_link(asciicast)
|
|
|
|
img_src = asciicast_url(asciicast, format: :png)
|
|
|
|
url = asciicast_url(asciicast)
|
|
|
|
width = %{width="#{asciicast.image_width}"} if asciicast.image_width
|
|
|
|
%(<a href="#{url}" target="_blank"><img src="#{img_src}" #{width}/></a>)
|
|
|
|
end
|
|
|
|
|
|
|
|
def embed_markdown_link(asciicast)
|
|
|
|
img_src = asciicast_url(asciicast, format: :png)
|
|
|
|
url = asciicast_url(asciicast)
|
|
|
|
"[![asciicast](#{img_src})](#{url})"
|
|
|
|
end
|
|
|
|
|
2013-09-20 21:21:25 +00:00
|
|
|
private
|
|
|
|
|
2015-03-27 11:35:34 +00:00
|
|
|
def translate_asset_paths(css)
|
2015-08-26 19:32:58 +00:00
|
|
|
css.gsub(/['"]\/assets\/(.+?)(-\w{64})?\.(.+?)['"]/) { |m|
|
2015-03-27 11:35:34 +00:00
|
|
|
path = assets.find_asset("#{$1}.#{$3}").pathname
|
|
|
|
"'#{path}'"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|