2014-02-01 00:26:58 +00:00
|
|
|
class AsciicastPagePresenter
|
2014-01-18 10:44:13 +00:00
|
|
|
|
2014-02-01 00:14:37 +00:00
|
|
|
attr_reader :asciicast, :current_user, :playback_options
|
2014-01-18 10:44:13 +00:00
|
|
|
|
2014-02-01 00:14:37 +00:00
|
|
|
def self.build(asciicast, current_user, playback_options)
|
|
|
|
new(asciicast.decorate, current_user, PlaybackOptions.new(playback_options))
|
2014-01-18 13:12:10 +00:00
|
|
|
end
|
|
|
|
|
2014-02-01 00:14:37 +00:00
|
|
|
def initialize(asciicast, current_user, playback_options)
|
2014-01-18 13:12:10 +00:00
|
|
|
@asciicast = asciicast
|
2014-02-01 00:14:37 +00:00
|
|
|
@current_user = current_user
|
2014-01-18 13:12:10 +00:00
|
|
|
@playback_options = playback_options
|
2014-01-18 10:44:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
asciicast_title
|
|
|
|
end
|
|
|
|
|
|
|
|
def asciicast_title
|
|
|
|
asciicast.title
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_img_link
|
|
|
|
asciicast.author_img_link
|
|
|
|
end
|
|
|
|
|
|
|
|
def author_link
|
|
|
|
asciicast.author_link
|
|
|
|
end
|
|
|
|
|
|
|
|
def asciicast_created_at
|
|
|
|
asciicast.created_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def asciicast_env_details
|
|
|
|
"#{asciicast.os} / #{asciicast.shell} / #{asciicast.terminal_type}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def views_count
|
|
|
|
asciicast.views_count
|
|
|
|
end
|
|
|
|
|
|
|
|
def embed_script(h)
|
|
|
|
src = h.asciicast_url(asciicast, format: :js)
|
|
|
|
id = "asciicast-#{asciicast.id}"
|
|
|
|
%(<script type="text/javascript" src="#{src}" id="#{id}" async></script>)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_admin_dropdown?
|
2014-02-01 00:14:37 +00:00
|
|
|
asciicast.managable_by?(current_user)
|
2014-01-18 10:44:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_description?
|
|
|
|
asciicast.description.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
asciicast.description
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_other_asciicasts_by_author?
|
|
|
|
author.asciicast_count > 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def other_asciicasts_by_author
|
2014-01-18 11:21:33 +00:00
|
|
|
author.asciicasts_excluding(asciicast, 3).decorate
|
2014-01-18 10:44:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def author
|
|
|
|
asciicast.user
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|