Pass title and author info to the player

element
Marcin Kulik 9 years ago
parent 21740104b7
commit a44121eb7b

@ -13,7 +13,11 @@ function tryCreatePlayer(parentNode, asciicast, options) {
autoPlay: options.autoPlay,
loop: options.loop,
fontSize: options.fontSize,
theme: options.theme
theme: options.theme,
title: options.title,
author: options.author,
authorURL: options.authorURL,
authorImgURL: options.authorImgURL
}
);
}

@ -29,6 +29,10 @@ class UserDecorator < ApplicationDecorator
model.theme || Theme.default
end
def url
h.profile_path(model)
end
private
def wrap_with_link(html)

@ -1,8 +1,9 @@
module AsciicastsHelper
def player(asciicast, options = PlaybackOptions.new)
def player(asciicast, options = PlaybackOptions.new, skip_titlebar = false)
render 'asciicasts/player', asciicast: AsciicastSerializer.new(asciicast),
options: options
options: options,
skip_titlebar: skip_titlebar
end
def screenshot_javascript_tag

@ -9,4 +9,14 @@ class PlaybackOptions
attribute :benchmark, Boolean, default: false
attribute :theme, String, default: Theme::DEFAULT
def as_json(*)
{
speed: speed,
autoPlay: autoplay,
loop: loop,
fontSize: size,
theme: theme
}
end
end

@ -13,4 +13,20 @@ class AsciicastSerializer < ActiveModel::Serializer
object.private?
end
def title
object.title
end
def author_display_name
object.user.display_name
end
def author_url
object.user.url
end
def author_avatar_url
object.user.avatar_url(object.user)
end
end

@ -21,13 +21,12 @@
tryCreatePlayer(
$('.player')[0],
<%= asciicast.to_json.gsub('</', '<\/').html_safe %>,
{
speed: <%= options.speed %>,
autoPlay: <%= options.autoplay %>,
loop: <%= options.loop %>,
fontSize: '<%= options.size %>',
theme: '<%= h options.theme %>'
}
<%= options.as_json.merge(skip_titlebar ? {} : {
title: asciicast.title,
author: asciicast.author_display_name,
authorURL: asciicast.author_url,
authorImgURL: asciicast.author_avatar_url
}).to_json.gsub('</', '<\/').html_safe %>
);
});
</script>

@ -1 +1 @@
= player page.asciicast, page.playback_options
= player page.asciicast, page.playback_options, true

Loading…
Cancel
Save