Rename container_width option to max_width

openid
Marcin Kulik 11 years ago
parent 2d93333cb5
commit 585167089d

@ -14,7 +14,7 @@ class Asciinema.AbstractPlayer
hud: @options.hud
rendererClass: @options.rendererClass
snapshot: @model.get 'snapshot'
containerWidth: @options.containerWidth
maxWidth: @options.maxWidth
createMovie: ->
throw 'not implemented'

@ -19,9 +19,9 @@ class Asciinema.PlayerView extends Backbone.View
@renderSnapshot()
setupClipping: ->
if @options.containerWidth
if @options.maxWidth
rendererWidth = @rendererView.elementWidth()
min = Math.min(@options.containerWidth, rendererWidth)
min = Math.min(@options.maxWidth, rendererWidth)
@rightClipWidth = rendererWidth - min
else
@rightClipWidth = 0

@ -36,8 +36,8 @@ class AsciicastsController < ApplicationController
def raw
response.headers.delete('X-Frame-Options')
@asciicast = asciicast.decorate
render :layout => 'raw'
render locals: { page: BareAsciicastPresenter.build(asciicast, params) },
layout: 'raw'
end
def example

@ -0,0 +1,18 @@
class BareAsciicastPresenter
attr_reader :asciicast, :playback_options
def self.build(asciicast, playback_options)
new(asciicast.decorate, PlaybackOptions.new(playback_options))
end
def initialize(asciicast, playback_options)
@asciicast = asciicast
@playback_options = playback_options
end
def asciicast_id
asciicast.id
end
end

@ -3,16 +3,16 @@
javascript:
$(function() {
var playerClass = #{options.player_class};
var containerWidth = #{options.max_width || 'null'};
var maxWidth = #{options.max_width || 'null'};
window.player = new playerClass({
el: $('.player'),
speed: #{options.speed},
benchmark: #{options.benchmark},
model: new Asciinema.Asciicast(#{asciicast.html_safe}),
containerWidth: containerWidth || $('.cinema .player').parent().width(),
rendererClass: #{options.renderer_class},
autoPlay: #{options.autoplay},
hud: #{!options.hide_hud}
el: $('.player'),
speed: #{options.speed},
benchmark: #{options.benchmark},
model: new Asciinema.Asciicast(#{asciicast.html_safe}),
maxWidth: maxWidth || $('.cinema .player').parent().width(),
rendererClass: #{options.renderer_class},
autoPlay: #{options.autoplay},
hud: #{!options.hide_hud}
});
});

@ -1,4 +1,4 @@
= player @asciicast
= player page.asciicast, page.playback_options
p.powered
' Powered by
a href=root_url target="_top" asciinema
@ -9,7 +9,7 @@ javascript:
if (typeof target != "undefined" && window !== window.parent) {
var w = $(document).width();
var h = $(document).height();
target.postMessage(['asciicast:size', { id: #{@asciicast.id}, width: w, height: h }], '*');
target.postMessage(['asciicast:size', { id: #{page.asciicast_id}, width: w, height: h }], '*');
}
function onMessage(e) {

@ -19,7 +19,7 @@
}
function params(container, script) {
var params = '?container_width=' + container.offsetWidth;
var params = '?max_width=' + container.offsetWidth;
var size = script.getAttribute('data-size');
if (size) {

@ -0,0 +1,30 @@
require 'spec_helper'
describe BareAsciicastPresenter do
describe '.build' do
subject { described_class.build(asciicast, playback_options) }
let(:asciicast) { stub_model(Asciicast, decorate: decorated_asciicast) }
let(:playback_options) { { speed: 3.0 } }
let(:decorated_asciicast) { double('decorated_asciicast') }
it "builds presenter instance with given asciicast decorated" do
expect(subject.asciicast).to be(decorated_asciicast)
end
it "builds presenter instance with given playback options" do
expect(subject.playback_options.speed).to eq(3.0)
end
end
let(:presenter) { described_class.new(asciicast, nil) }
let(:asciicast) { stub_model(Asciicast, id: 123) }
describe '#asciicast_id' do
subject { presenter.asciicast_id }
it { should eq(123) }
end
end
Loading…
Cancel
Save