Play v1 format by default if available

This commit is contained in:
Marcin Kulik 2015-12-22 17:40:20 +00:00
parent 4da03be774
commit e3c04e1461
8 changed files with 776 additions and 750 deletions

View File

@ -5,8 +5,7 @@ function tryCreatePlayer(parentNode, asciicast, options) {
asciinema_player.core.CreatePlayer(
parentNode,
asciicast.width, asciicast.height,
asciicast.stdout_frames_url,
asciicast.duration,
asciicast.url,
{
snapshot: asciicast.snapshot,
speed: options.speed,
@ -31,7 +30,7 @@ function tryCreatePlayer(parentNode, asciicast, options) {
}
function checkReadiness() {
if (asciicast.stdout_frames_url) {
if (asciicast.url && asciicast.snapshot) {
$('.processing-info').remove();
createPlayer();
} else {

View File

@ -30,7 +30,7 @@ module Api
end
format.json do
render json: asciicast
render json: asciicast, playback_options: PlaybackOptions.new
end
end
end

View File

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

View File

@ -85,6 +85,10 @@ class Asciicast < ActiveRecord::Base
end
end
def data_url
file_url || stdout_frames_url
end
def stdout
return @stdout if @stdout
@stdout = Stdout::Buffered.new(get_stdout)

View File

@ -20,6 +20,7 @@ class PlaybackOptions
attribute :benchmark, Boolean, default: false
attribute :theme, String, default: Theme::DEFAULT
attribute :t, Time
attribute :v0, Boolean, default: false
def as_json(*)
opts = {

View File

@ -1,7 +1,7 @@
class AsciicastSerializer < ActiveModel::Serializer
self.root = false
attributes :id, :duration, :stdout_frames_url, :snapshot
attributes :id, :url, :snapshot
attribute :terminal_columns, key: :width
attribute :terminal_lines, key: :height
@ -9,6 +9,14 @@ class AsciicastSerializer < ActiveModel::Serializer
object.to_param
end
def url
if playback_options.v0
object.stdout_frames_url
else
object.data_url
end
end
def private?
object.private?
end
@ -29,4 +37,10 @@ class AsciicastSerializer < ActiveModel::Serializer
object.user.avatar_url(object.user)
end
private
def playback_options
@options[:playback_options]
end
end

View File

@ -2,7 +2,7 @@ require 'rails_helper'
describe AsciicastSerializer do
let(:serializer) { described_class.new(asciicast) }
let(:serializer) { AsciicastSerializer.new(asciicast, playback_options: PlaybackOptions.new) }
let(:asciicast) { create(:asciicast) }
describe '#to_json' do
@ -12,12 +12,8 @@ describe AsciicastSerializer do
expect(subject['id']).to eq(asciicast.to_param)
end
it 'includes duration' do
expect(subject['duration']).to eq(asciicast.duration)
end
it 'includes stdout_frames_url' do
expect(subject['stdout_frames_url']).to eq(asciicast.stdout_frames_url)
it 'includes url' do
expect(subject['url']).to eq(asciicast.file_url)
end
it 'includes snapshot' do

File diff suppressed because one or more lines are too long