Add ?t=1:20 param support
This commit is contained in:
parent
9881c5df6c
commit
cc13bf755a
@ -12,6 +12,7 @@ function tryCreatePlayer(parentNode, asciicast, options) {
|
||||
speed: options.speed,
|
||||
autoPlay: options.autoPlay,
|
||||
loop: options.loop,
|
||||
startAt: options.startAt,
|
||||
fontSize: options.fontSize,
|
||||
theme: options.theme,
|
||||
title: options.title,
|
||||
|
@ -1,22 +1,40 @@
|
||||
class PlaybackOptions
|
||||
|
||||
class Time < Virtus::Attribute
|
||||
def coerce(value)
|
||||
value = value.presence
|
||||
|
||||
if value
|
||||
smh = value.strip.sub("m", ":0").split(":").reverse
|
||||
smh[0].to_i + smh[1].to_i * 60 + smh[2].to_i * 3600
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include Virtus.model
|
||||
|
||||
attribute :speed, Float, default: 1.0
|
||||
attribute :size, String, default: 'small'
|
||||
attribute :autoplay, Boolean, default: false
|
||||
attribute :autoplay, Boolean
|
||||
attribute :loop, Boolean, default: false
|
||||
attribute :benchmark, Boolean, default: false
|
||||
attribute :theme, String, default: Theme::DEFAULT
|
||||
attribute :t, Time
|
||||
|
||||
def as_json(*)
|
||||
{
|
||||
opts = {
|
||||
speed: speed,
|
||||
autoPlay: autoplay,
|
||||
loop: loop,
|
||||
fontSize: size,
|
||||
theme: theme
|
||||
theme: theme,
|
||||
}
|
||||
|
||||
if t
|
||||
opts = opts.merge(startAt: t)
|
||||
end
|
||||
|
||||
opts
|
||||
end
|
||||
|
||||
end
|
||||
|
13
spec/models/playback_options.rb
Normal file
13
spec/models/playback_options.rb
Normal file
@ -0,0 +1,13 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe PlaybackOptions do
|
||||
it 'coerces time' do
|
||||
expect(PlaybackOptions.new.t).to eq(nil)
|
||||
expect(PlaybackOptions.new(t: '').t).to eq(nil)
|
||||
expect(PlaybackOptions.new(t: '5').t).to eq(5)
|
||||
expect(PlaybackOptions.new(t: '5s').t).to eq(5)
|
||||
expect(PlaybackOptions.new(t: '2m9s').t).to eq(129)
|
||||
expect(PlaybackOptions.new(t: '2:09').t).to eq(129)
|
||||
expect(PlaybackOptions.new(t: '1:02:09').t).to eq(3600+129)
|
||||
end
|
||||
end
|
1071
vendor/assets/javascripts/asciinema-player.js
vendored
1071
vendor/assets/javascripts/asciinema-player.js
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user