2014-02-01 00:26:58 +00:00
|
|
|
class AsciicastPagePresenter
|
2015-03-30 17:54:43 +00:00
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
2014-01-18 10:44:13 +00:00
|
|
|
|
2015-03-30 10:02:21 +00:00
|
|
|
attr_reader :routes, :asciicast, :current_user, :policy, :playback_options
|
2014-01-18 10:44:13 +00:00
|
|
|
|
2016-01-11 15:14:46 +00:00
|
|
|
delegate :download_filename, :width, :height, to: :asciicast, prefix: true
|
2016-01-11 14:45:24 +00:00
|
|
|
|
2015-03-30 10:02:21 +00:00
|
|
|
def self.build(routes, asciicast, current_user, playback_options)
|
2014-06-30 21:26:25 +00:00
|
|
|
decorated_asciicast = asciicast.decorate
|
2014-07-05 12:59:42 +00:00
|
|
|
policy = Pundit.policy(current_user, asciicast)
|
2014-06-30 21:26:25 +00:00
|
|
|
|
|
|
|
playback_options = {
|
|
|
|
'theme' => decorated_asciicast.theme_name
|
|
|
|
}.merge(playback_options)
|
|
|
|
|
2015-03-30 10:02:21 +00:00
|
|
|
new(routes, decorated_asciicast, current_user, policy,
|
2014-07-05 12:59:42 +00:00
|
|
|
PlaybackOptions.new(playback_options))
|
2014-01-18 13:12:10 +00:00
|
|
|
end
|
|
|
|
|
2015-03-30 10:02:21 +00:00
|
|
|
def initialize(routes, asciicast, current_user, policy, playback_options)
|
|
|
|
@routes = routes
|
2014-01-18 13:12:10 +00:00
|
|
|
@asciicast = asciicast
|
2014-02-01 00:14:37 +00:00
|
|
|
@current_user = current_user
|
2014-07-05 12:59:42 +00:00
|
|
|
@policy = policy
|
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 show_admin_dropdown?
|
2014-07-05 12:59:42 +00:00
|
|
|
[show_edit_link?,
|
|
|
|
show_delete_link?,
|
|
|
|
show_set_featured_link?,
|
|
|
|
show_unset_featured_link?].any?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_edit_link?
|
|
|
|
policy.update?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_delete_link?
|
|
|
|
policy.destroy?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_set_featured_link?
|
2015-04-25 18:47:52 +00:00
|
|
|
!asciicast.featured? && policy.change_featured?
|
2014-07-05 12:59:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_unset_featured_link?
|
2015-04-25 18:47:52 +00:00
|
|
|
asciicast.featured? && policy.change_featured?
|
2014-01-18 10:44:13 +00:00
|
|
|
end
|
|
|
|
|
2014-11-15 18:30:05 +00:00
|
|
|
def show_make_private_link?
|
2015-04-25 18:47:52 +00:00
|
|
|
!asciicast.private? && policy.change_visibility?
|
2014-11-15 18:30:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show_make_public_link?
|
2015-04-25 18:47:52 +00:00
|
|
|
asciicast.private? && policy.change_visibility?
|
2014-11-15 18:30:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-18 10:44:13 +00:00
|
|
|
def show_description?
|
|
|
|
asciicast.description.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
|
|
|
asciicast.description
|
|
|
|
end
|
|
|
|
|
2015-03-30 17:54:43 +00:00
|
|
|
def short_text_description
|
|
|
|
if asciicast.description.present?
|
|
|
|
truncate(strip_tags(asciicast.description).gsub(/\n+/, ' '), length: 200)
|
|
|
|
else
|
|
|
|
"Recorded by #{asciicast.user.display_name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-18 10:44:13 +00:00
|
|
|
def other_asciicasts_by_author
|
2015-04-26 13:30:42 +00:00
|
|
|
@other_asciicasts_by_author ||= author.other_asciicasts(asciicast, 3).decorate
|
2014-01-18 10:44:13 +00:00
|
|
|
end
|
|
|
|
|
2015-03-30 10:02:21 +00:00
|
|
|
def asciicast_oembed_url(format)
|
2015-03-29 18:43:32 +00:00
|
|
|
routes.oembed_url(url: routes.asciicast_url(asciicast), format: format)
|
|
|
|
end
|
|
|
|
|
2015-05-15 17:36:12 +00:00
|
|
|
def show_private_label?
|
|
|
|
asciicast.private?
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_featured_label?
|
|
|
|
asciicast.featured?
|
|
|
|
end
|
|
|
|
|
2016-01-11 14:45:24 +00:00
|
|
|
def can_replay_in_terminal?
|
|
|
|
asciicast.version > 0
|
|
|
|
end
|
|
|
|
|
2014-01-18 10:44:13 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def author
|
|
|
|
asciicast.user
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|